# Clean Architecture And The Benefits Of Structured Software Design

> It's easy to get swayed by the latest trends, and lose sight of the architectural principles that really matter. One of the more popular ones is Clean Architecture, a design approach that prioritizes maintainability, scalability, flexibility, and productivity.

Published: 2022-12-24. Author: Milan Jovanović.

Canonical: https://milanjovanovic.tech/blog/clean-architecture-and-the-benefits-of-structured-software-design

Clean Architecture organizes a system around an inner circle that holds the business rules, with the Infrastructure and Presentation layers around it.
The dependency rule points inward: the outer layers depend on the core, and never the other way around.
That separation is what makes the business rules easier to unit test and easier to modify.

In the world of software development, there are countless approaches
and methodologies to choose from. It's easy to get swayed with the
latest trends, and loose sight of architectural principles that really matter.

One of the more popular ones is **Clean Architecture**, a design approach
that prioritizes maintainability, scalability, flexibility, and productivity.

In this week's newsletter, we will explore the key benefits of using
**Clean Architecture** and how it can help your team build better software.

Let's dive in.

## What Is Clean Architecture?

**Clean Architecture**, also known as "[**The Onion Architecture**](https://milanjovanovic.tech/blog/clean-architecture-vs-onion-vs-hexagonal)," was first
introduced by Robert C. Martin (aka "Uncle Bob") in his book
"Clean Architecture: A Craftsman's Guide to Software Structure and Design".

At its core, **Clean Architecture** is a way of organizing a software system
in a way that separates the concerns of the various components,
making it easier to understand and maintain.

In **Clean Architecture**, the core of the system is the **"inner circle"**,
which contains the business rules and logic.

Surrounding this **inner circle** are layers of abstraction,
each one representing a different concern.

![Clean Architecture layers with Domain at the center, surrounded by Application, Presentation, and Infrastructure](https://milanjovanovic.tech/blogs/mnw_017/clean_architecture.png)

The typical outer layers are **Infrastructure** and **Presentation** layers.
The **Infrastructure** layer handles external concerns such as APIs and databases.
While the **Presentation** layer exposes an interface for clients to interact with
the application.

The key principle of **Clean Architecture** is that the **inner circle**
should not depend on the outer layers. Instead, the outer layers should
depend on the **inner circle**. This helps to ensure that the **core** of the
system is flexible and easy to modify, without worrying about the impact
on other parts of the system.

## Benefits Of Using Clean Architecture

I want to highlight some of the key benefits of using **Clean Architecture**.

### Improved Maintainability

One of the primary benefits of using **Clean Architecture** is improved **maintainability**.
By separating the concerns of the various components and enforcing the [**dependency rule**](https://milanjovanovic.tech/blog/dependency-rule-clean-architecture),
it becomes much easier to understand and modify the code.
Depending on abstractions allows you to design your business logic in a flexible way,
without having to know the implementation details.

### Modularity and Separation of Concerns

**Clean Architecture** helps to create a clear **separation of concerns**
within the codebase. Each layer has a specific purpose and is decoupled
from the others, making it easier to understand and modify individual
components without affecting the rest of the system. This modularity
also makes it easier to reuse components in other projects.

### Testability

**Clean Architecture** also makes it **easier to test** and debug the code.
Because the inner circle is independent of the outer layers,
it's easier to write unit tests that focus specifically on the business
rules. This can help to catch errors early on in the development
process and reduce the overall testing effort.

### Loose Coupling of Components

**Clean Architecture** also promotes **loose coupling** between the various
components of the system. This means that it's easier to swap out
external dependencies or make other modifications without affecting
the core business logic. This can be especially useful when it comes
to upgrading or replacing technology.

### Increased Flexibility

Another key benefit of **Clean Architecture** is increased **flexibility**.
By separating the concerns of the various components, it's easier
to modify and adapt the code to changing requirements. This can be
especially useful in fast-paced environments where requirements
are constantly evolving.

### Improved Team Productivity

**Clean Architecture** can help to improve team **productivity**.
By establishing clear separation of responsibilities and well-defined
boundaries, it's easier for team members to understand their roles
and responsibilities. This can improve communication and collaboration,
leading to more efficient and effective work.

## Clean Architecture In The Real World

This all sounds nice in theory, but how does **Clean Architecture**
perform in the real world?

I have used **Clean Architecture** on roughly 10 projects in the
last 5 years, and I've had a lot of success with it. It was
easy to add new features, and scale the applications when
necessary. **Clean Architecture** can easily be broken down
into multiple modules or services, if performance is suffering
and there is a need to scale out.

One problem with the **Clean Architecture** is that it is [**easy to overengineer**](https://milanjovanovic.tech/blog/clean-architecture-anti-patterns).

Dogmatism is a real issue, as I see many people with strong
opinions of what **Clean Architecture** should be.
I've been guilty of this myself in the past.

Recently, I try to be more **pragmatic** when using **Clean Architecture**.
I apply what I like, and give myself the flexibility of **"breaking"**
**Clean Architecture** if I think it will simplify things in the long run.

## Closing Thoughts

By following the principles of **Clean Architecture**, you can create a flexible
and maintainable codebase that is well-suited to evolving requirements and technology.

However, it's important to be **pragmatic** with **Clean Architecture** and
allow yourself to be flexible in the design, in order to simplify things in the long run.

If you want to see how to apply **Clean Architecture** in practice,
I have a
[**playlist with more than 20 videos on Clean Architecture**](https://youtu.be/tLk4pZZtiDY?list=PLYpjLpq5ZDGstQ5afRz-34o_0dexr1RGa).

---

## Frequently asked questions

### What is Clean Architecture?

Clean Architecture, introduced by Robert C. Martin, organizes a software system around an inner circle that contains the business rules, surrounded by layers such as Infrastructure and Presentation. Separating these concerns makes the system easier to understand and maintain.

### What is the dependency rule in Clean Architecture?

The inner circle should not depend on the outer layers. Instead, the outer layers depend on the inner circle. This keeps the core of the system flexible and easy to modify without worrying about the impact on other parts of the system.

### What are the benefits of Clean Architecture?

Improved maintainability, clear separation of concerns, easier testing of the business rules, loose coupling that lets you swap external dependencies, flexibility to adapt to changing requirements, and better team productivity through well-defined boundaries and responsibilities.

### Does Clean Architecture make testing easier?

Yes. Because the inner circle is independent of the outer layers, it is easier to write unit tests that focus specifically on the business rules. That helps catch errors early in development and reduces the overall testing effort.

### What are the downsides of Clean Architecture?

It is easy to overengineer, and dogmatism is a real issue among people with strong opinions about what Clean Architecture should be. I try to be pragmatic: apply what works, and allow yourself to "break" Clean Architecture when that simplifies things in the long run.

### Does Clean Architecture work in real projects?

In my experience, yes. I used it on roughly 10 projects over 5 years, adding new features and scaling was easy, and a Clean Architecture codebase can be broken down into multiple modules or services if performance suffers and you need to scale out.
