Onion Architecture: Why I still use it after so many years

Architecture_Blueprint
Onion_Pattern_v2.0
Core Domain
Entities & Value Objects
The heart of Onion Architecture. Pure business logic, zero dependencies.
The Core: Protecting the Domain
In the center of the Onion lies the Domain Model. After so many years, the biggest mistake I see is developers leaking SQL types or HTTP concerns into their business entities. In Onion Architecture, the Core is independent. It doesn't know about your database, your API, or your cloud provider. This purity ensures that as your infrastructure evolves, your business rules - the most valuable part of your IP - remain untouched.
The Layers of Protection
Surrounding the Core are Domain Services and Application Services. These layers act as the orchestrators. The key rule is simple: dependencies only point inward. The inner layers define interfaces (contracts), and the outer layers (Infrastructure) implement them. This Dependency Inversion is what prevents the Big Ball of Mud and allows you to swap a PostgreSQL implementation for MongoDB without touching a single line of business logic.
The Infrastructure: Pushing Details to the Edge
In Onion Architecture, the database, UI, and external integrations are details on the outermost rim. By pushing these to the edge, we gain incredible testability. Since the business logic doesn't depend on a database connection, you can run thousands of unit tests in seconds. I've found that this architecture is the single greatest predictor of whether a project will still be maintainable five years after its first release.
Why it Lasts: Fighting Framework Churn
Frameworks come and go, but business logic is forever. Many developers bake their logic directly into a specific framework's controllers or ORM models. When that framework reaches end-of-life, the project dies with it. Onion Architecture decouples you from the hype cycle. It allows you to upgrade your tech stack at the edge while the heart of your application continues to beat reliably.
"Build your system so that the database and UI are details, not the foundation. Your domain logic is the only thing that truly matters."

