Onion architecture
Rings around the domain model; infrastructure on the outside depends on everything inside.

Onion architecture, named by Jeffrey Palermo in 2008, puts the domain model at the centre and wraps it in rings: domain services, then application services, then infrastructure, the UI and tests on the outside. Every ring may depend only on rings inside it, so the database is a detail at the edge rather than the foundation everything sits on.
It is close to hexagonal and clean architecture; the difference is mostly emphasis. Onion is explicit that repository interfaces belong inside, next to the domain, and that their implementations live in the outer ring.
The parts of the pattern
- Domain model
- Entities and value objects such as Order and Money. Depends on nothing.
- Domain services
- Logic that spans several entities, such as pricing, and the repository interfaces.
- Application services
- Use cases that coordinate domain objects and transactions.
- Infrastructure, UI and tests
- Controllers, SQL repositories, message handlers and test code, all on the outside.
How it works
- A controller in the outer ring receives a request and calls an application service.
- The application service loads the order through a repository interface and calls the pricing service.
- The pricing service works purely on domain objects.
- At start-up, dependency injection wires the SQL repository in the outer ring to the interface in the inner ring.
When to use it, and when not to
Good fit
- Domain-driven design projects, especially in .NET and Java, where the style is well supported.
- Applications where the domain must be testable without infrastructure.
- Teams that want a stricter version of layered architecture with dependencies inverted.
Think twice
- Thin CRUD services with no domain logic.
- When the team already follows hexagonal or clean architecture: pick one vocabulary, not three.
Edit this diagram
Click Open the diagram in the editor to get your own copy, saved in your browser. Rename the boxes to match your system, swap the generic boxes for technology icons from the palette, then export a PNG, SVG or PDF, or share a link. No sign-up.