Separates the system into layers, so that the more important a layer is, the more protected it is
The great villain of software development is the coupling between components, so the clean architecture has a layer separation model that can be represented by the image below:
The arrows indicate how each layer communicates data with another.
This separation of concerns allows for a clear separation of business rules from external services and user interface, making the code more modular, testable, and easy to maintain. Additionally, by keeping the core business rules in the center and external services on the outer layers, it makes it easier to change or replace external services without affecting the core business rules. It also makes the system more flexible and adaptable to changing requirements. Overall, the goal of clean architecture is to create a maintainable and scalable software system that is easy to understand, test and modify.
In summary, the layers could be described as follows:
These are the most core and independent classes of the system. They represent the business rules and do not depend on any external services. For example, in an e-commerce application, an Entity might be a Product class with properties such as id, name, and price.
}
}
These classes handle specific business logic and interact with the Entities. They depend on the Entities, but not on any external services. For example, in an e-commerce application, a Use Case might be a AddProduct class that takes a Product instance and adds it to the cart.
}
}
}
These classes handle the interaction between the Use Cases and external services such as databases, APIs, and the user interface. They depend on the Use Cases but not on any external services. For example, in an e-commerce application, an Interface Adapter might be a ProductRepository class that takes a Product instance and saves it to a database.
}
}
}
These are the external services such as databases, APIs, and the user interface that the system depends on. They are the outermost layer and depend on the Interface Adapters. For example, in an e-commerce application, a Framework & Driver might be a Express server that handles HTTP requests and responses.
app.
res.
});