Skip to content

This stands as a comprehensive solution template that embodies the principles of Clean Architecture, seamlessly integrated with the prowess of CQRS implementation, all within the ASP.NET Core framework.

License

Notifications You must be signed in to change notification settings

omid-ahmadpour/CleanArchitecture-Template

Repository files navigation

CleanArchitecture-Template

Welcome to the CleanArchitecture-Template repository, a powerful solution template that exemplifies the principles of Clean Architecture and integrates them seamlessly with CQRS using ASP.NET Core.

CleanArchitecture

Show Your Appreciation! ⭐

If you find value in this project, whether you're using it for learning or kickstarting your solution, a star is a wonderful way to express your support. Thank you in advance!

Prerequisites

  • Visual Studio 2022
  • .NET 8.0 Runtime

Architecture

For full notes and explanations, see docs/architecture.md.

flowchart TB
  %% LAYERS
  subgraph Presentation["Presentation Layer (ASP.NET Core Web API)"]
    Controllers["API Controllers"]
    Middleware["Middleware / Filters"]
    Versioning["API Versioning"]
    Swagger["Swagger / OpenAPI"]
  end

  subgraph Application["Application Layer (CQRS, Use Cases)"]
    CQRS["Commands / Queries (DTOs)"]
    Handlers["Handlers (Use Cases)"]
    Behaviors["Pipeline Behaviors (Validation / Logging / Caching)"]
    Validators["Validators"]
    AppPorts["Application Interfaces (Ports)"]
  end

  subgraph Domain["Domain Layer (Enterprise Logic)"]
    Entities["Entities / Aggregates"]
    ValueObjects["Value Objects"]
    DomainEvents["Domain Events"]
    RepoPorts["Repository Interfaces (Ports)"]
    DomainServices["Domain Services"]
  end

  subgraph Infrastructure["Infrastructure Layer (Implementations)"]
    Repositories["Repository Implementations (Adapters)"]
    DbContext["EF Core DbContext + Configurations"]
    External["External Integrations (e.g., Email, Cache, Message Bus)"]
    Auth["Authentication / Authorization"]
  end

  subgraph Testing["Testing"]
    UnitTests["Unit Tests"]
    IntegrationTests["Integration Tests"]
  end

  Database[("Relational Database")]

  %% FLOWS
  Client["Client (HTTP / Swagger UI)"] --> Controllers
  Controllers -->|Command/Query| CQRS
  Middleware -. cross-cutting .-> Controllers
  Versioning -. applies .-> Controllers
  Swagger -. docs/ui .-> Client

  CQRS --> Handlers
  Handlers -->|invokes| Domain
  Validators --> Behaviors
  Behaviors -. cross-cutting .-> Handlers

  %% PORTS AND ADAPTERS
  Handlers -->|via ports| RepoPorts
  RepoPorts --> Repositories
  Repositories --> DbContext
  DbContext --> Database

  %% DOMAIN EVENTS
  DomainEvents -. publish/handle .-> Handlers

  %% TESTING SURFACES
  UnitTests --> Domain
  UnitTests --> Application
  IntegrationTests --> Presentation
  IntegrationTests --> Infrastructure

  %% INTERNAL RELATIONSHIPS
  DomainServices --- Entities
  ValueObjects --- Entities
  AppPorts --- Handlers
Loading

Effortless Project Creation

Here's the simplest way to get started with your project:

  1. Open your command-line interface.
  2. Execute the following command:
    dotnet new install ASPNETCleanTemplate.nuspec::3.5.2
  3. Create an empty folder to house your solution and navigate into it.
  4. Run the subsequent command, replacing MyNewCleanTemplate with your desired project name:
    dotnet new aspnetcleantemplate -n MyNewCleanTemplate

Smooth Database Migration:

To handle database migration with finesse:

  1. Set the default project to Persistence.
  2. Open the Package Manager Console and run:
    Update-Database -Context AppDbContext

Monitor Health

For health check administration, utilize the following URL: https://Url:Port/healthchecks-ui

Technologies at Play:

  • ASP.NET Core
  • Entity Framework Core
  • MediatR
  • Swagger
  • Redis (for distributed caching)
  • Jwt Token Authentication
  • Custom Asp.Net Identity
  • Api Versioning
  • FluentValidation
  • PolyCache (for caching)
  • Serilog
  • Elasticsearch (for writing Logs)
  • Mapper
  • Docker
  • xUnit

Championing Best Practices and Design Principles:

  • Clean Architecture
  • Clean Code
  • CQRS
  • Authentication and Authorization
  • Distributed caching
  • SOLID Principles
  • Segregated ReadOnly and Write DbContext
  • Segregated ReadOnly and Write Repository
  • REST API Naming Conventions
  • Multi-environment Utilization in ASP.NET Core (Development, Production, Staging, etc.)
  • Modular Design
  • Custom Exceptions
  • Tailored Exception Handling
  • Unit Tests
  • Integration Tests
  • PipelineBehavior for Validation and Performance Tracking.

Further Reading

  1. The Significance of Clean Architecture Template with .NET
  2. Understanding and Implementing Scalability in CQRS
  3. Why We Need Clean Architecture?

Elevate your development journey with the CleanArchitecture-Template Plus!

About

This stands as a comprehensive solution template that embodies the principles of Clean Architecture, seamlessly integrated with the prowess of CQRS implementation, all within the ASP.NET Core framework.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •