Skip to content

Clean Architecture

Clean Architecture maintains strict separation between business logic and technical details. The domain logic remains independent of frameworks, databases, and external services.

Core Concept

Dependencies point inward through four concentric layers:

  1. Domain (innermost) - Entities, Value Objects, Events, Repository Interfaces, Exceptions
  2. Application - Commands, Queries, Handlers, Controllers, Event Listeners
  3. Infrastructure - Repository implementations, external service adapters
  4. Presentation (outermost) - Presenters, View Models, Templates

The fundamental rule: outer layers depend on inner layers, never the reverse.

Presentation → Application → Domain
Infrastructure → Domain

Key Points

Dependency Rule

  • Domain layer has no dependencies
  • Application depends only on Domain
  • Infrastructure implements Domain interfaces
  • Presentation transforms Application responses

Testability

Each layer can be tested independently. Domain logic requires no database or framework. Application logic uses in-memory repositories for fast, isolated tests.

Flexibility

Technical implementations can be replaced without changing business logic. Switching from SQLite to PostgreSQL requires no domain code changes.

Enforcement

Deptrac enforces architectural boundaries:

task deptrac:analyse

See Also