SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
Cleaning up your Codebase
With a Clean Architecture
Expressing complexity through separation of concerns
Who am I?
Lead Developer and Solutions Architect for
DynamicReservations
Writing web apps professionally for 12 yrs
DDD and EventSourcing fanatic (I will talk for hours)
Recovered Architecture Astronaut
Organiser of PHPDublin @barryosull
barry@tercet.io
http://dev.to/barryosull
http://barryosullivan.me
Todays Talk
Why is Writing Good Code so Hard?
What is a Clean Architecture?
How do you apply a Clean Architecture?
Why Writing Good Code is so Hard
The Status Quo
1 YEAR
LATER
OR
OR
The Core of the Problem
"Our codebase is really messy and hard to
use. How do we clean it up?"
"Simple. We just need to refactor it, move code
into objects, separate the concerns."
"Ok, great!
How do we do that?"
"Easy. We'll use design patterns and follow the
SOLID principles. Job done."
Why doesn’t this work?
Only talks about these
Never talks about these
“How do you make things?”
Learning the patterns isn't enough
?
?
?
?
?
?
?
?
?
?
?
?
Wrong design pattern makes it worse
Wrong
Patterns
WHY?!!
What is “Design”?
Design
Is an
Action
Problem
Research
Solution
Implementation
Evaluation
Definition
What is a Clean Architecture
Clean Architecture
Business Objects
(User/Email/ProfileImage)
Usecases
(CreateUser/SetProfileImage)
Controllers
(UserController/ImageController)
Technology Details
(MySQL/Redis/Filesystem/Framework)
NB: Layers can only reference concepts from their layer
and inners layers. They can never point at outer layers.
Why is it layered this way?
Business Requirements Change
“A user can upload a profile picture”
New User functionality
New Usecase
New Controller
Update datamapper and add
DB migration
Application Requirements Changes
No change to Users
Add a new Usecase
Add a new Controller
Add a new Twilio Service
“A user can change their email address via text ”
Implementation Requirements Change
“User Signup is slow, because checking email uniqueness takes ages, it should be faster”
No business logic changes
Usecases stay the same
Controllers stay the same
Redis used as a faster
datastore in implementation
Applying a Clean Architecture
Too many concepts/different languages
Separating the Concerns
Isolate details
● Config
● Flysystem
● AWS S3
● Eloquent ORM
Replace with abstractions
● Make implicit concepts explicit
Why is this better?
● Easier to read
● Easier to test
● Patterns used effectively
● Loose coupling
○ Easier to change implementation
Why is this worse?
● Larger Codebase
● Design isn’t free, it takes time
class Room{
const ELEPHANT = true;
}
Practice makes Perfect Better
When to do it
Conclusion
Q: Why is Writing Good Code so Hard?
Because we don’t define the problem our architecture is solving
Q: What is a Clean Architecture?
A model for decoupling code through common categories to make
complexity and changes easier to manage
Q: How do you apply a Clean Architecture?
By removing outer layer language from inner layers, making each layer
simpler, consistent and concise
Thank you
Question Time! More Material
● Implementing Domain Driven Design by
Vaughn Vernon
● Uncle Bob’s “Clean Architecture” Article
(1st google result)
● @barryosull
(I tweet/write/talk about this stuff a lot)
● http://dev.to/barryosull
● http://barryosullivan.me
● Or just talk to me afterwards!

Contenu connexe

Tendances

Rapid application development in java
Rapid application development in javaRapid application development in java
Rapid application development in java
Pankaj Tiwari
 
Clean code, Feb 2012
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012
cobyst
 

Tendances (20)

Richardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichardrodger nodeday-2014-final
Richardrodger nodeday-2014-final
 
Creating Hyper Performant Web Apps with React
Creating Hyper Performant Web Apps with ReactCreating Hyper Performant Web Apps with React
Creating Hyper Performant Web Apps with React
 
Making a Mock by Kelsey Shannahan
Making a Mock by Kelsey ShannahanMaking a Mock by Kelsey Shannahan
Making a Mock by Kelsey Shannahan
 
