Clean Architecture Principles

Kiran Mushnuri
2 min readOct 1, 2023

In this article, I am talking about the principles that we need to consider and adopt for clean architecture.

To start with, a clean architecture primarily consists of 4 layers:

  1. Domain Layer
  2. Application Layer
  3. Adapter Layer
  4. Infrastructure Layer

Domain Layer: It will be the fundamental building block of clean architecture. It consists of enterprise business rules, entities that are essential to building an application or service. Domain Layers don’t have any knowledge about the other layers. In this way it provides the highest levels of abstraction. This domain layer can be used by more than applications.

Application Layer: The application layer, which sits outside of this core, contains the rules and logic that relate specifically to the application’s design and behaviour. While business rules in domain layer cater across enterprise, rules in application layer confine to only one specific application. This layer also includes the ‘use cases’ pertaining to an application.

Adapter Layer: It holds APIs and gateways, which govern the flow of communication between the application’s back end and the external components. This layer is responsible for elements like application presenters, views and controllers.

Infrastructure Layer: This is the highest level of layer which serves up all necessary details pertaining to the particular web frameworks or database models in use. It consists of web frameworks, database, libraries.

Fundamentally our layers should be formed in such a way that each one is abstracted from another. If we change a database or web framework, the other layers shouldn’t be impacted.

Principles of Clean architecture:

  1. Independent of any framework: The layers must be so well separated that they can survive individually, without the need for externals
  2. Testable: Each module, both UI, database, API Rest connection, etc., must be able to be tested individually.
  3. Common reuse: segregate the layers in such a way that any layer can easily be reused
  4. SOLID principle:

a) Single responsibility principle

b) Open to extension, closed to modification

c) Liskov Substitution Principle

d) Interface Segregation Principle

e) Dependency Inversion Principle

SOLID principles help us to make sure our application and modules are light weight and independent to each other.

SOLID principles help us to make sure our application and modules are light weight and independent to each other.

Conclusion: Clean architecture is programming language agnostic. We can use those principles while building an application or service. We can combine programming paradigms to create microservices especially. Following clean architecture while designing and developing your solution makes it testable and more independent from libraries, frameworks, databases and provides better maintainability in the long term.

If you have any questions, on this article, feel free to reach out to me through my email id : kiran.mvv@gmail.com or LinkedIn — https://www.linkedin.com/in/kiran-mushnuri-7b09a73b/

--

--

Kiran Mushnuri

AWS Solution Architect Professional and having experience in Pivotal Cloudfoundry.