SlideShare a Scribd company logo
CLEAN
ARCHITECTURE
Flavius Ștef, Syneto
Timișoara, Oct. 2018
CODING IS HARD
ENOUGH ALREADY
Programming language
Libraries
Front-end framework
Back-end framework
AWS or Azure
sync vs async
trees and graphs
ML
...2
Why also bother with architecture?
Layered, MVC, REST, Microservices...
3
TWO PHASES FOR EACH CODEBASE
4
Puberty
MVP, 0.9beta, 1.0
Code familiarity
Progress
Maturity
Value delivery
Speed
Quality
Architecture
matters the
most here
ARCHITECTUREtries to solve an economic set of needs,
not a technical one
5
Average codebase life:
10 years
6
SYNETO ARCHITECTURE NEEDS
Steady Velocity
In the marketplace
High quality
Limited margin for errors
Easy onboarding
Of new team members.
Reuse components
As we build new features
Test automation
To catch errors fast.
Code readability
Change code with confidence.
7
YOUR NEEDS?
Reuse, automation, readability
Security
Scalability
Velocity
8
CLEAN ARCHITECTURE
By Robert “Uncle Bob” Martin
Code maintenance and evolution
9
1.
MAINTAINABLE CODE
General principles
What gets in the way?
11
Dependencies
12
PRINCIPLE #1Limit dependencies
13
Encapsulation
All related code should be in the
same class/module.
LIMIT DEPENDENCIES
Cohesion
All code in the same
class/module should be related.
14
👍 👎
“every module or class should
have responsibility over a
single part of the functionality
provided by the software, and
that responsibility should be
entirely encapsulated by the
class.
-- Wikipedia (SRP)
15
SRP
16
# $ %
MODULE LEVEL
DEPENDENCY MANAGEMENT
▪ How do we group classes together?
▪ How do the dependencies point?
▪ Who creates the clases?
17
Big Ball of Mud
HOW DO WE GROUP CLASSES?
18
MVC / MVVM / MVP Layered
Controller
Model View
UI
Business
Database
PRINCIPLE #2Introduce boundaries between modules
19
Big Ball of Mud
DEPENDENCIES
20
MVC / MVVM / MVP Layered
Controller
Model View
UI
Business
Database
CLEAN ARCHITECTURE
21
Business
Logic
Application
Logic
Infrastructure
concrete abstract
PRINCIPLE #3Dependencies point in the direction of the abstraction
22
23
SMTPSenderInvoiceGenerator
MailSenderInvoiceGenerator
SMTPSender
PRINCIPLE #4Inject dependencies
24
25
class InvoiceGenerator {
private SMTPSender sender;
public InvoiceGenerator() {
sender = new SMTPSender();
}
}
// client
InvoiceGenerator g = new InvoiceGenerator();
interface EmailSender { public void sendEmail(); }
class SMTPSender implements EmailSender { ... }
class AWSEmailSender implements EmailSender { ... }
class CleanInvoiceGenerator {
private EmailSender sender;
public CleanInvoiceGenerator(EmailSender s) { sender = s; }
}
// client
CleanInvoiceSender s = new InvoiceSender(new SMTPSender());
CleanInvoiceSender s = new InvoiceSender(new AWSEmailSender());
MAINTAINABLE CODE PRINCIPLES
▪ Limit dependencies
▪ Introduce boundaries between modules
▪ Dependencies point in the dir. of the abstraction
▪ Inject dependencies
26
2.
CLEAN ARCHITECTURE
Putting it all together
CHARACTERISTICS
1. independent of frameworks
2. testable
3. independent of the UI
4. independent of the database
5. independent of any external agency
28
“your business rules don’t know
anything at all about the
interfaces to the outside world.
-- R. Martin, Clean Architecture
29
30
Entities
“VAT of 19% will be applied to all sold
items, except for books where VAT is 5%”
“You cannot power off a powered off VM
Enterprise Rules
31
Entities
Enterprise Rules
Use Cases
Application Rules
“send a SMS to the client after we have
successfully approved his meal order”
32
Entities
Enterprise Rules
Use Cases
Application Rules
33
Entities
Enterprise Rules
Use Cases
Application Rules
Web
UI
Devices
DB
Frameworks & Drivers
34
Entities
Enterprise Rules
Use Cases
Application Rules
Web
UI
Devices
DB
Frameworks & Drivers
Controllers
Interface Adapters
35
public class App {
...
static void main(String[] args){
...
dbConn = new MysqlConnection(...); // framework
view = new HTMLView(...); //framework
repository = new MysqlRepository(dbConn); // interface adapter
controller = new Controller(getRequest()); // interface adapter
presenter = new Presenter(view); // interface adapter
useCase = new ListOrders(controller, repository);
useCase.addPresenter(presenter);
useCase.run();
...
}
...
}
36
Entities
Use Cases
Web
UI
Devices
DB
Controllers
FLOW OF
CONTROL
37
AN
EXAMPLE
38
Entities
Use Cases
Web
UI
Devices
DB
Controllers
DEPENDENCIES
3.
FINAL WORDS
A few tips and tricks and summary
TIPS
Analyze the investment
Clean architecture is not cheap
40
Use it with DDD and CQRS
It maps nicely
Don’t be too rigid
Figure out which rules can be broken
Spend time understanding the layers
What should go in infrastructure, app and domain
CLEAN ARCHITECTURE IS
ReadableTestable Reusable Evolvable
THANKS!
Any questions?
You can find me at:
@flaviusstef
flavius.stef@gmail.com
slideshare.net/fstef
42