Humans by the hundred (DevOps Days Ohio)
Humans by the hundred (DevOps Days Ohio)Humans by the hundred (DevOps Days Ohio)
Humans by the hundred (DevOps Days Ohio)
 
Основы функционального JS
Основы функционального JSОсновы функционального JS
Основы функционального JS
 
Clean Code
Clean CodeClean Code
Clean Code
 
How microservices fail, and what to do about it
How microservices fail, and what to do about itHow microservices fail, and what to do about it
How microservices fail, and what to do about it
 
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
 
Building Autonomous Services
Building Autonomous ServicesBuilding Autonomous Services
Building Autonomous Services
 
What is good software design? And why it matters?
What is good software design? And why it matters?What is good software design? And why it matters?
What is good software design? And why it matters?
 
Convert olm to pst
Convert olm to pstConvert olm to pst
Convert olm to pst
 
Hacker News Meetup April 2014
Hacker News Meetup April 2014Hacker News Meetup April 2014
Hacker News Meetup April 2014
 
Rapid application development in java
Rapid application development in javaRapid application development in java
Rapid application development in java
 
Clean code, Feb 2012
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012
 
Why You're A Bad PHP Programmer
Why You're A Bad PHP ProgrammerWhy You're A Bad PHP Programmer
Why You're A Bad PHP Programmer
 
Yelp Tech Talks: Mobile Testing 1, 2, 3
Yelp Tech Talks: Mobile Testing 1, 2, 3Yelp Tech Talks: Mobile Testing 1, 2, 3
Yelp Tech Talks: Mobile Testing 1, 2, 3
 
Email Production at scale
Email Production at scaleEmail Production at scale
Email Production at scale
 
No estimates
No estimatesNo estimates
No estimates
 
Sql server baselines
Sql server baselinesSql server baselines
Sql server baselines
 
Single Responsibility Principle
Single Responsibility PrincipleSingle Responsibility Principle
Single Responsibility Principle
 

Similaire à Cleaning up your codebase with a clean architecture

Contemporary Software Engineering Practices Together With Enterprise
Contemporary Software Engineering Practices Together With EnterpriseContemporary Software Engineering Practices Together With Enterprise
Contemporary Software Engineering Practices Together With Enterprise
Kenan Sevindik
 

Similaire à Cleaning up your codebase with a clean architecture (20)

Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
 
The Architect's Two Hats
The Architect's Two HatsThe Architect's Two Hats
The Architect's Two Hats
 
Architecting for Change: An Agile Approach
Architecting for Change: An Agile ApproachArchitecting for Change: An Agile Approach
Architecting for Change: An Agile Approach
 
Contemporary Software Engineering Practices Together With Enterprise
Contemporary Software Engineering Practices Together With EnterpriseContemporary Software Engineering Practices Together With Enterprise
Contemporary Software Engineering Practices Together With Enterprise
 
Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"
 
Selecting the Best Javascript Web Framework
Selecting the Best Javascript Web FrameworkSelecting the Best Javascript Web Framework
Selecting the Best Javascript Web Framework
 
Pragmatic Architecture in .NET
Pragmatic Architecture in .NETPragmatic Architecture in .NET
Pragmatic Architecture in .NET
 
Importance Of Being Driven
Importance Of Being DrivenImportance Of Being Driven
Importance Of Being Driven
 
Dtacs
DtacsDtacs
Dtacs
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
CQRS recepies
CQRS recepiesCQRS recepies
CQRS recepies
 
Opticon 2017 How Developers Can Take Experimentation
Opticon 2017 How Developers Can Take ExperimentationOpticon 2017 How Developers Can Take Experimentation
Opticon 2017 How Developers Can Take Experimentation
 
A sweet taste of clean code and software design
A sweet taste of clean code and software designA sweet taste of clean code and software design
A sweet taste of clean code and software design
 
It is a sunny day
It is a sunny dayIt is a sunny day
It is a sunny day
 
Friday final test
Friday final testFriday final test
Friday final test
 
