SlideShare a Scribd company logo
1 of 56
Clean Architecture
Augustinas Nomicas
.NET Developer
What is good software architecture?
● Good architecture must be time-proof
● Architecture must change because of new business requirements,
not because of new technologies
● Good architecture must clearly communicate code purpose
● Being flexible in wrong places is bad example of software architecture
● Good architecture let's defer major decisions
Problem:
so many bad architecture
projects in the wild
Case study for market leading software
Why?
● Accumulated technical dept
● Bad software design
The goal of software architecture is to minimize the human effort
required to build and maintain the required system
Robert C. Martin
Aka Uncle Bob
Clean architecture
● Architectural style suitable for all platforms, languages and domains
● Abstract, more like “mindset” instead of concrete rules / frameworks
● Easily adoptable
● Easily testable
● Independent from database
● Independent from frameworks
● Always ready to deploy
● High isolation of modules
Clean architecture
Clean architecture is not always
right for small projects
So...
???
The center of your application is not the
database. Nor is it one or more of the
frameworks you may be using. The center
of your application is the use cases of your
application - Uncle Bob
Insurance company example
● The heart of insurance company business is insurance calculation
formula which would determine correct price for insurance policy
and ensure profitable business model
○ Insurance calculation can be performed by human being with peace of paper and
calculator
○ It’s the Critical Business Rule, and can be delivered to customer via
Fax/Mail/Mobile App/Web
What is use-case ?
Wikipedia:
a use case is a list of actions or event steps typically defining the interactions
between a role (known in the Unified Modeling Language as an actor) and a
system to achieve a goal.
Clean Architecture book:
These use cases orchestrate the flow of data to and from the entities, and
direct those entities to use their Critical Business Rules to achieve the goals of
the use case.
Two cases of business rules
● Business specific business rules
○ Fundamental business rules
● Application specific business rules
○ For example communication with user, validation
It’s important to separate those rules in application architecture
Software dependency
● In clean architecture we INVERT software dependencies for
○ Database
○ Framework
○ UI
How to invert dependency
Business
layer
AddCar
Database
layer
CarSqlDB
References
Business
layer
AddCar
Database
layer
CarSqlDB
Implements
ICarStore
References
Entities
● Represent your domain model
● Entities should be reusable in many
applications
● They encapsulate the most general/high-level
rules.
Entities
● Entity layer must contain only POCO (Plain old
CLR object) objects
○ Easy to migrate between different .NET versions
○ Easy serialization and caching
○ Easy testable
Use Cases
● Use cases are application specific business
rules
○ Changes should not impact the Entities
○ Changes should not be impacted by infrastructure such
as a database
● Orchestrate data flow from and to Entities
● Validators, exceptions, commands, queries and
interfaces
● Layer where 3rd party code can be used
○ MVC, API controllers, presenters, all belong here
○ Entity Framework: DbContext, Migrations,
Configurations
● Implements interfaces defined in Use-Cases
level
● No code further in (use cases, entities) should
have any knowledge of the db
Controllers / Gateways / Presenters
● OS functions, api clients, file system, GPIO
● Web Server, SQL Server, Redis cache
● You’re not writing much of this code, i.e. we use
SQL Server, but we don’t write it.
● These are the glue that hook the various layers
up (IoC container XML config)
DB / Devices / WEB / UI
Only 4 circles?
● No, the circles are schematic. You may find that you need more than
just these four.
● BUT: Dependency Rule always applies. Source code dependencies
always point inwards.
● As you move inwards the software grows more abstract, and
encapsulates higher level policies. The innermost circle is the most
general and most stable
● Layers can not skip layers
Crossing boundaries
● Data that can cross boundaries are only simple data structures
● They are called DTOs, ViewModels
● You can not pass database rows or whole entities
● Passed data structure must be most convenient for inner circle
Main component
● Every system has “main” component where everything is wired-up
● It mostly likely has references to all layers
● Usually it is IoC container register
● Application.Startup method
Screaming architecture
The architecture should scream the intent of the system!
VS
Clean Architecture in ASP.NET MVC 5
Author: Matthew Renze
https://www.matthewrenze.com/articles/clean-architecture-in-asp-net-mvc-5/
Screaming architecture
● Architecture based on use-cases and shows them on the first glance
● Same functionality put under same folders and easy to find (high
cohesion)
What about .NET
Framework?
What about MVC?
● MVC is not an architecture
○ MVC was introduced in 1970s into Smalltalk
○ Intention was to use for small UI object (button, text input, circle)
○ MVC is a delivery design pattern
○ Should be in Presentation layer
What about testing?
● Clean architecture is very test-friendly
○ We can test our Entities and Use-cases (business logic) without database and UI
○ Test should be considered as outermost circle in the architecture
● Tests should be considered as first-class citizen of software
architecture
ASP.NET Examples
ASP.NET project template
https://marketplace.visualstudio.com/items?itemName=
GregTrevellick.CleanArchitecture
Northwind Traders in ASP .NET Core
https://github.com/JasonGT/NorthwindTraders
Clean Architecture with ASP.NET Core
https://www.youtube.com/watch?v=_lwCVE_
XgqI
Clean architecture
♡
KISS
Summary
● Business operations (use cases) are the most important thing!
Respect them and don’t pollute them with unnecessary things
● Database is only a Detail
● Frameworks are only the Details
● UI (Presentation) is a Detail
More By Robert C. Martin (Uncle Bob)
Ačiū!

