Clean architecture - Hexagonal architecture, Screaming architecture, DCI, BCE
The content here is under the Attribution 4.0 International (CC BY 4.0) license
Separation of concern, isolating pieces of code that repeats and decoupling responsibilities from different parts of the code base seems to be a common approach among experienced developers. Maximiliano Contieri for example, named coupling the only software design. Therefore, through the experience comes the opinionated approach, some developers might decide to create specific directories or others might use longer file names to express intent.
I have published my own thoughts on that matter as well, and then I discovered the clean architecture book , which dives much deeper on that subject and also explores the pros of having an architecture in place.
As a companion for this post I recommend the talk “The Principles of Clean Architecture” by Uncle Bob Martin as well as the playlist that I built on software architecture in general .
Architectural styles compared to the clean architecture
As I first started my path through the clean architecture I often found asking myself: is hexagonal architecture  the same as clean architecture? The clean architecture, shares decisions compared with the hexagonal architecture, as  states that the clean architecture is an attempt to integrate the hexagonal architecture and other as well, named:
- Hexagonal architecture / Onion architecture
- Screaming architecture
- DCI (Data, Context and Interaction)
- BCE (Boundary, Control, Entity) 
The clean architecture is an attempt to combine those styles together to produce an output, in short, it tries to combine the good parts of every other style into a one.
Clean architecture in a glance
Clean architecture focuses on the separation of concerns and also it takes care of the evolution of the code, the evolution is one of key aspects of the clean architecture as it has a dedicated section in the first chapter, “The Total Cost of Owning a Mess”,  that depicts the fact that the productivity degrades as the time goes. Which is caused by the lack of care with code and also the software maintainability. The following diagram taken from  depicts the clean architecture overview.
The structure I am following next is the same presented by , so then I can follow some line of thought, besides that I also give my contribution to each section.
The dependency rule
The dependency rule follows basically the same principle as the layered architecture. . Anything in the inner circle should not know anything about the outer circle, the same principle in the layered architecture, to keep layers following a same direction.
Entities are the objects that represents the business.
Use cases are the business rule that the application executes. Here is the place to add the business logic. In a comparison with MVC, the use case, is the place as where the controller is.
Frameworks and adapters
Opposed to what MVC frameworks impose in the architecture for web applications, the clean architecture does not take the framework as something that is the core of the application, instead the framework is something that is a “implementation detail”, meaning that it is possible to change the framework choice if needed, without impacting the use cases. The same way as the framework is a detail the database is as well .
The book comes with code examples to illustrate the scenarios and also to make statements on the point being made, therefore, there is no folder structure, file name convention or what so ever to “glue the pieces together”. This is a point to improve, but not necessary in the book. I would argue that for any programmer with a few years of experience, the concepts given are understandable, but there are programmers like me that like some sort of guide lines so the it is possible to compare implementations.
 provides an implementation of clean architecture using java. It goes along the clean architecture definitions and depicts folder structure, files, boundaries, abstractions and also reinforce definitions on the use cases.
- Steve Pember shared his thoughts on his talk entitled “Anatomy of a Spring Boot App with Clean Architecture by Steve Pember” at Spring I/O 2023. His thoughts, vision and implementation matchs with the points shared in here. Besides, he also offers an out-of-the-box implementation and direction based on the clean architecture book that is available on GitHub.
- R. C. Martin, “Clean Architecture A Craftsman’s Guide To Software Structure And Design,” 2017 [Online]. Available at: https://archive.org/details/CleanArchitecture/page/n179/mode/2up. [Accessed: 2020-Jun-11AD]
- M. Marabesi, “Software architecture,” 2020 [Online]. Available at: https://youtube.com/playlist?list=PLN7yVcqYnDlWcwm8BwiHiyMTXdpozIIXR. [Accessed: 14-Aug-2021]
- A. Cockburn, “Hexagonal architecture,” 2012 [Online]. Available at: https://alistair.cockburn.us/hexagonal-architecture. [Accessed: 13-Aug-2012]
- R. C. Martin, “The Clean Architecture,” 2020 [Online]. Available at: https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html. [Accessed: 07-Oct-2020]
- I. Jacobson, “The use-case construct in object-oriented software engineering,” in Scenario-based design: envisioning work and technology in system development, 1995, pp. 309–336.
- R. Mark, Software Architecture Patterns. O’Reilly Media, Inc, 2015.
- T. Hombergs, “Get Your Hands Dirty on Clean Architecture - A Hands-on Guide to Creating Clean Web Applications with Code Examples in Java,” 2020 [Online]. Available at: https://leanpub.com/get-your-hands-dirty-on-clean-architecture. [Accessed: 30-Jan-2020]
Table of contents
- Architectural styles compared to the clean architecture
- Clean architecture in a glance
- Implementation details
- Related work