What is Clean Software Architecture?

What is Clean Software Architecture?

“Clean Software Architecture” is a type of software architecture that focuses on the separation of concerns, thereby increasing the maintainability and testability of an application. This architecture separates an application into multiple layers by depicting each of the layers as a concentric circle.

This architecture follows a rule called the?Dependency Rule?that states that?the flow between the layers should move towards the inner circle. This, in turn, means that the inner circle should not be bothered by what happens in the outer circle. By using this rule, the outer circle won’t have any effect on the inner circles.

?The original architecture lists about 4 layers.

?1. Domain Layer

·??????? This is the innermost layer, consisting of entities or any objects/functions/code which can transform the data. The entities should not change if we move from one framework to another.

·??????? The entities should not be affected by some external change. For instance, a function that adds a user to a “users” table should not know how it is being added. It only deals with accepting the new user and returning the updated “users” table with the newly added user.

?2. Application Layer

·??????? This layer deals with the use cases or user scenarios of the application. It is responsible for containing the business logic or all the functionality present in the application. The use cases are application-specific and should not depend on UI, external systems, or any framework.

·??????? For example, in a use case where we need to search for a book, it would deal with finding the book in the database, applying some filters, and returning the searched book as a result. This use case can interact with entities like books and categories.

?3. Adapter Layer

·??????? This layer is responsible for converting data from use cases into a desired format that can be stored in external sources, such as a database.

·??????? This layer contains three things:

o?? Controllers:?Handle input from external sources and hold references to use cases

o?? Presenters:?Responsible for implementing the interface by taking data from the use cases

o?? Gateways:?Interfaces that enable the application to interact with databases, services, or frameworks

?4. Infrastructure Layer

·??????? This layer contains frameworks and tools like the database, external interfaces (any library for authentication), UI components, the web (network requests), and any devices such as printers or scanners. The core business logic is kept isolated from this layer.

·??????? For instance, code in this layer can connect to a?SQL database, send?HTTP requests?to a web service, or manage routes.

?Advantages of Clean Frontend Architecture

·??????? Separation of concerns: Having separation of concerns makes it easier to comprehend the code structure as everything is divided into its own layers, making them lightly coupled with each other.

·??????? Modularity: Dividing the code in such a way that each function/class/component does only one thing makes the code pretty easy to read and maintain. Moreover, if anything fails, it would be easier to find where the cause of the failure lies.

·??????? Maintainability: Separating the concerns along with breaking down the code into smaller chunks increases the maintainability of the whole application, thereby making it easier to read.

·??????? Testability: If the functionalities in the code are decoupled from each other, it makes it easier to test the application. When it comes to the layers, it is possible for us to test each layer independently.

·??????? Improved collaboration: By implementing a set of guidelines and real-world programming principles, the code can be standardized, which can make collaborating on an application easier.

·??????? Scalability: Separating different functionalities and isolating components gives a lot of opportunities to add more functionalities, thereby scaling the application to a whole new level. This can also improve collaboration between the team members, as they can work on the application independently.

?Disadvantages of Clean Frontend Architecture

Although there are numerous benefits that we get from applying a clean frontend architecture, it can also have multiple disadvantages.

·??????? Difficult to onboard:?It is essential to have a good understanding of the various principles involved in creating a clean frontend architecture, but that requires a learning curve. That can be time consuming and hence, it can be detrimental to the project if the development time is slower than what is required.

·??????? Increased codebase size:?Making the application more modular can lead to dividing the modules into their own files and folders, resulting in a large codebase. This may introduce more complexity than is necessary.

·??????? Maybe overkill for small applications:?If a lot of principles or highly modular architecture is introduced in a relatively smaller or less complex codebase, it can cause complexity issues unnecessarily. This is a common result of over-engineering.

?Conclusion

Implementing a clean architecture in our application can do wonders if applied correctly. It can make our application more readable, testable, scalable, and maintainable. In this article, we discussed what a?clean software architecture?is, the?different principles?that we should know, and the?pros and cons?of having a clean software architecture.

Make sure that you understand the requirements of the application and do not over-engineer things or force your application to have a clean frontend architecture, as it can bring a lot of new issues if not applied correctly.

要查看或添加评论,请登录

Jeetendra Gawas的更多文章

  • REST API IMPLEMENTATION WITH FLASK

    REST API IMPLEMENTATION WITH FLASK

    What are API’s ? ? API stands for “Application Programming Interface.” An API is a software intermediary that allows…

    2 条评论
  • What are “SOLID Principles”?

    What are “SOLID Principles”?

    What are “SOLID Principles”? SOLID is a popular acronym in software engineering that consists of five principles that…

  • Quick comparison for FastAPI vs. Django Rest Framework in Python

    Quick comparison for FastAPI vs. Django Rest Framework in Python

    In the world of web development, building robust and efficient APIs is a fundamental requirement. Two popular choices…

社区洞察

其他会员也浏览了