More Related Content

What's hot

Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net coreSam Nasr, MCSA, MVP
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#Pascal Laurin
 
2012 the clean architecture by Uncle bob
2012 the clean architecture by Uncle bob 2012 the clean architecture by Uncle bob
2012 the clean architecture by Uncle bob GEORGE LEON
 
Clean architecture
Clean architectureClean architecture
Clean architectureLieven Doclo
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean ArchitectureDmytro Turskyi
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the DomainVictor Rentea
 
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 2023Steve Pember
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidOutware Mobile
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignRyan Riley
 
Domain driven design and model driven development
Domain driven design and model driven developmentDomain driven design and model driven development
Domain driven design and model driven developmentDmitry Geyzersky
 
DDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan PaulovichDDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan PaulovichIvan Paulovich
 
Clean architecture on android
Clean architecture on androidClean architecture on android
Clean architecture on androidBenjamin Cheng
 
Domain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) DistilledDomain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) DistilledNicola Costantino
 
Clean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software CraftsmanshipClean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software CraftsmanshipIvan Paulovich
 

What's hot (20)

Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
 
2012 the clean architecture by Uncle bob
2012 the clean architecture by Uncle bob 2012 the clean architecture by Uncle bob
2012 the clean architecture by Uncle bob
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean Architecture
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the Domain
 
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
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Domain driven design and model driven development
Domain driven design and model driven developmentDomain driven design and model driven development
Domain driven design and model driven development
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
DDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan PaulovichDDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan Paulovich
 
Domain Driven Design
Domain Driven Design Domain Driven Design
Domain Driven Design
 
Clean architecture on android
Clean architecture on androidClean architecture on android
Clean architecture on android
 
Domain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) DistilledDomain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) Distilled
 
Clean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software CraftsmanshipClean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software Craftsmanship
 

Similar to Clean architecture

Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Fwdays
 
The working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор ТурскийThe working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор ТурскийSigma Software
 
The working architecture of node js applications open tech week javascript ...
The working architecture of node js applications   open tech week javascript ...The working architecture of node js applications   open tech week javascript ...
The working architecture of node js applications open tech week javascript ...Viktor Turskyi
 
From class to architecture
From class to architectureFrom class to architecture
From class to architectureMarcin Hawraniak
 
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...Daniel Zivkovic
 
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020OdessaJS Conf
 
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 XPagesUlrich Krause
 
