Clean Architecture

Let’s understand what clean architecture means.

Every production system, whether it’s a software package, a mechanical device, or a simple procedure, is made up of components with unique connections between those components. The purpose of these connections is to use the outputs of some components as inputs to others. This allows us to perform a particular action or set of steps.

Within a process, the architecture specifies which components are part of the implementation and how they’re interconnected.

An example of this is the process of writing a document. We can define this process as the conversion of a set of ideas and sentences into a written text. It can take the form of multiple implementations, for example, when someone writes with a pen and paper. This becomes more complex when we add more people to the process. Perhaps we introduce someone who dictates what to write. We could also have multiple proofreaders to check the text and suggest edits, as well as a designer to curate the visual rendering of the text.

In all these cases, the process itself is the same. The nature of inputs (ideas and sentences) and outputs (a document or a book) doesn’t change. However, different architecture can significantly affect the quality of the production or the speed with which it’s produced.

An architecture can have many granular details, which can have different levels that we can “zoom” into when we look at its components and their connections. The first level describes the whole process as a black box with inputs and outputs. At this level, we aren’t concerned with the components of the system or how they work. We only know what the system does.

As we zoom in, we start to discover the architecture’s details, namely which components are in the aforementioned black box and how they’re connected. These components are, in turn, black boxes themselves. The most interesting things for us to know here are their inputs and outputs, where the inputs come from, and how the outputs are used by other components.

This process is virtually unlimited. So, there is never one single architecture that describes a complete system. Instead, there are sets of architectures, each one covering the granular detail we’re interested in.

Why it’s called clean architecture

The architecture explained in this course has many names, but the one that is mainly used now is clean architecture. This name was used by Robert Martin in his book Clean Architecture: A Craftsman’s Guide to Software Structure and Design. Although the idea of this structure has also been promoted by software designers over the years. The adjective “clean” in clean architecture describes one of the fundamental aspects of software structure as well as its development approach. It’s clean in the sense that it’s easy to understand the code and what it does.

Clean architecture is the opposite of spaghetti code, where everything is intertwined. The elements aren’t easily detached from each other and can’t be replaced without collapsing the whole system. The main benefit of clean architecture is the ability to clearly identify where something is and why. It’s always a good idea to ensure this when we design and implement a new software system. This clarifies which architecture or development methodology we want to follow.

Clean architecture is not necessarily the right solution for all scenarios, and requires some planning before we decide to use it. Like any other solution, it addresses a set of problems and tries to solve them, but there’s no universal remedy that’ll solve every problem. As was mentioned above, it’s important to understand how clean architecture solves a problem, and then we can decide if that solution suits our needs.

We’ll use Python to demonstrate the concepts that we learn in this course. Python is a very powerful programming language that has been around for many years. It has become one of the preferred languages for many programmers around the world and is a great language to demonstrate the benefits of clean architecture.

Therefore, it’s important to have some knowledge of Python to understand the examples and the project we present in this course. The main concepts discussed in this course are also useful for other programming languages, especially object-oriented ones.