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
Clean architectureClean architecture
Clean architectureandbed
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean ArchitectureDmytro Turskyi
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignRyan Riley
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)Tom Kocjan
 
Clean architecture on android
Clean architecture on androidClean architecture on android
Clean architecture on androidBenjamin Cheng
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationOğuzhan Soykan
 
ITkonekt 2019 | Robert C. Martin (Uncle Bob), Clean Architecture and Design
ITkonekt 2019 | Robert C. Martin (Uncle Bob), Clean Architecture and DesignITkonekt 2019 | Robert C. Martin (Uncle Bob), Clean Architecture and Design
ITkonekt 2019 | Robert C. Martin (Uncle Bob), Clean Architecture and DesignErginBilgin3
 
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
 
Domain-Driven Design
Domain-Driven DesignDomain-Driven Design
Domain-Driven DesignAndriy Buday
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignNader Albert
 
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
 
Hexagonal architecture for java applications
Hexagonal architecture for java applicationsHexagonal architecture for java applications
Hexagonal architecture for java applicationsFabricio Epaminondas
 
Onion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureOnion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureAttila Bertók
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureMohamed Galal
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design PrinciplesAndreas Enbohm
 
Hexagonal Architecture.pdf
Hexagonal Architecture.pdfHexagonal Architecture.pdf
Hexagonal Architecture.pdfVladimirRadzivil
 

What's hot (20)

Clean architecture
Clean architectureClean architecture
Clean architecture
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean Architecture
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
 
Clean architecture on android
Clean architecture on androidClean architecture on android
Clean architecture on android
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) Presentation
 
ITkonekt 2019 | Robert C. Martin (Uncle Bob), Clean Architecture and Design
ITkonekt 2019 | Robert C. Martin (Uncle Bob), Clean Architecture and DesignITkonekt 2019 | Robert C. Martin (Uncle Bob), Clean Architecture and Design
ITkonekt 2019 | Robert C. Martin (Uncle Bob), Clean Architecture and Design
 
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
 
Domain-Driven Design
Domain-Driven DesignDomain-Driven Design
Domain-Driven Design
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
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 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
 
Hexagonal architecture
Hexagonal architectureHexagonal architecture
Hexagonal architecture
 
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
 
Hexagonal architecture for java applications
Hexagonal architecture for java applicationsHexagonal architecture for java applications
Hexagonal architecture for java applications
 
Onion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureOnion Architecture / Clean Architecture
Onion Architecture / Clean Architecture
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
Hexagonal Architecture.pdf
Hexagonal Architecture.pdfHexagonal Architecture.pdf
Hexagonal Architecture.pdf
 

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

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
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.
 

Recently uploaded (20)

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
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
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
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 ...
 

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į.