More Related Content

PDF
Introducing Clean Architecture
PPTX
Clean architecture
PPTX
Clean architecture
PDF
Clean Architecture
PPSX
SOLID Principles and The Clean Architecture
PDF
Clean Architecture
PPTX
Clean Architecture
PDF
Clean architecture with asp.net core
Introducing Clean Architecture
Clean architecture
Clean architecture
Clean Architecture
SOLID Principles and The Clean Architecture
Clean Architecture
Clean Architecture
Clean architecture with asp.net core

What's hot (20)

PPTX
Dependency Inversion Principle
PPTX
Microservice vs. Monolithic Architecture
PDF
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
PPTX
Clean Code
PPT
SOLID Design Principles
PPTX
The Clean Architecture
PDF
2012 the clean architecture by Uncle bob
PPTX
Clean architecture
PPTX
No Onions, No Tiers - An Introduction to Vertical Slice Architecture by Bill ...
PDF
Introduction to ASP.NET Core
PDF
Clean architecture
PPTX
Clean Pragmatic Architecture - Avoiding a Monolith
PPTX
Introduction to React JS for beginners
PPTX
Microservices Architecture - Bangkok 2018
PDF
Hexagonal architecture for java applications
PPTX
React workshop presentation
PPTX
Microservices architecture overview v2
PDF
Clean architecture - Protecting the Domain
PPTX
Domain Driven Design
PPTX
Design Pattern - MVC, MVP and MVVM
Dependency Inversion Principle
Microservice vs. Monolithic Architecture
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Clean Code
SOLID Design Principles
The Clean Architecture
2012 the clean architecture by Uncle bob
Clean architecture
No Onions, No Tiers - An Introduction to Vertical Slice Architecture by Bill ...
Introduction to ASP.NET Core
Clean architecture
Clean Pragmatic Architecture - Avoiding a Monolith
Introduction to React JS for beginners
Microservices Architecture - Bangkok 2018
Hexagonal architecture for java applications
React workshop presentation
Microservices architecture overview v2
Clean architecture - Protecting the Domain
Domain Driven Design
Design Pattern - MVC, MVP and MVVM
Ad

Similar to Clean Architecture (20)

