Skip to content
Back to skills

Clean Architecture 3

ASecurity

Clean Architecture principles for maintainable, testable applications. Use when designing application structure or refactoring.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
businessexpressfastapitestingrefactoringapidatabase

Works with

  • cli
  • api

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill clean-architecture-3 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Clean Architecture 3?

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

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

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: Clean Architecture principles for maintainable, testable applications. Use when designing application structure or refactoring.
---

# Clean Architecture

## Layer Structure

```
┌─────────────────────────────────────────────┐
│ FRAMEWORKS & DRIVERS (Web, DB, External)    │
│ ┌─────────────────────────────────────────┐ │
│ │ INTERFACE ADAPTERS (Controllers, Repos) │ │
│ │ ┌─────────────────────────────────────┐ │ │
│ │ │ APPLICATION (Use Cases)             │ │ │
│ │ │ ┌─────────────────────────────────┐ │ │ │
│ │ │ │ DOMAIN (Entities)               │ │ │ │
│ │ │ └─────────────────────────────────┘ │ │ │
│ │ └─────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────┘ │
└─────────────────────────────────────────────┘
```

## Dependency Rule

**Dependencies point inward only.**

- Domain knows nothing about outer layers
- Use Cases know Domain, nothing else
- Adapters know Use Cases + Domain
- Frameworks know everything

## Layers

### Domain (Entities)
- Business objects with behavior
- Validation rules
- No framework dependencies
- No I/O operations

### Application (Use Cases)
- Orchestrates domain objects
- One use case = one action
- Defines repository interfaces
- Input/Output DTOs

### Interface Adapters
- Controllers: HTTP → Use Case
- Repositories: Use Case → Database
- Presenters: Use Case → Response format

### Frameworks & Drivers
- Web framework (Express, FastAPI, Fiber)
- Database clients
- External APIs
- Configuration

## Folder Structure

```
src/
├── domain/
│   └── entities/
├── application/
│   ├── use-cases/
│   └── interfaces/      # Repository interfaces
├── infrastructure/
│   ├── repositories/    # Interface implementations
│   └── external/        # API clients
└── interfaces/
    ├── http/            # Controllers, routes
    └── cli/             # CLI handlers
```

## Key Patterns

### Dependency Injection
```
UseCase depends on RepositoryInterface (not implementation)
Controller injects concrete Repository into UseCase
```

### Use Case Structure
```
1. Validate input
2. Load entities via repository
3. Execute domain logic
4. Persist via repository
5. Return output DTO
```

### Repository Interface
```
Defined in: application/interfaces/
Implemented in: infrastructure/repositories/
```

## When to Apply

**Use Clean Architecture when:**
- Application will grow/evolve
- Multiple entry points (API, CLI, queue)
- Team needs clear boundaries
- Testing is priority

**Skip for:**
- Simple CRUD apps
- Prototypes/MVPs
- Scripts/tools

## Common Mistakes

- Entities depending on ORM/framework
- Use cases calling HTTP directly
- Business logic in controllers
- Skipping the interface layer
- Over-engineering simple apps

## Testing Strategy

| Layer | Test Type | Mocks |
|-------|-----------|-------|
| Domain | Unit | None |
| Use Cases | Unit | Repositories |
| Adapters | Integration | External services |
| E2E | System | None |

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…