Layers in Software Design

Separation of concerns is one of the most important principles used in software design. To comply with this principle, the most convenient way is to divide the application code into several levels of abstraction or layers, each of which performs its strictly defined function.

Layers in Software Design

Infrastructure Layer

The infrastructure is the outer layer through which all interaction of the application with the outside world takes place. The infrastructure layer contains all the code that works with the external dependencies of the application, such as databases, third-party services, API controllers, etc. It contains the implementation of entity repositories, adapters for working with message queues and external systems, libraries for working with the network, files, and even with a computer timer. Various ORMs and similar things are hidden here.

Application Layer

The application layer contains application services, interfaces of adapters and repositories with which these services work. Application services implement logic that coordinates the interaction of domain entities with the outside world through adapters. Services also manage the life cycle of aggregation roots: getting them from the repository, calling entity methods, initiating state saving, and deleting them from memory. Application services are intermediaries between the infrastructure and the entities of the domain, isolating them from each other. The application layer has no dependencies on the infrastructure layer.

Domain Layer

The domain layer, as the name implies, contains only the logic associated with the implementation of the domain requirements. All entities, aggregation roots, entity state objects and other domain items are located here. This layer has no references to other layers, and objects in this layer do not directly refer to objects in other layers. This ensures the purity and completeness of the domain, although it requires the implementation of additional logic.