← All topics
🏗️ Architecture

Clean Architecture

The dependency rule, and where each pattern above actually lives.

Concentric layers — Domain (entities, value objects, domain logic — zero external dependencies) at the center, Application (use cases/handlers, orchestration — depends only on Domain) around it, then Infrastructure (EF Core, message bus clients, external APIs) and Presentation (API controllers/Minimal API endpoints) on the outside.

The Dependency Rule: source code dependencies point inward only. Infrastructure depends on Application/Domain abstractions (via interfaces defined in the inner layers), never the reverse — this is Dependency Inversion applied project-wide, not just per-class. In practice: your IOrderRepository interface lives in Domain/Application; EfOrderRepository (the implementation) lives in Infrastructure and is wired up via DI at the composition root (Program.cs).

Where the topics above physically live: Repository interfaces + Strategy interfaces + domain entities → Domain/Application. Repository/Strategy implementations, DbContext, NServiceBus/RabbitMQ client config → Infrastructure. MediatR handlers (Commands/Queries) → Application. This mapping is a great answer if asked "where would you put X" for anything in this whole document.

Flashcards (3)

State the Dependency Rule in Clean Architecture.
tap to reveal answer
Source code dependencies point inward only — outer layers (Infrastructure, Presentation) depend on inner layers (Application, Domain), never the reverse. Achieved via interfaces defined in inner layers and implemented in outer ones.
Where does an IOrderRepository interface live vs its EfOrderRepository implementation, in Clean Architecture terms?
tap to reveal answer
The interface lives in Domain or Application (inner layer, defines what's needed). The EF Core implementation lives in Infrastructure (outer layer) and is wired to the interface via DI at the composition root.
Which layer do MediatR command/query handlers belong in, and why?
tap to reveal answer
Application layer — they orchestrate use cases (calling domain logic and infrastructure abstractions like repositories) but contain no framework/infrastructure detail themselves and no core business rules (those live in Domain).