PDF
Building Cloud-Native Microservices with .NET 8 and Minimal APIs.pdf
PPTX
Micro Front-End & Microservices - Plansoft
PDF
Midwest PHP Presentation - New MSQL Features
PPTX
Horizontal Scaling for Millions of Customers!
PPT
Integration in the Cloud
PDF
[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...
PDF
APIdays Paris 2019 - Cloud native API Management for Microservices on a Servi...
PPTX
Serverless: The next major shift in cloud computing
PDF
Enterprise Integration in Cloud Native Microservices Architectures
PPTX
Microservices for performance - GOTO Chicago 2016
PPTX
Microservices at ibotta pitfalls and learnings
PDF
linkerd.pdf
PPTX
Microservices in the cloud at AutoScout24
PDF
Migrate to Microservices Judiciously!
PDF
OpenStack in Enterprise
PDF
Integration in the Cloud, by Rob Davies
PDF
Docebo: history of a journey from legacy to serverless
PPTX
GOTO Amsterdam 2017 - Enterprise Fast Lane
PPTX
GOTO Berlin 2016
PPTX
.net Framework
Building Cloud-Native Microservices with .NET 8 and Minimal APIs.pdf
Micro Front-End & Microservices - Plansoft
Midwest PHP Presentation - New MSQL Features
Horizontal Scaling for Millions of Customers!
Integration in the Cloud
[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...
APIdays Paris 2019 - Cloud native API Management for Microservices on a Servi...
Serverless: The next major shift in cloud computing
Enterprise Integration in Cloud Native Microservices Architectures
Microservices for performance - GOTO Chicago 2016
Microservices at ibotta pitfalls and learnings
linkerd.pdf
Microservices in the cloud at AutoScout24
Migrate to Microservices Judiciously!
OpenStack in Enterprise
Integration in the Cloud, by Rob Davies
Docebo: history of a journey from legacy to serverless
GOTO Amsterdam 2017 - Enterprise Fast Lane
GOTO Berlin 2016
.net Framework
Ad

More from Flavius Stef (13)

PDF
Five Things I've Learned in Ten Years of Agile
PPTX
Product ownership versus product management
PDF
Is management dead?
PDF
Big rewrites without big risks
PDF
Scrum vs Kanban: Is there really a battle?
PDF
Leading Tech Teams
PDF
Scaling Agility: The Technical Angle
PDF
Mindset: the biggest barrier to agility
ODP
An introduction to Kanban
PDF
Catalyzing change
PDF
Stop throwing money out the window
PDF
What Do Agile Leaders Do
PDF
The Scrum Master's Toolbox
Five Things I've Learned in Ten Years of Agile
Product ownership versus product management
Is management dead?
Big rewrites without big risks
Scrum vs Kanban: Is there really a battle?
Leading Tech Teams
Scaling Agility: The Technical Angle
Mindset: the biggest barrier to agility
An introduction to Kanban
Catalyzing change
Stop throwing money out the window
What Do Agile Leaders Do
The Scrum Master's Toolbox

Recently uploaded (20)

PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Hybrid model detection and classification of lung cancer
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
1. Introduction to Computer Programming.pptx
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
Architecture types and enterprise applications.pdf
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPT
What is a Computer? Input Devices /output devices
PDF
August Patch Tuesday
observCloud-Native Containerability and monitoring.pptx
Hybrid model detection and classification of lung cancer
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
Web App vs Mobile App What Should You Build First.pdf
NewMind AI Weekly Chronicles – August ’25 Week III
DP Operators-handbook-extract for the Mautical Institute
1. Introduction to Computer Programming.pptx
Developing a website for English-speaking practice to English as a foreign la...
Zenith AI: Advanced Artificial Intelligence
Final SEM Unit 1 for mit wpu at pune .pptx
Chapter 5: Probability Theory and Statistics
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
OMC Textile Division Presentation 2021.pptx
O2C Customer Invoices to Receipt V15A.pptx
Architecture types and enterprise applications.pdf
A contest of sentiment analysis: k-nearest neighbor versus neural network
What is a Computer? Input Devices /output devices
August Patch Tuesday

Clean Architecture