Clean architecture is a system of architecture that is made with the guidelines of Robert C. Martin. These proposed guidelines have been derived from the guidelines of the Onion architecture, Hexagonal architecture etc. These guidelines are commonly followed by software engineers for building software that offers scalability, easy testing and maintenance. The goal you are trying to achieve with the help of software architecture is to use minimal human resources for building and maintaining a required system. The software that has a good and clean architecture is easy to test, easy to maintain and change. Its development, as well as deployment, is seamless and it can work independently.
The Dependency Rule
This rule dictates that the dependencies of the source code should only print onwards. This means that the things that are in the inner circle of the software architecture can not know anything of the things that are in the outside circle. The inner-circle elements cannot have any dependencies on the elements of the outer circle.
This is considered important as it makes the whole architecture work. But it can surely be quite comprehensive to understand and accomplish. Breaking down the rule can help understand what issues it can lead to and how to keep up with them while implementing this rule for a clean architecture.
First, frameworks and drivers should have a dependency on the adapters of the interface, which in turn depends on the business rule application, which is dependent on business rule enterprise. The bottom or inner layer is not dependent on the upper or outer layer.
Frameworks and Drivers
This is the area of the software that will contain the user interface as well as the database. The external interface like the Native API contains the web and devices. The interface adapter is the layer of the software that holds the presenters like the logic of the user interface as well as the states.
It also contains the controllers, the interface that contains the functions that will be necessary for the application while being implemented by a device, the web or the external interface. Gateways are the interfaces that contain the CRUD operations that are performed by the application and implemented by the database.
Application Business Rules
These are those rules that do not fall under the category of core business rules but are necessary for a particular application. This is the layer or area of the software that contains the use cases. As is suggested by the name, these provide the use cases of the application, it is holding the functionalities that are provided by the software.
This is the layer that will determine which gateway or controller will be called upon for a specific use case. Some use cases may need controllers or gateways from different functions. This is the area where the various functions will work in coordination. If the developer wants the application to apply a discount on the purchase of a particular user for one item in a month, this is the area where it will happen.
The application will have to get the amount the user is spending in that month from the function of purchases, then apply the discount on the result obtained on the checkout function of the user. A function can be made for allying to the discount, that will call the controller of the purchase function and apply the discount in the module of the checkout.
Enterprise Business Rules
This is the area of the software that contains that core business rule, business rules that are domain-specific. This is also the layer that is the least likely to change. Changes made in any of the outer layers will not have any effect on this layer. Because the business rules do not change very much, a change in this layer of the software is rare. This is that one layer which will contain the entities.
An entity in this layer may be a core data structure that is required for the business rules, or it may be an object that has the functions that contain the logic of the business rules. To calculate interest, a module in the banking application will contain the business logic and will be inside this layer.