Clean Architecture vs Hexagonal vs Onion vs N-tier — are they the same?
Three of them are essentially the same idea. One is fundamentally different.
The same idea, three names
Hexagonal Architecture / Ports & Adapters (Cockburn, 2005) Onion Architecture (Palermo, 2008) Clean Architecture (Martin, 2012)
All three describe the same structural pattern:
- Business logic in the center
- Dependencies point inward (Dependency Rule)
- The center defines interfaces ("ports"); the outside provides implementations ("adapters")
- The outermost layer is delivery / IO (HTTP, DB, queues)
They differ only in visual metaphor:
| Name | Metaphor | What's emphasized |
|---|---|---|
| Hexagonal | A hexagon with "ports" on each side | The symmetry of inputs and outputs |
| Onion | Concentric onion rings | Layered nature of the model |
| Clean | Concentric circles with dependency arrows | The Dependency Rule itself |
If you understand one, you understand all three. In .NET conversations, "Clean Architecture" is the dominant term today.
N-tier is fundamentally different
N-tier (or "layered architecture") splits the codebase horizontally:
┌──────────────────┐
│ Presentation │ Controllers, views
├──────────────────┤
│ Business Layer │ Services
├──────────────────┤
│ Data Layer │ Repositories, DbContext
├──────────────────┤
│ Database │
└──────────────────┘
Dependencies flow down:
- Presentation depends on Business
- Business depends on Data
- Data depends on the DB schema
In particular, Business depends on Data. The service layer knows about IOrderRepository because Data exposes it. If you change the DB, you change Data, and the ripple goes upward.
The critical difference
| N-tier | Clean / Hexagonal / Onion | |
|---|---|---|
| Direction of dependencies | Top-down (Pres → Biz → Data → DB) | Inward (everything points to Domain) |
| Who defines repository interfaces | Data layer | Application layer (it knows what it needs) |
| Where business logic depends on the DB | Yes, indirectly through Data | NO — business logic depends on nothing |
| Testability of business logic | Needs DB or DB mocks | None — pure unit tests |
| Surviving framework swaps | Hard | Easy |
In N-tier, your service classes import Microsoft.EntityFrameworkCore indirectly because they call repositories that return EF entities. In Clean Architecture, the Domain entity is a POCO with zero framework code.
Why this matters in interviews
A common interview question is "you're using N-tier — what would you change to test the business logic without a database?"
Answer: invert the dependency. Make the Application layer define the repository interfaces instead of the Data layer. Implementations move into Infrastructure. Now Application has zero references to EF Core, and tests can inject a fake repository.
That single inversion turns N-tier into Clean Architecture.
Practical consequence in a .NET project
N-tier project references:
Web → Business → Data → (EF Core, MSSQL)
Business.csproj references Data.csproj → indirectly references EF.
Clean Architecture project references:
Web → Application → Domain
Web → Infrastructure → Application → Domain
Infrastructure → (EF Core, MSSQL)
Application.csproj references only Domain.csproj. Has no idea EF Core exists.
Other patterns sometimes confused
- Microservices — a deployment pattern (multiple processes / databases). Orthogonal to Clean Architecture. You can have a monolith with Clean Architecture, or microservices with N-tier inside each.
- DDD (Domain-Driven Design) — a modeling approach (bounded contexts, aggregates, ubiquitous language). Often used WITH Clean Architecture but is not the same thing.
- MVC / MVVM — UI patterns. Clean Architecture lives BELOW the UI; both MVC and MVVM can sit on top.
Interview-grade summary
"Clean Architecture, Hexagonal, and Onion are three names for the same pattern — dependencies point inward, business logic in the center, interfaces defined at the boundary. N-tier is fundamentally different: dependencies flow top-down, and business logic ends up depending on the data layer (and therefore the database). Inverting that one dependency is what turns N-tier into Clean."