Technology insights: Decision Science Platform
Technology insights: Decision Science PlatformTechnology insights: Decision Science Platform
Technology insights: Decision Science PlatformDecision Science Community
 
Software Architecture - All you need to know
Software Architecture - All you need to knowSoftware Architecture - All you need to know
Software Architecture - All you need to knowVincent Composieux
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCUlrich Krause
 
Software architecture, Patterns for Scale
Software architecture, Patterns for ScaleSoftware architecture, Patterns for Scale
Software architecture, Patterns for ScaleiGbanam
 
Single Source of Truth for Network Automation
Single Source of Truth for Network AutomationSingle Source of Truth for Network Automation
Single Source of Truth for Network AutomationAndy Davidson
 
From prototype to production - The journey of re-designing SmartUp.io
From prototype to production - The journey of re-designing SmartUp.ioFrom prototype to production - The journey of re-designing SmartUp.io
From prototype to production - The journey of re-designing SmartUp.ioMáté Lang
 
Software architectures
Software architecturesSoftware architectures
Software architecturesAmandeep Singh
 
ASAS 2014 - Simon Brown
ASAS 2014 - Simon BrownASAS 2014 - Simon Brown
ASAS 2014 - Simon BrownAvisi B.V.
 
Object oriented sad-5 part i
Object oriented sad-5 part iObject oriented sad-5 part i
Object oriented sad-5 part iBisrat Girma
 
Secret Twists to Efficiently Develop Reactive Software Systems
Secret Twists to Efficiently Develop Reactive Software SystemsSecret Twists to Efficiently Develop Reactive Software Systems
Secret Twists to Efficiently Develop Reactive Software SystemsBart Jonkers
 
Online Real Estate Management System
Online Real Estate Management SystemOnline Real Estate Management System
Online Real Estate Management Systemshahrukh Nawandish
 
Rapid app building with loopback framework
Rapid app building with loopback frameworkRapid app building with loopback framework
Rapid app building with loopback frameworkThomas Papaspiros
 
Architecturing the software stack at a small business
Architecturing the software stack at a small businessArchitecturing the software stack at a small business
Architecturing the software stack at a small businessYangJerng Hwa
 

Similar to Clean architecture (20)

Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"
 
The working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор ТурскийThe working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор Турский
 
The working architecture of node js applications open tech week javascript ...
The working architecture of node js applications   open tech week javascript ...The working architecture of node js applications   open tech week javascript ...
The working architecture of node js applications open tech week javascript ...
 
From class to architecture
From class to architectureFrom class to architecture
From class to architecture
 
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
 
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
 
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
 
Technology insights: Decision Science Platform
Technology insights: Decision Science PlatformTechnology insights: Decision Science Platform
Technology insights: Decision Science Platform
 
Software Architecture - All you need to know
Software Architecture - All you need to knowSoftware Architecture - All you need to know
Software Architecture - All you need to know
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVC
 
Software architecture, Patterns for Scale
Software architecture, Patterns for ScaleSoftware architecture, Patterns for Scale
Software architecture, Patterns for Scale
 
Single Source of Truth for Network Automation
Single Source of Truth for Network AutomationSingle Source of Truth for Network Automation
Single Source of Truth for Network Automation
 
From prototype to production - The journey of re-designing SmartUp.io
From prototype to production - The journey of re-designing SmartUp.ioFrom prototype to production - The journey of re-designing SmartUp.io
From prototype to production - The journey of re-designing SmartUp.io
 
Software architectures
Software architecturesSoftware architectures
Software architectures
 
ASAS 2014 - Simon Brown
ASAS 2014 - Simon BrownASAS 2014 - Simon Brown
ASAS 2014 - Simon Brown
 
Object oriented sad-5 part i
Object oriented sad-5 part iObject oriented sad-5 part i
Object oriented sad-5 part i
 
