Intro to Onion Architecture
Introduction
A software architectural pattern known as “Onion Architecture” focuses on maintainability and separation of concerns while encouraging a modular and loosely coupled architecture.
Layers
- Domain Layer: It is responsible for the principal business logic, business rules, and entities of the software.
- Application Layer: It carries out use cases and manages the data flow between the domain and infrastructure layers.
- Infrastructure Layer: It deals with external elements such as databases, file systems, or external services.
- Presentation Layer: It handles user interfaces and all related presentation logic.
Key Concepts
Internal levels are unaware of external layers due to the inward flow of dependencies. This guarantees that there is no direct dependency between high-level and low-level modules. Rather, both rely on abstractions, which allow for interchangeable implementations and reduce coupling.
Every layer, or circle, offers an interface to the outer layer while encapsulating or hiding internal implementation details. Data structures and formats might differ between levels. Inner layers shouldn’t use data types from the outer levels.
Core domain logic is represented by the inner circles, while mechanisms are represented by the outer circles.
The application is organized into layers, each handling a distinct set of tasks and concerns. All layers function within the application as modules, packages, or namespaces.
The objective is to increase coupling inside a vertical slice across layers and reduce coupling across layers. This guarantees that we do not worry too much about implementation issues and can instead concentrate on the domain model.
Pros and Cons
References
- https://romanglushach.medium.com/understanding-hexagonal-clean-onion-and-traditional-layered-architectures-a-deep-dive-c0f93b8a1b96
- https://medium.com/@edin.sahbaz/exploring-the-evolution-of-backend-software-architecture-n-layered-ddd-hexagon-onion-and-9edc833521bc
- https://medium.com/expedia-group-tech/onion-architecture-deed8a554423