SuperAPI AI Directory

clean-architecture

General & other

View repository

Updated 10-15 22:39

About this skill

Clean Architecture

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

  1. Are there no external dependencies in the domain layer?

    • Check for the inclusion of DB connections, HTTP clients, etc.
  2. Is the Repository implementation placed correctly?

    • It should be in the interface adapter layer
  3. Is the infrastructure layer becoming bloated?

    • Check whether persistence code has crept in
  4. 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 Architecture
  • package-design: Package design principles within each layer
  • ddd-module-pattern: Module composition within the domain layer