Grokking TechTalk #30: From App to Ecosystem: Lessons Learned at Scale
Grokking TechTalk #30: From App to Ecosystem: Lessons Learned at ScaleGrokking TechTalk #30: From App to Ecosystem: Lessons Learned at Scale
Grokking TechTalk #30: From App to Ecosystem: Lessons Learned at Scale
 
N-tier and oop - moving across technologies
N-tier and oop - moving across technologiesN-tier and oop - moving across technologies
N-tier and oop - moving across technologies
 
Don't Let Legacy CDNs Hold You Back
Don't Let Legacy CDNs Hold You BackDon't Let Legacy CDNs Hold You Back
Don't Let Legacy CDNs Hold You Back
 

Dernier

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Dernier (20)

Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Cleaning up your codebase with a clean architecture

  • 1. Cleaning up your Codebase With a Clean Architecture Expressing complexity through separation of concerns
  • 2. Who am I? Lead Developer and Solutions Architect for DynamicReservations Writing web apps professionally for 12 yrs DDD and EventSourcing fanatic (I will talk for hours) Recovered Architecture Astronaut Organiser of PHPDublin @barryosull barry@tercet.io http://dev.to/barryosull http://barryosullivan.me
  • 3. Todays Talk Why is Writing Good Code so Hard? What is a Clean Architecture? How do you apply a Clean Architecture?
  • 4. Why Writing Good Code is so Hard
  • 5. The Status Quo 1 YEAR LATER OR OR
  • 6. The Core of the Problem "Our codebase is really messy and hard to use. How do we clean it up?" "Simple. We just need to refactor it, move code into objects, separate the concerns." "Ok, great! How do we do that?" "Easy. We'll use design patterns and follow the SOLID principles. Job done."
  • 7. Why doesn’t this work? Only talks about these Never talks about these “How do you make things?”
  • 8. Learning the patterns isn't enough ? ? ? ? ? ? ? ? ? ? ? ?
  • 9. Wrong design pattern makes it worse Wrong Patterns WHY?!!
  • 10. What is “Design”? Design Is an Action Problem Research Solution Implementation Evaluation Definition
  • 11. What is a Clean Architecture
  • 12. Clean Architecture Business Objects (User/Email/ProfileImage) Usecases (CreateUser/SetProfileImage) Controllers (UserController/ImageController) Technology Details (MySQL/Redis/Filesystem/Framework) NB: Layers can only reference concepts from their layer and inners layers. They can never point at outer layers.
  • 13. Why is it layered this way?
  • 14. Business Requirements Change “A user can upload a profile picture” New User functionality New Usecase New Controller Update datamapper and add DB migration
  • 15. Application Requirements Changes No change to Users Add a new Usecase Add a new Controller Add a new Twilio Service “A user can change their email address via text ”
  • 16. Implementation Requirements Change “User Signup is slow, because checking email uniqueness takes ages, it should be faster” No business logic changes Usecases stay the same Controllers stay the same Redis used as a faster datastore in implementation
  • 17. Applying a Clean Architecture
  • 18.
  • 19.
  • 21. Separating the Concerns Isolate details ● Config ● Flysystem ● AWS S3 ● Eloquent ORM Replace with abstractions ● Make implicit concepts explicit
  • 22.
  • 23.
  • 24.
  • 25.
  • 26. Why is this better? ● Easier to read ● Easier to test ● Patterns used effectively ● Loose coupling ○ Easier to change implementation
  • 27. Why is this worse? ● Larger Codebase ● Design isn’t free, it takes time class Room{ const ELEPHANT = true; }
  • 30. Conclusion Q: Why is Writing Good Code so Hard? Because we don’t define the problem our architecture is solving Q: What is a Clean Architecture? A model for decoupling code through common categories to make complexity and changes easier to manage Q: How do you apply a Clean Architecture? By removing outer layer language from inner layers, making each layer simpler, consistent and concise
  • 31. Thank you Question Time! More Material ● Implementing Domain Driven Design by Vaughn Vernon ● Uncle Bob’s “Clean Architecture” Article (1st google result) ● @barryosull (I tweet/write/talk about this stuff a lot) ● http://dev.to/barryosull ● http://barryosullivan.me ● Or just talk to me afterwards!