Clean Architecture in .NET: One Rule, Four Layers, and When to Skip the Whole ThingMixed sources2 sources, drawn from a mix of official docs, project repositories and research.This rates where the sources come from. It doesn't prove every claim.
The dependency rule applied pragmatically — solution layout, port-and-adapter wiring, NetArchTest enforcement, and when Vertical Slice Architecture is the better fit.
By Amit UpadhyayPublished Updated 14 minArticle 2 of 10 in Backend (.NET / C#)
AI assistant · answers from this article
1 of 6
A CRUD service
Nothing to add yet
With no business rules to protect, a single project that talks to the database directly is honest and fast.
On this page
Clean Architecture, in one sentence
Clean Architecture is one rule about which code may depend on which: business rules sit in the middle, and everything else points inward at them.
You reach for it when a team is structuring a .NET service and wants it to stay maintainable. Not before: it costs judging each service by its domain complexity rather than using one template for all.
The cheat sheet
What to use when
You do not need all of this on day one. Each row is one signal and the piece that answers it. Stop at the row your system has reached, or pick one to see it in the picture above.
Where you areThe signalWhat to useWhat it costs
None. Most endpoints list, get, create and update a few tables.Nothing. One project, with EF Core in the handlersNothing
Business rules are tangled with database and framework code, and every infrastructure change puts them at risk.The dependency rule: source-code dependencies point inwardOne rule, four rings ↓Ports to define, and more projects
The domain project gains a reference to the data-access library, and the build stays green.An architecture test that fails the buildThe solution layout ↓One test to maintain
Entities have public setters, and all the logic sits in handlers.Behaviour in the aggregate. Handlers only orchestratePitfalls ↓Domain modelling work
Adding one field means touching every project, with a mapping pass between each layer.Vertical slices for the simple features, and mapping only at the edgeWhen it is the wrong choice ↓Two styles to explain in one codebase
Five services with four projects each is twenty project files for a team of four.Layers as folders in one project, until the size justifies splittingKeep it proportional ↓A boundary to add later, when real pain appears
Start With One Project
If most of your endpoints list, get, create and update a few tables, one project with EF Core in the handlers is honest and fast. The structure below is for services with real domain rules, where those rules need protecting from changes in the infrastructure around them.
Plenty of .NET solutions have folders called Domain, Application, Infrastructure, and Web (or API). Some actually benefit from the structure. Others copied a template, ended up with anaemic domain models, an Application layer that does nothing but pass DTOs through, and a hidden coupling to EF Core via “repository” interfaces that exist only to satisfy the dependency rule on paper.
🤔 If every service starts from the same template
Clean Architecture isn't a project template; it's a constraint on the direction of source-code dependencies. Adopt it without understanding the constraint, and you get ceremony with no payoff. Adopt it for the wrong size of system and the abstraction tax outweighs the benefit. The trick is knowing which problem you actually have.
Treat it as a tool, not a religion. Below is when its rules earn their keep, when Vertical Slice Architecture is a better fit, and how to wire the layers in modern .NET without inventing interfaces nobody needs.
Pro deep dive14 min full read
Keep reading with Pro
This is one of our advanced production deep dives. Pro unlocks the rest of it, every other deep dive, and the See, Animate, Test and Build modes on every topic.
What it covers
The dependency rule applied pragmatically — solution layout, port-and-adapter wiring, NetArchTest enforcement, and when Vertical Slice Architecture is the better fit.