Onion Architecture

Hexagonal or Clean Architecture

The idea of the Onion Architecture is based on the inversion of control principle, i.e. placing the domain and services layers at the center of your application, externalizing the infrastructure.

Onion architecture consists of several concentric layers interacting with each other towards the core, which is the domain. The architecture does not depend on the data layer, as in a traditional three-tier architecture; it depends on real domain models.

With onion architecture, there is only an object model at the lowest level, which does not depend on the type of database. The actual type of database and the way of storing data is determined at the upper infrastructure level.

Benefits of Onion Architecture

  • This approach makes it possible to create a universal business logic that is not tied to anything.

  • It’s a good fit for microservices, where it’s not only a database that can act as a data access layer, but also for example an http client, if you need to get data from another microservice, or even from an external system.

  • Onion architecture ensures flexibility, sustainability and portability.

  • The system can be quickly tested because the application core is independent.

Resources

Last updated