DEV Community

Cover image for Clean Architecture : Infrastructure vs Core
Nicolas Lapointe
Nicolas Lapointe

Posted on • Edited on

Clean Architecture : Infrastructure vs Core

This article follows on from a more comprehensive presentation of Clean Architecture, which you can find here!

Imagine your application as a complex story between two essential protagonists: the Business Domain (Core) and the Technical Domain (Infrastructure). Their clear separation is the basis of Clean Architecture. Let's discover how this division, like a well-orchestrated score, optimizes the maintainability, scalability and clarity of your code.

In the complex world of application development, Clean Architecture stands out for its ability to clearly separate the business domain (Core) from the technical domain (Infrastructure). In this article, we'll explore in detail the separation between Core and Infrastructure that ensures better management of software complexities, as well as the importance of use cases as drivers of business rules.

Understanding the separation: Core vs Infrastructure

Before delving into the details, it's essential to understand the nature of this separation. Core represents the very essence of the application, where business rules and key concepts reside. Infrastructure, on the other hand, encompasses the technical details, such as database access or the management of external dependencies. This clear distinction ensures efficient management of the different aspects of your application: technical constraints are not mixed up with business rules.

The Business Domain (Core)

The Core is the rampart of business logic, where entities and use cases reside. Entities represent the key objects of the domain (the “core elements”, what we “present” to the business), while use cases direct the execution of business rules. This layer is the heart of the application, guaranteeing consistency and clarity of functionality.

The core can be divided into 2 layers: entities and use cases. Let's start with the first layer in the Core, Entities.

Nature of entities

Entities represent the fundamental concepts of the business domain. They encapsulate essential data and business rules, ensuring the consistency and integrity of information. Think of them as the main actors in a play, each with a defined role to play in the story.

For example, in an order management application, an entity might represent an order or a product.

Entities maintain strict independence from technical details, guaranteeing their reusability and scalability. This clear separation enables developers to concentrate fully on business logic without being distracted by technical considerations.

Compare this to the separation between the script of a play (Core) and the sets (Infrastructure) - the show can evolve without altering the main plot.

IllustrationImage from Freepik

Role of Use Cases

Use cases describe the application's functionality from the user's point of view. They coordinate the actions performed by entities to meet the application's functional requirements.

For example, a use case might be “Create a new order” or “Modify product details”.

Use cases also maintain a clear separation from Infrastructure, focusing solely on business logic. This approach enables agile scalability, where functionality can be added or modified without disrupting the application's structure.

The Technical Domain (Infrastructure)

Conversely, the Infrastructure is the technical backdrop to your application. It manages everything behind the scenes, from databases to external frameworks, ensuring that the Core remains isolated from the technical details. It will never encroach on business logic. It's like a discreet orchestrator, ensuring that technical details never compromise the clarity and simplicity of the core scenario.

Think of this layer as the production team in the movie world, ensuring that the show runs smoothly while remaining invisible to the viewer.

Illustration imageImage de frimufilms sur Freepik

Technical Details Management

The Infrastructure also provides interfaces for interacting with these components. For example, rather than accessing a specific database directly, the Core uses an interface defined with the Infrastructure to interact with the data.

Separation of responsibilities

Finally, an essential feature of the Infrastructure is its ability to separate responsibilities. Each component is designed to perform a specific task, making it easy to maintain and evolve that part too. For example, a component responsible for data access can be easily replaced or upgraded without affecting the rest of the application or even the rest of the technical part.

Advantages of Core vs. Infrastructure separation

The clear distinction between Core and Infrastructure offers many advantages for application development.

Maintainability and scalability

By isolating the business logic from the rest of the application, Clean Architecture facilitates code maintenance and evolution. Changes made to the Infrastructure have no impact on the Core, enabling technical components to be updated or replaced without disrupting business functionality.

For example, you can decide to change the SMS sending partner, without any impact on the business code, which remains unchanged.

Clear understanding of the Code Base

The distinction between Core and Infrastructure makes the code clearer and more comprehensible. As I often say, the team PO can even have an eye on the Core part, without necessarily having a technical background.

Developers can easily identify which parts of the application are responsible for the business logic and which are responsible for the technical details. This facilitates debugging, collaboration and long-term maintenance.

Core and Infrastructure, the heart of Clean Architecture

Clean Architecture, with its distinction between Core and Infrastructure, offers a solid, structured approach to application development. By fully understanding this separation and focusing on entities and use cases as the pillars of the business domain, you can create applications that are robust, scalable and easier to maintain.

This article is an introduction to Clean Architecture and is part of a dedicated series on this topic. Stay tuned for more!

Want to learn how implement it with typescript and express? See my udemy course! In french or english 😉

Articles on Clean Architecture:

Top comments (0)