Secret Twists to Efficiently Develop Reactive Software Systems
Secret Twists to Efficiently Develop Reactive Software SystemsSecret Twists to Efficiently Develop Reactive Software Systems
Secret Twists to Efficiently Develop Reactive Software Systems
 
Online Real Estate Management System
Online Real Estate Management SystemOnline Real Estate Management System
Online Real Estate Management System
 
Rapid app building with loopback framework
Rapid app building with loopback frameworkRapid app building with loopback framework
Rapid app building with loopback framework
 
Architecturing the software stack at a small business
Architecturing the software stack at a small businessArchitecturing the software stack at a small business
Architecturing the software stack at a small business
 

More from .NET Crowd

Quantum Computing With the Q# Language
Quantum Computing With the Q# LanguageQuantum Computing With the Q# Language
Quantum Computing With the Q# Language.NET Crowd
 
Fast IDentity Online New wave of open authentication standards
Fast IDentity Online New wave of open authentication standardsFast IDentity Online New wave of open authentication standards
Fast IDentity Online New wave of open authentication standards.NET Crowd
 
Multi-threading your way out
Multi-threading your way outMulti-threading your way out
Multi-threading your way out.NET Crowd
 
Visual Studio Team Services Extensions by Taavi Kõosaar (@melborp)
Visual Studio Team Services Extensions by Taavi Kõosaar (@melborp)Visual Studio Team Services Extensions by Taavi Kõosaar (@melborp)
Visual Studio Team Services Extensions by Taavi Kõosaar (@melborp).NET Crowd
 
Typescript language
Typescript languageTypescript language
Typescript language.NET Crowd
 
Dependency Injection: išmoktos pamokos
Dependency Injection: išmoktos pamokosDependency Injection: išmoktos pamokos
Dependency Injection: išmoktos pamokos.NET Crowd
 
Raimondas tijunaitis tackle_big_ball_of_mud_super_mario_style
Raimondas tijunaitis tackle_big_ball_of_mud_super_mario_styleRaimondas tijunaitis tackle_big_ball_of_mud_super_mario_style
Raimondas tijunaitis tackle_big_ball_of_mud_super_mario_style.NET Crowd
 
Tomas Urbonaitis "Introduction to asynchronous persistent messaging with NSer...
Tomas Urbonaitis "Introduction to asynchronous persistent messaging with NSer...Tomas Urbonaitis "Introduction to asynchronous persistent messaging with NSer...
Tomas Urbonaitis "Introduction to asynchronous persistent messaging with NSer....NET Crowd
 
Rokas Balevičius "Logstash - system heartbeat implementation"
Rokas Balevičius "Logstash - system heartbeat implementation"Rokas Balevičius "Logstash - system heartbeat implementation"
Rokas Balevičius "Logstash - system heartbeat implementation".NET Crowd
 
Andrej Slivko "CQRS praktikoje"
Andrej Slivko "CQRS praktikoje"Andrej Slivko "CQRS praktikoje"
Andrej Slivko "CQRS praktikoje".NET Crowd
 
Donatas Mačiūnas "Git - pažabokim istoriją"
Donatas Mačiūnas "Git - pažabokim istoriją"Donatas Mačiūnas "Git - pažabokim istoriją"
Donatas Mačiūnas "Git - pažabokim istoriją".NET Crowd
 

More from .NET Crowd (11)

Quantum Computing With the Q# Language
Quantum Computing With the Q# LanguageQuantum Computing With the Q# Language
Quantum Computing With the Q# Language
 
Fast IDentity Online New wave of open authentication standards
Fast IDentity Online New wave of open authentication standardsFast IDentity Online New wave of open authentication standards
Fast IDentity Online New wave of open authentication standards
 
Multi-threading your way out
Multi-threading your way outMulti-threading your way out
Multi-threading your way out
 
