advanced
Onion Architecture
Model concentric layers around the domain core so outer infrastructure depends on inner policy rather than the reverse.
Onion Architecture models concentric layers around the domain core so infrastructure depends on application and domain, never the reverse. Domain services and aggregates sit near the center; application services coordinate use cases; infrastructure implements repositories and messaging at the outside.
On interviews: compare Onion with Hexagonal and Clean Architecture—they share the dependency rule with different vocabulary. Discuss where application services end and domain services begin.
Common pitfalls: onion diagrams with hollow centers; domain services that only wrap repositories; infrastructure leaking into application via shared ORM models.
The trade-off is flexibility versus complexity—know when the simpler path is enough.
Checklist:
- Domain model expresses business language.
- Application layer coordinates transactions.
- Infrastructure references inward interfaces only.
- Tests target domain without database when possible.