Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clean Architecture

Clean Architecture

Ivan Paulovich

November 17, 2020
Tweet

More Decks by Ivan Paulovich

Other Decks in Programming

Transcript

  1. The “Software Architecture” Presentation Layer ASP.NET MVC and Autofac Business

    Layer MediatR and AutoMapper Data Layer Entity Framework and Dapper Database and Messaging SQL Server and RabbitMQ IDE and Tools Visual Studio, Resharper and .NET Framework 3 @ivanpaulovich
  2. The “Software Architecture” Presentation Layer ASP.NET MVC and Autofac Business

    Layer MediatR and AutoMapper Data Layer Entity Framework and Dapper Database and Messaging SQL Server and RabbitMQ IDE and Tools Visual Studio, Resharper and .NET Framework 4 @ivanpaulovich Not a Software Architecture!
  3. Each of these architectures produce systems that are: • Independent

    of Frameworks. • Testable. • Independent of UI. • Independent of Database. • Independent of any external agency. https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html “ @ivanpaulovich
  4. Clean Architecture Style @ivanpaulovich Clean Architecture Style Hexagonal Architecture Style

    Ports and Adapters Pattern Dependency Inversion
 Principle Test-Driven Development Clean Architecture Style @ivanpaulovich
  5. Clean Architecture Style Hexagonal Architecture Style Ports and Adapters Pattern

    Dependency Inversion
 Principle Test-Driven Development Clean Architecture Style Object-Oriented Design
 Principles Use Cases as Central Organising Structure Pluggable User Interface @ivanpaulovich
  6. Hexagonal Architecture Style 1. Ports and Adapters pattern. 2. The

    implementation is guided by tests. 3. It is decoupled from technology details. @ivanpaulovich
  7. Business @ivanpaulovich 13 Ports and Adapters Cloud 
 Messaging UI

    In Memory 
 Persistence 
 Tests In Memory 
 Messaging 
 SQL
  8. Business @ivanpaulovich 14 Ports and Adapters Cloud 
 Messaging UI

    In Memory 
 Persistence 
 Tests In Memory 
 Messaging 
 SQL Ports
  9. Business v @ivanpaulovich 16 Ports and Adapters Cloud 
 Messaging

    UI In Memory 
 Persistence 
 Tests In Memory 
 Messaging 
 SQL Adapters
  10. Application Unit Test Web Database Domain Primary Actors Secondary Actors

    @ivanpaulovich 18 Infrastructure Ports and Adapters
  11. The First Test Deposit 
 Use Case Customer 
 Repository

    Account Repository Test Expectations @ivanpaulovich
  12. The Walking Skeleton Deposit 
 Use Case Customer 
 Repository

    Account Repository Fakes User 
 Interface @ivanpaulovich
  13. Deposit 
 Use Case Customer 
 Repository Account Repository Fakes

    User 
 Interface Integration Tests s Account Repository Test Customer 
 Repository
  14. A Wallet Application Deposit Withdraw Transfer Close Account Open Account

    Database Persistence Exchange Service User Interface Exchange Rates API In Memory SQL In Memory Security @ivanpaulovich
  15. Services Controllers Repositories Use Cases Domain Component 
 Tests HTTP

    Component Tests @ivanpaulovich Fake API Fake DB
  16. Services Controllers Repositories Use Cases Domain External APIS Database TCP

    HTTP Integration Tests Integration Tests @ivanpaulovich
  17. Application External APIS Database End to End 
 Tests HTTP

    TCP HTTP End to End Tests @ivanpaulovich
  18. Use Cases • Use Cases show the intent of a

    system. • Use Cases are delivery independent. • Use Cases are algorithms that interpret the input to generate the output data. • Use Cases diagrams highlight the Primary and secondary actors. 29 @ivanpaulovich
  19. Controller Use Case Core User Interface @ivanpaulovich Request Response Input

    Output • Abstract • General • Stable • Consistent • Concrete • Speci f i c • Unstable • Inconsistent
  20. Entities Entities Clean Architecture Entities Use Cases Controllers Gatew ays

    Presenters D evices W eb UI DB External Interfaces @ivanpaulovich •Abstractness increases with stability. •Modules depend in the direction of stability. •Classes that change together are packaged together.
  21. Entities Use Cases Controllers Presenters Gateways Devices UI DB Web

    External Interfaces Abstract,
 General,
 Stable,
 Consistent Concrete,
 Speci f i c, 
 Unstable, Inconsistent Level Clean Architecture @ivanpaulovich
  22. Takeaways • Clean Architecture is about usage and the use

    cases are the central organising structure. • Use cases implementation are guided by tests. • The User Interface and Persistence adapters are designed to ful f i l the core needs (not the opposite!). • Defer decisions by implementing the simplest component f i rst. 40 @ivanpaulovich