Clean Architecture - amitbhilagude/userfullinks GitHub Wiki

  1. Clean architecture overview
    1. Solution contains 3 main projects. it is alternative for n-tier architecture
      1. Core Project
        1. Most of the business logic and domain model is implemented here
      2. Infrastructure Project
        1. DB connectivity and implementation is here
      3. API or Web Project
        1. Front-end application that contains endpoint and interacts with the core project. Controllers in this project are very small as all business logic is reside in the Core project.
      4. Nuget package download for clean Architecture template https://github.com/ardalis/CleanArchitecture
        1. Another example with additional layer. which is best practice https://github.com/matthewrenze/clean-architecture-core
    2. Earlier it was DB centric architecture not it is moved to the Domain centric architecture.
  2. Principals
    1. Separation of Concerns.
      1. Separate code which has different responsibilities by creating folder or namespace etc.
    2. Single Responsibility from SOLID i.e. Avoid God Classes which does everything
    3. Don't repeat or duplications
    4. Dependency Inversion: Should talk using abstractions using Interfaces.
  3. Challenges with n-tier Architecture
    1. This Architecture heavily depends on the DB layer and is difficult to test each layer separately.
    2. Clean Architecture is Domain-Centric Design and Domain Model is the focus.
  4. Domain Model vs Data Model
    1. Data Model are EF Entities(Not DDD Entities) which fetches the Data in different views as per requirement
    2. Domain Models are Entities(DDD Concept- Classes), Interfaces, Services and More
  5. Rules
    1. Domain Model should be part of Core Project
    2. All Projects should depend on the Core Project
    3. Innerproject should implement the Interface and the outer project should implement always e.g. Core project will have interfaces always.
    4. Avoid direct dependency with Repository project except for Startup.cs and Integration test.
    5. Core Project shouldn't have dependencies except Standerd Nuget packages.It contains Interfaces, DDD Concepts(Entities, Value Objects, Aggregates, Domain Services and exceptions), Domain Events and Event Handlers.It uses Specification Pattern. Query-based pattern to communicate to repository pattern or Core Project
    6. Infrastructure Project: It contents Repositories, EF Core context, Cached Repository, HTTP Clients, Email send or any other interfaces which is used by internal Infrastructure project e.g. Blob Interface to connect to blob storage. It needs to loosely-coupled pattern which can be replaced easily by any other.
    7. Web Project: Controllers, Views, Razor pages, View Models, Filters, etc. or any interfaces used inside.
    8. Controller needs to be as light as possible. you can interact controller with the core by using domain events. MediatR is a common NuGet package is sued to send domain events.
  6. Fully working example
    1. https://github.com/dotnet-architecture/eShopOnWeb