SlideShare a Scribd company logo
C l e a n A r c h i t e c t u r e
T r a v i s F r i s i n g e r
@ t m f r i s i n g e r
ABOUT
ME
- I have written software for over 25
years
- 17 of those professionally.
- Owner of StoneAge Technologies LLC
- Fractional CTO
- Trainer
- Speaker
- Using Clean Architecture for over 3
years.
- Started using it when there was
mainly only Uncle Bob’s blog post
about it.
- Used it on over 6 projects learning
lessons with each implementation.
- I maintain a few nuget packages that
simplify the boiler plate code of Clean
Architecture for .Net and .NetCore
Overview
C l e a n A r c h i t e c t u r e
MVC Migration TipsElements of Good Architecture The Architecture
How I evaluate an
architecture
Examination of the whole
and its parts
How to refactor your
existing architecture
Brief History
What came before
• Handle constant change while ensuring
maintainability of code base
• Easily facilitate teams working together
• Avoid ‘god’ classes
• Quality
Why do we need architecture?
C l e a n A r c h i t e c t u r e
• Testable
• Enables Technical Agility
• Independent of Frameworks
• Independent of UI
• Independent of Database
• Changes are easy to accommodate
• Easy to deploy
• Easy to implement
Elements of Good Architecture
C l e a n A r c h i t e c t u r e
- Layered
- MVC
- Microservices
Other Patterns
Brief History
C l e a n A r c h i t e c t u r e
Design Principles
- SOLID
- DRY
SOLID
C l e a n A r c h i t e c t u r e
• Single Responsibility
• A class should have only one reason to
change
• Open Closed
• Software entities (classes, modules, functions,
etc.) should be open for extension but closed
modification
• Liskov Substitution Principle
• Subtypes must be substitutable for their base
types
• Interface Segregation
• Clients should not be forced to depend on
methods they do not use
• Dependency Inversion
• A. High-level modules should not depend on
low-level modules. Both should depend on
abstractions.
• B. Abstractions should not depend on details.
Details should depend on abstractions.
DRY
C l e a n A r c h i t e c t u r e
• Don’t Repeat Yourself
• Every piece of knowledge must
have a single unambiguous,
authoritative representation in
the system.
• Often this principle is miss-
understood with developers
building abstractions for things
that look similar, but represent
different concepts. It is only
repeated if the code represents
the same concept. That is the
same sentence can be used to
describe what it represents.
Layered
C l e a n A r c h i t e c t u r e
UI
Business Logic
Persistence
• Components within the layered
architecture pattern are organized into
horizontal layers
• Each layer performing a specific role
within the application
• Request moves from layer to layer, it must
go through the layer right below it to get to
the next layer below that one.
Database
MVC
C l e a n A r c h i t e c t u r e
• Separates internal representation of
information from how the information is
presented and accepted from the user.
• Model – Manages data, logic and
business rules
• View – What the user sees
• Controller – Takes input and converts it to
operation for the model or view
Dependency
Graph Over Time
MVC + Repository
C l e a n A r c h i t e c t u r e
• MVC with the addition of decoupled data
storage
• Allows developer to apply S and D of
SOLID
• Increases testability of architecture
Microservices
C l e a n A r c h i t e c t u r e
• Quickly gaining ground in the industry as
a viable alternative to monolithic
applications and service-oriented
architectures.
• Each component of the microservices
architecture is deployed as a separate
unit or service component.
• Service components, which can vary in
granularity from a single module to a large
portion of the application
• All the components within the architecture
are fully decoupled from one other and
accessed through some sort of remote
access protocol
https://www.oreilly.com/library/view/software-architecture-patterns/9781491971437/ch04.html
Why Clean Architecture
C l e a n A r c h i t e c t u r e
“We should think about our application as a group of use cases that describe
the intent of the application and a group of plugins that give those use cases
access to the outside world.”
Uncle Bob
The Architecture
C l e a n A r c h i t e c t u r e
The Architecture
C l e a n A r c h i t e c t u r e
Presenters Repositories
Data Flow
C l e a n A r c h i t e c t u r e
Entry Point
Presenter
Use Cases
Entities
Repositories
Data Source
Dependency Rule
C l e a n A r c h i t e c t u r e
Entry Point
Presenter
Use Cases
Entities
Repositories
Data Source
Entry Point
Presenter
Composition Layer Domain Layer Data Layer
Use CasesEntities
Interfaces
Repositories
Network
Data Source
File System
Data Source
Use Case
Inputs
Dependency Inversion
C l e a n A r c h i t e c t u r e
Use Case Repository
Interface
Depends on Repository Interface Implements Interface
Injected into Use Case via IoC container
Data Models
C l e a n A r c h i t e c t u r e
Entities
Input Model
Mapper
Composition Layer Domain Layer Data Layer
Entities Repositories
Data Model
Mapper
Power of Presenters
C l e a n A r c h i t e c t u r e
Use Cases
Entities
Repositories
Data Source
Output
Presenter
Composition Layer Domain Layer
Use Case
Interface
Use Case depends on presenter
interface across boundary
Creates concrete presenter to
pass into use case depending on
needs to entry point
Use Case isVoid return.
Relies on the presenter to return data
Testing
C l e a n A r c h i t e c t u r e
Entry Point
Composition Layer
Use Case
Mock
Repository
Mock
Presenter
External
Mocks
Entities
(Http, File System)
Test Server
Testing
C l e a n A r c h i t e c t u r e
Use Case
Test
Presenter
Domain Layer
Services
Repository
Entity
Test Data
Services
I find often I pull services back
onto the entity where the data
sits.This means I need to test
them.
There may still be other 3rd
party services the entity needs
to do it’s job hence why they are
created as part of the testing
process.
Testing DB
Context
Make use ofTest
Data Builders to
populate this and
allow for re-use
across test.
Config
If making use of more then
one repository. Mock our the
non-critical repositories to
pass through in the test.
Testing
C l e a n A r c h i t e c t u r e
Repositories
Data
Layer
Repository
Services
Testing DB
Context
Config
- Well Structured
- Modular
- Very Testable
- Independent of Frameworks and Tools
- Maintainable
Benefits
- Boiler plate code
- Not suitable for all projects
- Multiple ways to implement
Issues
Issues and Benefits
Y o u r G r e a t S u b t i t l e H e r e
Tips for moving from standard MVC
to Clean Architecture
MVC
MIGRATION
- Use test to drive the process
- Create repositories for data operations
- Inject the repositories into your
controller
- Model Domain Entities
- Do not have controllers take Domain
Entities instead they should take an
Input TO and transform to Domain
entity
- Have repositories accept and return
Domain entity
- Migrate service logic onto the related
Domain Entity
- Create Use Cases to
- Use Repositories
- House remaining logic in Controller
- Coordinate Entities
- If need be create Composite Use
Cases to allow for re-use of common
business logic.
T h a n k Yo u
@ t m f r i s i n g e r
S o u r c e a n d P a c k a g e s
https://github.com/T-rav/Reference-CleanArchitecture-DotNet
(https://bit.ly/2FwXxsK)
https://www.nuget.org/profiles/T-rav
(https://bit.ly/2HDc5JJ)
References
C l e a n A r c h i t e c t u r e
• https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html
• https://github.com/mattia-battiston/clean-architecture-example
• https://proandroiddev.com/intro-to-app-architecture-922b392b21b2
• https://www.sitepoint.com/model-view-controller-mvc-architecture-rails/
• https://www.oreilly.com/library/view/software-architecture-patterns/9781491971437/ch01.html
https://www.oreilly.com/library/view/software-architecture-patterns/9781491971437/ch04.html
• https://www.codingblocks.net/podcast/clean-architecture-make-your-architecture-scream/
• https://medium.freecodecamp.org/a-quick-introduction-to-clean-architecture-990c014448d2
• https://proandroiddev.com/clean-architecture-data-flow-dependency-rule-615ffdd79e29

More Related Content

What's hot

SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
Mohamed Galal
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean Architecture
Mattia Battiston
 
Clean architecture
Clean architectureClean architecture
Clean architecture
Lieven Doclo
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the Domain
Victor Rentea
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
Sam Nasr, MCSA, MVP
 
Clean architecture on android
Clean architecture on androidClean architecture on android
Clean architecture on android
Benjamin Cheng
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Steve Pember
 
The Secrets of Hexagonal Architecture
The Secrets of Hexagonal ArchitectureThe Secrets of Hexagonal Architecture
The Secrets of Hexagonal Architecture
Nicolas Carlo
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introduction
wojtek_s
 
Clean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflixClean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflix
Victor Rentea
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Ryan Riley
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software design
Matthias Noback
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
Tom Kocjan
 
Clean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software CraftsmanshipClean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software Craftsmanship
Ivan Paulovich
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
Victor Rentea
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Hannah Farrugia
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
Indeema Software Inc.
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
Victor Rentea
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applications
Yura Nosenko
 
Hexagonal architecture for java applications
Hexagonal architecture for java applicationsHexagonal architecture for java applications
Hexagonal architecture for java applications
Fabricio Epaminondas
 

What's hot (20)

SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean Architecture
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the Domain
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
Clean architecture on android
Clean architecture on androidClean architecture on android
Clean architecture on android
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
 
The Secrets of Hexagonal Architecture
The Secrets of Hexagonal ArchitectureThe Secrets of Hexagonal Architecture
The Secrets of Hexagonal Architecture
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introduction
 
Clean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflixClean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflix
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software design
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
 
Clean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software CraftsmanshipClean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software Craftsmanship
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applications
 
Hexagonal architecture for java applications
Hexagonal architecture for java applicationsHexagonal architecture for java applications
Hexagonal architecture for java applications
 

Similar to Clean architecture

Microservices.pdf
Microservices.pdfMicroservices.pdf
Microservices.pdf
SelmaJelovac1
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
Srinivasan Nanduri
 
Devtest Orchestration for SDN & NFV
Devtest Orchestration for SDN & NFVDevtest Orchestration for SDN & NFV
Devtest Orchestration for SDN & NFV
Alex Henthorn-Iwane
 
[DSC Europe 23] Petar Zecevic - ML in Production on Databricks
[DSC Europe 23] Petar Zecevic - ML in Production on Databricks[DSC Europe 23] Petar Zecevic - ML in Production on Databricks
[DSC Europe 23] Petar Zecevic - ML in Production on Databricks
DataScienceConferenc1
 
Entity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and BeyondEntity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and Beyond
Steve Westgarth
 
I gotta dependency on dependency injection
I gotta dependency on dependency injectionI gotta dependency on dependency injection
I gotta dependency on dependency injection
mhenroid
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPages
Ulrich Krause
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVC
Ulrich Krause
 
Architectural Design & Patterns
Architectural Design&PatternsArchitectural Design&Patterns
Architectural Design & Patterns
Inocentshuja Ahmad
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
Qamar Abbas
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
Steven Smith
 
Diksha sda presentation
Diksha sda presentationDiksha sda presentation
Diksha sda presentation
dikshagupta111
 
Refactoring Applications using SOLID Principles
Refactoring Applications using SOLID PrinciplesRefactoring Applications using SOLID Principles
Refactoring Applications using SOLID Principles
Steven Smith
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
Steven Smith
 
Integration strategies best practices- Mulesoft meetup April 2018
Integration strategies   best practices- Mulesoft meetup April 2018Integration strategies   best practices- Mulesoft meetup April 2018
Integration strategies best practices- Mulesoft meetup April 2018
Rohan Rasane
 
IncQuery_presentation_Incose_EMEA_WSEC.pptx
IncQuery_presentation_Incose_EMEA_WSEC.pptxIncQuery_presentation_Incose_EMEA_WSEC.pptx
IncQuery_presentation_Incose_EMEA_WSEC.pptx
IncQuery Labs
 
Refactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationRefactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test Automation
Stephen Fuqua
 
Next-Generation Completeness and Consistency Management in the Digital Threa...
Next-Generation Completeness and Consistency Management in the Digital Threa...Next-Generation Completeness and Consistency Management in the Digital Threa...
Next-Generation Completeness and Consistency Management in the Digital Threa...
Ákos Horváth
 

Similar to Clean architecture (20)

Microservices.pdf
Microservices.pdfMicroservices.pdf
Microservices.pdf
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
 
Devtest Orchestration for SDN & NFV
Devtest Orchestration for SDN & NFVDevtest Orchestration for SDN & NFV
Devtest Orchestration for SDN & NFV
 
[DSC Europe 23] Petar Zecevic - ML in Production on Databricks
[DSC Europe 23] Petar Zecevic - ML in Production on Databricks[DSC Europe 23] Petar Zecevic - ML in Production on Databricks
[DSC Europe 23] Petar Zecevic - ML in Production on Databricks
 
Entity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and BeyondEntity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and Beyond
 
I gotta dependency on dependency injection
I gotta dependency on dependency injectionI gotta dependency on dependency injection
I gotta dependency on dependency injection
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPages
 
Mvc
MvcMvc
Mvc
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVC
 
Architectural Design & Patterns
Architectural Design&PatternsArchitectural Design&Patterns
Architectural Design & Patterns
 
Mvc
MvcMvc
Mvc
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
 
Diksha sda presentation
Diksha sda presentationDiksha sda presentation
Diksha sda presentation
 
Refactoring Applications using SOLID Principles
Refactoring Applications using SOLID PrinciplesRefactoring Applications using SOLID Principles
Refactoring Applications using SOLID Principles
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Integration strategies best practices- Mulesoft meetup April 2018
Integration strategies   best practices- Mulesoft meetup April 2018Integration strategies   best practices- Mulesoft meetup April 2018
Integration strategies best practices- Mulesoft meetup April 2018
 
IncQuery_presentation_Incose_EMEA_WSEC.pptx
IncQuery_presentation_Incose_EMEA_WSEC.pptxIncQuery_presentation_Incose_EMEA_WSEC.pptx
IncQuery_presentation_Incose_EMEA_WSEC.pptx
 
Refactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationRefactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test Automation
 
Next-Generation Completeness and Consistency Management in the Digital Threa...
Next-Generation Completeness and Consistency Management in the Digital Threa...Next-Generation Completeness and Consistency Management in the Digital Threa...
Next-Generation Completeness and Consistency Management in the Digital Threa...
 

Recently uploaded

Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 

Recently uploaded (20)

Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 

Clean architecture

  • 1. C l e a n A r c h i t e c t u r e T r a v i s F r i s i n g e r @ t m f r i s i n g e r
  • 2. ABOUT ME - I have written software for over 25 years - 17 of those professionally. - Owner of StoneAge Technologies LLC - Fractional CTO - Trainer - Speaker - Using Clean Architecture for over 3 years. - Started using it when there was mainly only Uncle Bob’s blog post about it. - Used it on over 6 projects learning lessons with each implementation. - I maintain a few nuget packages that simplify the boiler plate code of Clean Architecture for .Net and .NetCore
  • 3. Overview C l e a n A r c h i t e c t u r e MVC Migration TipsElements of Good Architecture The Architecture How I evaluate an architecture Examination of the whole and its parts How to refactor your existing architecture Brief History What came before
  • 4. • Handle constant change while ensuring maintainability of code base • Easily facilitate teams working together • Avoid ‘god’ classes • Quality Why do we need architecture? C l e a n A r c h i t e c t u r e
  • 5. • Testable • Enables Technical Agility • Independent of Frameworks • Independent of UI • Independent of Database • Changes are easy to accommodate • Easy to deploy • Easy to implement Elements of Good Architecture C l e a n A r c h i t e c t u r e
  • 6. - Layered - MVC - Microservices Other Patterns Brief History C l e a n A r c h i t e c t u r e Design Principles - SOLID - DRY
  • 7. SOLID C l e a n A r c h i t e c t u r e • Single Responsibility • A class should have only one reason to change • Open Closed • Software entities (classes, modules, functions, etc.) should be open for extension but closed modification • Liskov Substitution Principle • Subtypes must be substitutable for their base types • Interface Segregation • Clients should not be forced to depend on methods they do not use • Dependency Inversion • A. High-level modules should not depend on low-level modules. Both should depend on abstractions. • B. Abstractions should not depend on details. Details should depend on abstractions.
  • 8. DRY C l e a n A r c h i t e c t u r e • Don’t Repeat Yourself • Every piece of knowledge must have a single unambiguous, authoritative representation in the system. • Often this principle is miss- understood with developers building abstractions for things that look similar, but represent different concepts. It is only repeated if the code represents the same concept. That is the same sentence can be used to describe what it represents.
  • 9. Layered C l e a n A r c h i t e c t u r e UI Business Logic Persistence • Components within the layered architecture pattern are organized into horizontal layers • Each layer performing a specific role within the application • Request moves from layer to layer, it must go through the layer right below it to get to the next layer below that one. Database
  • 10. MVC C l e a n A r c h i t e c t u r e • Separates internal representation of information from how the information is presented and accepted from the user. • Model – Manages data, logic and business rules • View – What the user sees • Controller – Takes input and converts it to operation for the model or view Dependency Graph Over Time
  • 11. MVC + Repository C l e a n A r c h i t e c t u r e • MVC with the addition of decoupled data storage • Allows developer to apply S and D of SOLID • Increases testability of architecture
  • 12. Microservices C l e a n A r c h i t e c t u r e • Quickly gaining ground in the industry as a viable alternative to monolithic applications and service-oriented architectures. • Each component of the microservices architecture is deployed as a separate unit or service component. • Service components, which can vary in granularity from a single module to a large portion of the application • All the components within the architecture are fully decoupled from one other and accessed through some sort of remote access protocol https://www.oreilly.com/library/view/software-architecture-patterns/9781491971437/ch04.html
  • 13. Why Clean Architecture C l e a n A r c h i t e c t u r e “We should think about our application as a group of use cases that describe the intent of the application and a group of plugins that give those use cases access to the outside world.” Uncle Bob
  • 14. The Architecture C l e a n A r c h i t e c t u r e
  • 15. The Architecture C l e a n A r c h i t e c t u r e Presenters Repositories
  • 16. Data Flow C l e a n A r c h i t e c t u r e Entry Point Presenter Use Cases Entities Repositories Data Source
  • 17. Dependency Rule C l e a n A r c h i t e c t u r e Entry Point Presenter Use Cases Entities Repositories Data Source Entry Point Presenter Composition Layer Domain Layer Data Layer Use CasesEntities Interfaces Repositories Network Data Source File System Data Source Use Case Inputs
  • 18. Dependency Inversion C l e a n A r c h i t e c t u r e Use Case Repository Interface Depends on Repository Interface Implements Interface Injected into Use Case via IoC container
  • 19. Data Models C l e a n A r c h i t e c t u r e Entities Input Model Mapper Composition Layer Domain Layer Data Layer Entities Repositories Data Model Mapper
  • 20. Power of Presenters C l e a n A r c h i t e c t u r e Use Cases Entities Repositories Data Source Output Presenter Composition Layer Domain Layer Use Case Interface Use Case depends on presenter interface across boundary Creates concrete presenter to pass into use case depending on needs to entry point Use Case isVoid return. Relies on the presenter to return data
  • 21. Testing C l e a n A r c h i t e c t u r e Entry Point Composition Layer Use Case Mock Repository Mock Presenter External Mocks Entities (Http, File System) Test Server
  • 22. Testing C l e a n A r c h i t e c t u r e Use Case Test Presenter Domain Layer Services Repository Entity Test Data Services I find often I pull services back onto the entity where the data sits.This means I need to test them. There may still be other 3rd party services the entity needs to do it’s job hence why they are created as part of the testing process. Testing DB Context Make use ofTest Data Builders to populate this and allow for re-use across test. Config If making use of more then one repository. Mock our the non-critical repositories to pass through in the test.
  • 23. Testing C l e a n A r c h i t e c t u r e Repositories Data Layer Repository Services Testing DB Context Config
  • 24. - Well Structured - Modular - Very Testable - Independent of Frameworks and Tools - Maintainable Benefits - Boiler plate code - Not suitable for all projects - Multiple ways to implement Issues Issues and Benefits Y o u r G r e a t S u b t i t l e H e r e
  • 25. Tips for moving from standard MVC to Clean Architecture MVC MIGRATION - Use test to drive the process - Create repositories for data operations - Inject the repositories into your controller - Model Domain Entities - Do not have controllers take Domain Entities instead they should take an Input TO and transform to Domain entity - Have repositories accept and return Domain entity - Migrate service logic onto the related Domain Entity - Create Use Cases to - Use Repositories - House remaining logic in Controller - Coordinate Entities - If need be create Composite Use Cases to allow for re-use of common business logic.
  • 26. T h a n k Yo u @ t m f r i s i n g e r
  • 27. S o u r c e a n d P a c k a g e s https://github.com/T-rav/Reference-CleanArchitecture-DotNet (https://bit.ly/2FwXxsK) https://www.nuget.org/profiles/T-rav (https://bit.ly/2HDc5JJ)
  • 28. References C l e a n A r c h i t e c t u r e • https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html • https://github.com/mattia-battiston/clean-architecture-example • https://proandroiddev.com/intro-to-app-architecture-922b392b21b2 • https://www.sitepoint.com/model-view-controller-mvc-architecture-rails/ • https://www.oreilly.com/library/view/software-architecture-patterns/9781491971437/ch01.html https://www.oreilly.com/library/view/software-architecture-patterns/9781491971437/ch04.html • https://www.codingblocks.net/podcast/clean-architecture-make-your-architecture-scream/ • https://medium.freecodecamp.org/a-quick-introduction-to-clean-architecture-990c014448d2 • https://proandroiddev.com/clean-architecture-data-flow-dependency-rule-615ffdd79e29

Editor's Notes

  1. Clean architecture helps us solve, or at least mitigate, these common problems with architecture: Decisions are taken too early, often at the beginning of a project, when we know the least about the problem that we have to solve It's hard to change, so when we discover new requirements we have to decide if we want to hack them in or go through an expensive and painful re-design. We all know which one usually wins. The best architectures are the ones that allow us to defer commitment to a particular solution and let us change our mind It's centered around frameworks. Frameworks are tools to be used, not architectures to be conformed to. Frameworks often require commitments from you, but they don’t commit to you. They can evolve in different directions, and then you’ll be stuck following their rules and quirks It's centered around the database. We often think about the database first, and then create a CRUD system around it. We end up using the database objects everywhere and treat everything in terms of tables, rows and columns We focus on technical aspects and when asked about our architecture we say things like “it’s servlets running in tomcat with an oracle db using spring” It's hard to find things which makes every change longer and more painful Business logic is spread everywhere, scattered across many layers, so when checking how something works our only option is to debug the whole codebase. Even worse, often it's duplicated in multiple places Forces/Encourages slow, heavy tests. Often our only choice for tests is to go through the GUI, either because the GUI has a lot of logic, or because the architecture doesn't allow us to do otherwise. This makes tests slow to run, heavy and brittle. It results in people not running them and the build beind broken often Infrequent deploys because it's hard to make changes without breaking existing functionalities. People resort to long-lived feature branches that only get integrated at the end and result in big releases, rather than small incremental ones Clean architecture gives us all these benefits: Effective testing strategy that follows the testing pyramid and gives us a fast and reliable build Frameworks are isolated in individual modules so that when (not if) we change our mind we only have to change one place, with the rest of the app not even knowing about it Independent from Database, which is treated just like any other data provider. Our app has real use cases rather than being a CRUD system Screaming architecture a.k.a. it screams its intended usage. When you look at the package structure you get a feel for what the application does rather than seeing technical details All business logic is in a use case so it's easy to find and it's not duplicated anywhere else Hard to do the wrong thing because modules enforce compilation dependencies. If you try to use something that you're not meant to, the app doesn't compile We're always ready to deploy by leaving the wiring up of the object for last or by using feature flags, so we get all the benefits of continuous integration (no need for feature branches) Swarming on stories so that different pairs can easily work on the same story at the same time to complete it quicker Good monolith with clear use cases that you can split in microservices later one, once you've learnt more about them Of course, it comes at a cost: Perceived duplication of code. Entities might be represented differently when used in business logic, when dealing with the database and when presenting them in a json format. You might feel like you're duplicating code, but you're actually favouring decoupling over DRY You need interesting business logic to "justify" the structure. If all you do in your use case is a one-line method to read or save from a database, then maybe you can get away with something simpler