Visual Studio Team Services Extensions by Taavi Kõosaar (@melborp)
Visual Studio Team Services Extensions by Taavi Kõosaar (@melborp)Visual Studio Team Services Extensions by Taavi Kõosaar (@melborp)
Visual Studio Team Services Extensions by Taavi Kõosaar (@melborp)
 
Typescript language
Typescript languageTypescript language
Typescript language
 
Dependency Injection: išmoktos pamokos
Dependency Injection: išmoktos pamokosDependency Injection: išmoktos pamokos
Dependency Injection: išmoktos pamokos
 
Raimondas tijunaitis tackle_big_ball_of_mud_super_mario_style
Raimondas tijunaitis tackle_big_ball_of_mud_super_mario_styleRaimondas tijunaitis tackle_big_ball_of_mud_super_mario_style
Raimondas tijunaitis tackle_big_ball_of_mud_super_mario_style
 
Tomas Urbonaitis "Introduction to asynchronous persistent messaging with NSer...
Tomas Urbonaitis "Introduction to asynchronous persistent messaging with NSer...Tomas Urbonaitis "Introduction to asynchronous persistent messaging with NSer...
Tomas Urbonaitis "Introduction to asynchronous persistent messaging with NSer...
 
Rokas Balevičius "Logstash - system heartbeat implementation"
Rokas Balevičius "Logstash - system heartbeat implementation"Rokas Balevičius "Logstash - system heartbeat implementation"
Rokas Balevičius "Logstash - system heartbeat implementation"
 
Andrej Slivko "CQRS praktikoje"
Andrej Slivko "CQRS praktikoje"Andrej Slivko "CQRS praktikoje"
Andrej Slivko "CQRS praktikoje"
 
Donatas Mačiūnas "Git - pažabokim istoriją"
Donatas Mačiūnas "Git - pažabokim istoriją"Donatas Mačiūnas "Git - pažabokim istoriją"
Donatas Mačiūnas "Git - pažabokim istoriją"
 

Recently uploaded

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 🔝✔️✔️Delhi Call girls
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
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.pdfkalichargn70th171
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 

Recently uploaded (20)

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 🔝✔️✔️
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
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
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
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
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 

