2. 2
Nenad Jankovski
Backend Java developer
Passionate about:
• Clean code
• Clean architecture
• System design
• Agile methodologies
• FC Bayern München
About me
Clean Architecture
3. 3
Why architecture matters
Clean Architecture
Benefits of good architecture
How to achieve good architecture
Don’t be overconfident!
Remember the race of the turtle
and the hare?
4. 4
The tale of two values
Behavior - states what the software can do
Structure - the ease and promptness of creating and
changing features in an existing system
4
Clean Architecture
5. 5
The tale of two values
Clean Architecture
Not Urgent
Urgent
Important
Not
Important
Urgent and Important
The Feature That
Stakeholders Need Most
Not Urgent and
Important
Architecture itself
Urgent and Not
Important
A feature that may be
just beautification
Not Urgent and Not
Important
Features with small
contributions
Dwight D. Eisenhower Matrix
I have two kinds of problems, the urgent and
the important. The urgent are not important,
and the important are never urgent.
If we translate this quote into the software
world then we can conclude that behaviour is
urgent but not important and structure is
important but not urgent.
5
9. 9
Layered architecture
Clean Architecture
Substitute layers with
alternative implementations
Defer decisions about layer
implementation
Dependencies between layers are
minimized
Coupling is evil, it kills you.
Big bowl of mud is coupling gone crazy
10. 10
Coupling is the property that one
module is forced to change because
another one changes
Cohesion is the property that a
module is subject to the same forces
of change
Layered architecture
Clean Architecture
Low coupling, high cohesion
11. 11
The domain layer. Contains two
types of business logic
1. Domain logic
2. Application logic
There are two basic
implementation logic to split the
domain layer
1. Domain façade – Apart from the
application logic, no other logic
2. Operation script – CRUD based
service
Layered architecture
Clean Architecture
11
Domain logic layer can be split
into two layers
1. Service Layer
2. Entity layer
16. 16
The Clean Architecture
Clean Architecture
Entities
Use Cases
Controllers
External
Interfaces
DB UI
Web
Devices
Enterprise Business Rules
Application Business Rules
Interface Adapters
Frameworks & Drivers
Presenter
Controller
Use Case
Outout Port
Use Case
Interactor
Use Case
Input Port
<I>
<I>
Flow of control
17. 17
Clean architecture – data flow
Clean Architecture
View Model
Presenter
Controller
View
Request Model
Boundary
Boundary
Resonse Model
<I>
<I>
Interactor
Entity Gateway
Entity Gateway
Implementation
Database Api
Entity
Entity
Entity
<I>
21. 21
Pros and Cons
Clean Architecture
PROS CONS
Doman stability Heavy (in classes)
Testing Indirect (a lot of interfaces)
Framework independence Learning curve (dep. inversion)
Database independence
UI Independent
Readability
Flexible
22. 22
Hints
22
Don’t use your Entity objects as data
structures to pass around in the outer
layers. Create separate data model
objects for that.
The top-level organization of your project
should clearly tell people what your
project is all about.
This is called screaming architecture.
Clean Architecture