Design and review support for projects adopting Clean Architecture.
Note: Use this skill only when the project adopts Clean Architecture. Do not apply it to other architectures (Hexagonal, Onion, Layered, etc.).
Overview of the Layer Structure
┌─────────────────────────────────────────────────────┐
│ Infrastructure(横断的関心事のみ) │
│ ・ログ ・設定 ・メトリクス ・DI設定 │
├─────────────────────────────────────────────────────┤
│ Interface Adapters(外部との境界) │
│ ・Controller ・Repository実装 ・Gateway実装 │
├─────────────────────────────────────────────────────┤
│ Use Cases(アプリケーション固有ルール) │
│ ・Use Case ・Output Port(Repository Interface等)│
├─────────────────────────────────────────────────────┤
│ Domain(ビジネスルール) │
│ ・Entity ・Value Object ・Domain Service │
└─────────────────────────────────────────────────────┘
Important Principles
Placement of Persistence and RPC
| Component | Placement Layer |
|---|---|
| Repository Interface | Use Case Layer (Output Port) |
| Repository Implementation | Interface Adapter Layer |
| Gateway Interface | Use Case Layer (Output Port) |
| Gateway Implementation (RPC, etc.) | Interface Adapter Layer |
Responsibilities of the Infrastructure Layer
What to Place(Cross-cutting concerns only):
- Logging Mechanism
- Configuration Management
- Metrics and Tracing
- DI Container Configuration
What Not to Place:
- Repository Implementation → To the Interface Adapter Layer
- External API Gateway → To the Interface Adapter Layer
Checkpoints During Review
-
Are there no external dependencies in the domain layer?
- Check for the inclusion of DB connections, HTTP clients, etc.
-
Is the Repository implementation placed correctly?
- It should be in the interface adapter layer
-
Is the infrastructure layer becoming bloated?
- Check whether persistence code has crept in
-
Is the dependency direction inward?
- Only dependencies from outer layers to inner layers are permitted
Detailed Reference
For the detailed responsibilities of each layer and the list of components that should be placed, refer to references/layer-responsibilities.md .
Related Skills (Recommended for Concurrent Reading)
When using this skill, also refer to the following skills:
repository-placement: Placement of repository interfaces in Clean Architecturepackage-design: Package design principles within each layerddd-module-pattern: Module composition within the domain layer