Clean architecture

  • 2. What is good software architecture? ● Good architecture must be time-proof ● Architecture must change because of new business requirements, not because of new technologies ● Good architecture must clearly communicate code purpose ● Being flexible in wrong places is bad example of software architecture ● Good architecture let's defer major decisions
  • 3. Problem: so many bad architecture projects in the wild
  • 4. Case study for market leading software
  • 5.
  • 6.
  • 7.
  • 8. Why? ● Accumulated technical dept ● Bad software design
  • 9. The goal of software architecture is to minimize the human effort required to build and maintain the required system
  • 10. Robert C. Martin Aka Uncle Bob
  • 11. Clean architecture ● Architectural style suitable for all platforms, languages and domains ● Abstract, more like “mindset” instead of concrete rules / frameworks ● Easily adoptable
  • 12. ● Easily testable ● Independent from database ● Independent from frameworks ● Always ready to deploy ● High isolation of modules Clean architecture
  • 13. Clean architecture is not always right for small projects
  • 14. So...
  • 15.
  • 16. ???
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. The center of your application is not the database. Nor is it one or more of the frameworks you may be using. The center of your application is the use cases of your application - Uncle Bob
  • 25. Insurance company example ● The heart of insurance company business is insurance calculation formula which would determine correct price for insurance policy and ensure profitable business model ○ Insurance calculation can be performed by human being with peace of paper and calculator ○ It’s the Critical Business Rule, and can be delivered to customer via Fax/Mail/Mobile App/Web
  • 26. What is use-case ? Wikipedia: a use case is a list of actions or event steps typically defining the interactions between a role (known in the Unified Modeling Language as an actor) and a system to achieve a goal. Clean Architecture book: These use cases orchestrate the flow of data to and from the entities, and direct those entities to use their Critical Business Rules to achieve the goals of the use case.
  • 27. Two cases of business rules ● Business specific business rules ○ Fundamental business rules ● Application specific business rules ○ For example communication with user, validation It’s important to separate those rules in application architecture
  • 28. Software dependency ● In clean architecture we INVERT software dependencies for ○ Database ○ Framework ○ UI
  • 29. How to invert dependency Business layer AddCar Database layer CarSqlDB References Business layer AddCar Database layer CarSqlDB Implements ICarStore References
  • 30.
  • 31.
  • 32. Entities ● Represent your domain model ● Entities should be reusable in many applications ● They encapsulate the most general/high-level rules.
  • 33. Entities ● Entity layer must contain only POCO (Plain old CLR object) objects ○ Easy to migrate between different .NET versions ○ Easy serialization and caching ○ Easy testable
  • 34. Use Cases ● Use cases are application specific business rules ○ Changes should not impact the Entities ○ Changes should not be impacted by infrastructure such as a database ● Orchestrate data flow from and to Entities ● Validators, exceptions, commands, queries and interfaces
  • 35. ● Layer where 3rd party code can be used ○ MVC, API controllers, presenters, all belong here ○ Entity Framework: DbContext, Migrations, Configurations ● Implements interfaces defined in Use-Cases level ● No code further in (use cases, entities) should have any knowledge of the db Controllers / Gateways / Presenters
  • 36. ● OS functions, api clients, file system, GPIO ● Web Server, SQL Server, Redis cache ● You’re not writing much of this code, i.e. we use SQL Server, but we don’t write it. ● These are the glue that hook the various layers up (IoC container XML config) DB / Devices / WEB / UI
  • 37. Only 4 circles? ● No, the circles are schematic. You may find that you need more than just these four. ● BUT: Dependency Rule always applies. Source code dependencies always point inwards. ● As you move inwards the software grows more abstract, and encapsulates higher level policies. The innermost circle is the most general and most stable ● Layers can not skip layers
  • 38. Crossing boundaries ● Data that can cross boundaries are only simple data structures ● They are called DTOs, ViewModels ● You can not pass database rows or whole entities ● Passed data structure must be most convenient for inner circle
  • 39. Main component ● Every system has “main” component where everything is wired-up ● It mostly likely has references to all layers ● Usually it is IoC container register ● Application.Startup method
  • 40. Screaming architecture The architecture should scream the intent of the system!
  • 41.
  • 42.
  • 43.
  • 44. VS
  • 45. Clean Architecture in ASP.NET MVC 5 Author: Matthew Renze https://www.matthewrenze.com/articles/clean-architecture-in-asp-net-mvc-5/
  • 46. Screaming architecture ● Architecture based on use-cases and shows them on the first glance ● Same functionality put under same folders and easy to find (high cohesion)
  • 48. What about MVC? ● MVC is not an architecture ○ MVC was introduced in 1970s into Smalltalk ○ Intention was to use for small UI object (button, text input, circle) ○ MVC is a delivery design pattern ○ Should be in Presentation layer
  • 49. What about testing? ● Clean architecture is very test-friendly ○ We can test our Entities and Use-cases (business logic) without database and UI ○ Test should be considered as outermost circle in the architecture ● Tests should be considered as first-class citizen of software architecture
  • 52. Northwind Traders in ASP .NET Core https://github.com/JasonGT/NorthwindTraders Clean Architecture with ASP.NET Core https://www.youtube.com/watch?v=_lwCVE_ XgqI
  • 54. Summary ● Business operations (use cases) are the most important thing! Respect them and don’t pollute them with unnecessary things ● Database is only a Detail ● Frameworks are only the Details ● UI (Presentation) is a Detail
  • 55. More By Robert C. Martin (Uncle Bob)

