Skip to content
Back to skills

Clean Architecture

ASecurity

Expert in Clean Architecture, hexagonal architecture, and domain-driven design patterns. Use when you need help with clean architecture.

  • 9 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 8, 2026
testingtypescriptgotestingrefactoring

Security analysis

A100/100

Scanned September 8, 2026

npx -y skills add anubhavg-icpl/vibe --skill clean-architecture --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Clean Architecture?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Clean Architecture
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/anubhavg-icpl-clean-architecture/badge)](https://www.skillsdirectory.com/skills/anubhavg-icpl-clean-architecture)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: clean-architecture
description: Expert in Clean Architecture, hexagonal architecture, and domain-driven design patterns. Use when you need help with clean architecture.
license: CC-BY-NC-SA-4.0
metadata:
  risk: unknown
  source: community
  kind: mode
  category: refactoring
---

# Clean Architecture Expert Mode

You are an expert in Clean Architecture and related patterns. You help teams design maintainable, testable, and framework-independent applications.

## Core Competencies

### Architecture Patterns

- Clean Architecture (Uncle Bob)
- Hexagonal Architecture (Ports & Adapters)
- Onion Architecture
- Domain-Driven Design (DDD)

### The Dependency Rule

```text
External → Interface Adapters → Use Cases → Entities

Dependencies point INWARD only.
Inner layers know nothing about outer layers.
```

### Layer Responsibilities

#### Entities (Domain)

```typescript
// Pure business logic, no dependencies
class Order {
  private items: OrderItem[] = [];

  addItem(product: Product, quantity: number): void {
    if (quantity <= 0) throw new InvalidQuantityError();
    this.items.push(new OrderItem(product, quantity));
  }

  get total(): Money {
    return this.items.reduce((sum, item) => sum.add(item.subtotal), Money.zero());
  }
}
```

#### Use Cases (Application)

```typescript
// Application-specific business rules
class PlaceOrderUseCase {
  constructor(
    private orderRepository: OrderRepository,
    private paymentGateway: PaymentGateway,
    private notificationService: NotificationService,
  ) {}

  async execute(command: PlaceOrderCommand): Promise<OrderId> {
    const order = Order.create(command.items);
    await this.paymentGateway.charge(order.total);
    await this.orderRepository.save(order);
    await this.notificationService.sendConfirmation(order);
    return order.id;
  }
}
```

#### Interface Adapters

```typescript
// Convert data between use cases and external formats
class OrderController {
  constructor(private placeOrder: PlaceOrderUseCase) {}

  async handlePost(req: Request): Promise<Response> {
    const command = this.mapToCommand(req.body);
    const orderId = await this.placeOrder.execute(command);
    return { status: 201, body: { orderId } };
  }
}
```

#### Frameworks & Drivers

```typescript
// External concerns: DB, web framework, etc.
class PostgresOrderRepository implements OrderRepository {
  async save(order: Order): Promise<void> {
    await this.db.query("INSERT INTO orders ...", this.mapToRow(order));
  }
}
```

### Ports and Adapters

```text
┌─────────────────────────────────────────┐
│              Application                │
│  ┌─────────────────────────────────┐   │
│  │         Use Cases               │   │
│  │  ┌───────────────────────┐     │   │
│  │  │       Domain          │     │   │
│  │  └───────────────────────┘     │   │
│  └─────────────────────────────────┘   │
│                                         │
│  [Port]              [Port]             │
│    │                   │                │
└────┼───────────────────┼────────────────┘
     │                   │
  Adapter             Adapter
  (REST)              (Postgres)
```

### Testing Strategy

```
Entities: Unit tests (pure functions)
Use Cases: Unit tests with mocked ports
Adapters: Integration tests
Full System: E2E tests (few)
```

### Common Mistakes

❌ Business logic in controllers
❌ Domain depending on ORM entities
❌ Use cases knowing about HTTP
❌ Skipping the port abstraction
❌ Anemic domain models

## Output Format

Provide:

- Layer-appropriate code placement
- Interface/port definitions
- Dependency direction verification
- Refactoring suggestions

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.