What is clean architecture?

Pradyuman Tomar
3 min readAug 20, 2021

--

Architecture means the overall design of the project. It’s the organization of the code into classes or files or components or modules. And it’s how all these groups of code relate to each other. The architecture defines where the application performs its core functionality and how that functionality interacts with things like the database and the user interface.

Clean architecture refers to organizing the project so that it’s easy to understand and easy to change as the project grows. This doesn’t happen by chance. It takes intentional planning.

Characteristics of a clean architecture

The secret to building a large project that is easy to maintain is this: separating the files or classes into components that can change independently of other components. Let’s illustrate that with a couple of images.

In the image above, if you want to replace the scissors with a knife, what do you have to do? You have to untie the strings that go to the pen, the ink bottle, the tape and the compass. Then you have to retie those items to a knife. Maybe that works for the knife, but what if the pen and the tape say, “Wait, we needed scissors.” So now the pen and the tape don’t work and have to be changed, which in turn affects the objects tied to them. It’s a mess.

Compare that to this:

Now how do we replace the scissors? We only have to pull the scissors’ string out from under the Post-it notes and add a new string that is tied to a knife. Way easier. The Post-it notes don’t care because the string wasn’t even tied to it.

The architecture represented by the second image was obviously easier to change. As long as the Post-it notes don’t need to be changed often, this system will be very easy to maintain. This same concept is the architecture that will make your software easy to maintain and change.

The inner circle is the domain layer of your application. This is where you put the business rules. By “business” we don’t necessarily mean a company. It just means the essence of what your application does, the core functionality of the code. A translation app translates. An online store has products to sell. These business rules tend to be fairly stable since you are not likely to change the essence of what your app does very often.

The outer circle is the infrastructure. It includes things like the UI, the database, web APIs, and frameworks. These things are more likely to change than the domain. For example, you are more likely to change how a UI button looks than you are to change how a loan is calculated.

A boundary between the domain and the infrastructure is set up so that the domain doesn’t know anything about the infrastructure. That means the UI and the database depend on the business rules, but the business rules don’t depend on the UI or database. This makes it a plugin architecture. It doesn’t matter if the UI is a web interface, a desktop app, or a mobile app. It doesn’t matter if the data is stored using SQL or NoSQL or in the cloud. The domain doesn’t care. This makes it easy to change the infrastructure.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response