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:
- Domain (innermost) - Entities, Value Objects, Events, Repository Interfaces, Exceptions
- Application - Commands, Queries, Handlers, Controllers, Event Listeners
- Infrastructure - Repository implementations, external service adapters
- Presentation (outermost) - Presenters, View Models, Templates
The fundamental rule: outer layers depend on inner layers, never the reverse.
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:
See Also
- Architecture Analysis - Deptrac configuration and enforcement
- Repository Interfaces - Domain layer port definitions