Project Architecture — The Onion Architecture

A simple and clean test driven friendly project structure for any big back end solution.

Once again we are really going to emphasize test driven development and maintainable applications here so we are going to go for a “Onion Architecture” where the Core/Hearth of our solution will base around Entities and not data access. This architecture leads emphasizes separation of concerns throughout the system, separation is the key.
It is worth to mention that this architecture is not optimal for small and basic applications. It’s appropriate for bigger solutions.

This is a pretty standard architecture that you usually see:

As you can see, each layer depends on the layer beneath. The big draw back with this is that it creates unnecessary coupling.
If you change something in the bottom layer then you will probably need to change something in the layer above and then the layer above that.
You probably get the point.

And this is the onion architecture:

As you can see here, the infrastructure is externalized and not tightly coupled.
Data base is external and not in the center, lowering the cost of maintenance for the life of the application and we can more easily write Unit Tests due to separation of the code.

Don’t forget to follow me on Twitter.

BTC

ETH

Kristoffer Karlsson

Written by

Software developer and indie game developer from Sweden. Been turning coffee into code since 2010.