Skip to content

Looking at the Big Picture

Why Clean Architecture Is Just as Important as Clean Code

A group of people holding plants in their hands

Photo from feey on Unsplash

The Last Stage of Our Journey

We have almost reached the end. Today, on the final content day of our Clean Code adventure (tomorrow there will be a conclusion), we raise our view from the code level to the system as a whole. This step requires a broader understanding and the ability to look at our software from a bird's eye perspective. Because even if every single line of code adheres to Clean Code principles, it doesn't guarantee a long-term maintainable system architecture.

The Fundamental System Elements

Recurring elements can be identified in every software system. The two most important ones are creation and application. Every system must be assembled from various components – services, repositories, domain objects, database connections, and many more. The creation of these components should be consistently separated from their use in business logic. This follows the well-known Single Responsibility Principle (SRP) and the concept of "Separation of Concerns," albeit at a higher level of abstraction.

This basic principle can be applied to almost any system. Modern frameworks support us through Dependency Injection, such as the Spring Container, which elegantly implements this separation.

Cross-Cutting Concerns

Another central example for the separation of concepts at the system level are the so-called "Cross-Cutting Concerns." These aspects permeate all parts and layers of an application and include:

  • Security

  • Performance measurement

  • Exception handling

  • Monitoring

  • Communication

  • Logging

The challenge: Without appropriate structuring, the corresponding code can heavily overlay the actual business logic. If every second business method contains a log output, there is a structural problem. For such cases, we typically use AOP (Aspect Oriented Programming). In languages like Go, middlewares are often used instead. For logging, for example, an aspect can be implemented that automatically records method calls including parameters – usually sufficient for effective problem analysis.

Other Important System Aspects

In the context of Clean Code architecture, there are numerous other relevant topics:

  • Testing architecture

  • Architectural decision processes

  • The use of established standards

  • Domain Specific Languages for system and architecture

  • and many more

Today's Impulse

My recommendation: Take regular breaks to look at your system as a whole. A simple visualization can be enormously helpful and significantly simplify further programming. Ask yourself where your "cross-cutting concerns" lie, where your objects are created, and where your business logic is located.

Particularly valuable is the question of consistent terminology: Are the terms used uniform and appropriate for the system? A software system is like a small town – it consists of many different elements, and each has a name and a role. When you identify and organize these, working with the system becomes significantly easier and more intuitive.

Author

Sebastian Bergandy
Sebastian Bergandy