Editor's Notes

  1. Architektūra turi būti tvari laikui. Ji turi būti pakankamai abstrakti kad leistų daryti pokyčius apie kuriuos dar nežinome ir pakankamai konkreti kad programuotojai nepridarytų sisteminių klaidų. Jos nereikia “perrašinėti” nes niekas nesusigaudo kaip kas veikia. Gera architektūra turi keistis dėl naujų verslo reikalavimų, o ne dėl naujų technologijų “Mums viską reikia perrašyti nes išėjo naujas frameworkas” Gera architektūra turi aiškiai komunikuoti programinės įrangos paskirtį (screaming architecture) Architektūra turi atskleisti ketinimus o ne slėpti juos Lankstumas netinkamose vietose yra blogos architektūros pavyzdys Gera architektūra leidžia atidėlioti ir lengvai keisti jau priimtus sprendimus. Kuriant sistemos architektūra reikia daryti major technologinius sprendimus, kurie impactins ilgam laikui visą biznį, todėl logišą priiminėti tuos sprendimus kai turime daugiausiai informacijos ir žinių
  2. Iliustruojantis pavyzdys
  3. Mind-set’as “pataisyme vėliau”, ko pasekoje reikia mokėti palūkanas už techninę skolą Dėl netinkamos architektūros tenka daryti hack’us ir workaroundus
  4. Architektūros tikslas yra minimizuoti reikalingą žmogaus įsikišimą kurio reikia palaikyti ir plėtoti sistemą Iš to išplaukia: Turi būti lengva bugfix’inti Turi būti lengva pridėti naujus features’u Lengva onboardinti naujus developerius Laikas skirtas bugfixinimui / naujiem featursams neturi augti bėgant metam
  5. 2017 metais išleido knygą kurioje aprašė “Clean architecture stilių” daugiau nei 30 metų dirba IT industrijoje programuotojų prie visokių sistemų Į šią knygą sudėjo kas jo manymu reikalinga padaryti gerą architektūra
  6. Architektūrinis stilius skirtas bet kokiai platformai, kalbai ar domain’ui. Abstraktus, labiau “mind-set” negu griežtos taisyklės ar frameworkas Lengvai pritaikomas. Jeigu sistema kuriama nuo pradžių
  7. Lengvai testuojama Nepriklausoma nuo duomenų bazės Nepriklausoma nuo framework’ų Visada paruošta deploy’inimui Izoliuoti moduliai
  8. Švariai architektūrai reikia griežtų layer’ių, daug kodo skaidymo kartais yra netinkama mažiems MVP produktams
  9. N-Tier / N-Layer
  10. Use-case yra veiksmų visuma kuriuos vartotojas gali atlikti su aplikacija norėdamas pasiekti tam tikro rezultato. Tie veiksmai dažniausiai būna tai dėl ko verslas gyvuoja ir kuriem automatizuoti kuriama aplikacija Mūsų atveju use-case orkestruoja duomenų srautą tarp kritinių biznio operacijų ir vartotojo
  11. Švarios architektūros pagrindinė idėja yra invertuoti priklausomybę. Taigi duomenų bazė tampa tik “pluginas” į mūsų biznio logiką Tas pats ir su framework’u ir UI
  12. Taigi, grįžkime prie originalaus paveiksliuko
  13. Kitoks tos pačios svogūno architektūros pjūvis Kuo arčiau centro tuo daugiau abstrakcijos, tuo mažiau priklausomybių ir kodas mažiau keičiasi
  14. Entičiai dažniausiai yra daiktavardžiai Entičiai turėtų galėti būti perpnaudojami keliose aplikacijose. Gali būt platinami kaip vidiniai nuget paketai. Jie neturi nuo nieko priklausyti Juose aprašomos labiausiai abstrakčios funkcijos ir struktūros, kurios rečiausiai keičiasi
  15. Entity sluoksnyje turi būti tik vadinami POCO objektai. Pvz jame neturėtų būti asynchroninio, linq kodo Lengva migruoti tarp skirtingų .net versijų Lengva serelizuoti ir cachuoti Lengva testuoti
  16. Use case dažniausiai yra biznio operacijos specifinės kuriamai aplikacijai Pakeitimai turėtų neįtakoti enticiu Pakeitimai neturi įtakoti infrastruktūrinių dalykų tokių kaip duomenų bazė ar UI Čia dedami validatoriai, exceptionai, komandos, queriai, interface’ai
  17. Konvertuoja duomenis tarp Domain objektų ir duomenų bazės bei UI Dažniausiai čia atsigula MVC Controlleriai Taip pat čia gula ir EntifyFramework reikalai: DbContext, Migrations, Configurations Taip pat čia konvertuojami duomenys iš išorinių servisų
  18. Išoriniai servisai, failų sistema, hardware input/outputs, integracijos Dauguma kodo čia parašyta ne mūsų, naudojam 3d party servisus Web projektas pvz suklijuoja visus layerius tarpusavyje
  19. Tik 4 layeriai? Ne, jų gali būti kiek reikia Bet: priklausomybės principas išlieka kuo arčiau apskritimo vidurio, tuo kodas turi turėti mažiau priklausomybių ir būti abstraktersnis
  20. Ribų kirtimas Tik paprastos duomenų struktūros gali vaikščioti taip layerių Negalima perdavinėti duomenų bazės objektų arba enticių iš centrinio apskritimo Tam reikės naudoti mapperius Duomenų struktūras derinti prie vidinio rato, nes išorinis ratas yra priklausomas nuo vidinio o ne atvirkščiai Šios duomenų struktūros dažniausiai vadinamos DTO arba ViewModeliais
  21. Folder-by-feature
  22. Atsidarę projektą pirmiausia matome ne framework’ą, o biznio objektus Architektūra paremta Use-Cases, o ne konkrečiu karkasu (framework) Panašus funkcionalumas sutelktas į vieną vietą (high cohesion)
  23. O kaip .net frameworkas? Deje programuoti C# be .net frameworko neišeina Reiktų naudoti kuo mažiau fancy featursu vidiniuose ratuose. Vidininiai ratai turi atitikti .NET Standarto specifikaciją .NET frameworkas iš esmės labai stabilus ir tikėtina pergyvens kuriamą sistemą Kaip “framework’ą reiktų laikyti MVC ASP. Jis žymiau labiau keitėsi negu .NET, dėl to ASP kodą reiktų laikyti išoriniame Presentation sluoksnyje. Jokiu būtų ne Application sluoksnyje
  24. O kaip Clean architektūra dera su MVC architektūra? Visų pirma MVC yra ne architetūra, o delivery patternas Ji priklauso presenstation sluoksnyje
  25. Iš esmes švari architektūra yra labai draugiška testam, nes kiekvienas komponentas turi aiškias ribas ir gali būti pakeistas į mocką Pvz, WEB’ą galima užmokinti ir kviesti tiesiai Application layeri’į iš automatinų testų. Tą patį galima padaryti su duomenų baze. Kuriant architektūrą testai turėtų būti laikomi tokie pat svarbūs kaip ir visi kiti moduliai. Jie neturi būti laikomi kažkas “už sistemos ribų”. Apie juos reikia pagalvoti nuo pat pirmų kodo eilučių nes vėliau integruoti gali būti sunku
  26. Nedidelis startup template’as kurį galima atsisiųsti iš MarketPlace’o Tik trys sluoksniai, pvz Core sluoksnyneje neišskrita Enterprise biznio logika ir Application biznio logika Minimas oficiliam ASP .NET Guide
  27. Visiem žinomas bet praktikoje dažnai užmirštamas Keep It Simple, Stupid principas. Kiss principas sako jog dauguma sistemų veikia geriau jeigu jos yra paprastos. Paprastumas turėtų būti jūsų pagrindinis tikslas kuriant sistemą. Stenkitės vengti perdėto kompleksiškumo.
  28. Plugin mindset. Duomenų bazė, framworkas, UI turi būti kaip plugin’ai į application branduolį.