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.
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!
- Visual Studio 2022
- .NET 8.0 Runtime
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
Here's the simplest way to get started with your project:
- Open your command-line interface.
- Execute the following command:
dotnet new install ASPNETCleanTemplate.nuspec::3.5.2
- Create an empty folder to house your solution and navigate into it.
- Run the subsequent command, replacing
MyNewCleanTemplate
with your desired project name:dotnet new aspnetcleantemplate -n MyNewCleanTemplate
To handle database migration with finesse:
- Set the default project to Persistence.
- Open the Package Manager Console and run:
Update-Database -Context AppDbContext
For health check administration, utilize the following URL: https://Url:Port/healthchecks-ui
- 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
- 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.
- The Significance of Clean Architecture Template with .NET
- Understanding and Implementing Scalability in CQRS
- Why We Need Clean Architecture?
Elevate your development journey with the CleanArchitecture-Template Plus!