A production-ready .NET 10 template implementing Clean Architecture principles with modern best practices, Docker support, and comprehensive architecture testing.
This template follows Clean Architecture principles, organizing code into concentric layers with clear separation of concerns:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Web.Api (Presentation) β
β βββββββββββββββββββββββ β
β β Infrastructure β β
β βββββββββββββββββΌββββββββββββββββββββββΌβββββββββββββ β
β β Application (Use Cases) β β
β β βββββββββββββββββββββββββββββββββββββββββββββββ β β
β β β Domain (Business Logic) β β β
β β β βββββββββββββββββββββββββββββββββββββββββ β β β
β β β β SharedKernel (Common Types) β β β β
β β β βββββββββββββββββββββββββββββββββββββββββ β β β
β β βββββββββββββββββββββββββββββββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Web.Api β Infrastructure β Application β Domain β SharedKernel
Application β Domain
clean-architecture-template/
βββ src/
β βββ Domain/ # Core business entities and logic
β βββ Application/ # Use cases, interfaces, DTOs
β βββ Infrastructure/ # External implementations (DB, APIs)
β βββ SharedKernel/ # Common types (Result, Error, Entity)
β βββ Web.Api/ # REST API, controllers, middleware
βββ tests/
β βββ ArchitectureTests/ # NetArchTest rules enforcement
βββ docker-compose.yml # Full stack orchestration
βββ Directory.Packages.props # Central package management
- β Clean Architecture - Strict layer separation with dependency rules
- β .NET 10 - Latest framework with modern C# features
- β Docker Ready - Multi-stage builds with docker-compose
- β PostgreSQL - Configured with EF Core and naming conventions
- β Serilog - Structured logging with Seq integration
- β Health Checks - Built-in health monitoring endpoints
- β Swagger/OpenAPI - Auto-configured API documentation
- β JWT Authentication - Ready-to-configure authentication
- β Architecture Tests - NetArchTest enforces layer boundaries
- β SonarAnalyzer - Static code analysis
- β Central Package Management - Consistent versions
- β Strict Code Analysis - Treat warnings as errors
- β Result Pattern - Functional error handling
- β Domain Events - Event-driven architecture support
- β Base Entity - Common entity infrastructure
| Layer | Technologies |
|---|---|
| Framework | .NET 10, ASP.NET Core |
| Database | PostgreSQL, EF Core 10 |
| Logging | Serilog, Seq |
| Validation | FluentValidation |
| Testing | xUnit, NetArchTest, Shouldly |
| API Docs | Swagger/OpenAPI |
| Container | Docker, Docker Compose |
- .NET 10 SDK
- Docker Desktop
- IDE (Visual Studio 2022, Rider, or VS Code)
-
Clone the repository
git clone https://github.com/yourusername/clean-architecture-template.git cd clean-architecture-template -
Run with Docker Compose
docker-compose up --build
-
Access the application
- API:
http://localhost:5000 - Swagger UI:
http://localhost:5000/swagger - Seq Logs:
http://localhost:8081 - PostgreSQL:
localhost:5432
- API:
# Restore dependencies
dotnet restore
# Run the API (development)
dotnet run --project src/Web.Api
# Run architecture tests
dotnet test tests/ArchitectureTestsPure business logic with no external dependencies.
- Entities
- Value Objects
- Domain Events
- Domain Services
Use cases and application orchestration.
- Commands & Queries (CQRS ready)
- DTOs & Mappers
- Validation (FluentValidation)
- Service Interfaces
External concerns implementation.
- EF Core DbContext & Migrations
- Repository Implementations
- External Services
- JWT Authentication
Presentation layer.
- Minimal APIs / Endpoints
- Middleware Pipeline
- Swagger Configuration
- Health Checks
Architecture tests using NetArchTest ensure layer boundaries are never violated:
// Example rules enforced by tests
Domain β No dependencies on Application/Infrastructure/Presentation
Application β No dependencies on Infrastructure/Presentation
Infrastructure β No dependencies on PresentationRun tests to verify:
dotnet test --filter "ArchitectureTests"The template includes a complete Docker setup:
| Service | Port | Description |
|---|---|---|
| web-api | 5000/5001 | ASP.NET Core API |
| postgres | 5432 | PostgreSQL database |
| seq | 8081 | Log aggregation |
Key configuration in appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Host=postgres;Database=clean-architecture;Username=postgres;Password=postgres"
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Seq" ],
"WriteTo": [
{ "Name": "Seq", "Args": { "serverUrl": "http://seq:80" } }
]
}
}public class UserService
{
public async Task<Result<User>> GetUserByIdAsync(Guid id)
{
var user = await _repository.GetByIdAsync(id);
if (user is null)
return Result.Failure<User>(Error.NotFound);
return Result.Success(user);
}
}public class UserCreatedEvent : IDomainEvent
{
public Guid UserId { get; }
public DateTime CreatedAt { get; }
}Built with β€οΈ using Clean Architecture principles