CleanArch Starter
Production-ready Clean Architecture template with CQRS, MediatR, and EF Core
About This Project
A ready-to-clone .NET 8 solution built on Clean Architecture with CQRS and MediatR. Covers Domain, Application, Infrastructure, and API layers — with FluentValidation pipeline behaviours, global error handling via ProblemDetails, Serilog structured logging, EF Core with PostgreSQL, and a full test suite using xUnit, Moq, and Testcontainers.
What You'll Learn
Key Features
Project Structure
CleanArch-Starter/ ├── src/ │ ├── CleanArch.Domain/ # Entities, value objects, domain events │ │ ├── Entities/ │ │ ├── Events/ │ │ └── Interfaces/ # Repository interfaces │ ├── CleanArch.Application/ # CQRS handlers, validators, DTOs │ │ ├── Commands/ │ │ ├── Queries/ │ │ ├── Validators/ │ │ └── Behaviours/ # MediatR pipeline (logging, validation) │ ├── CleanArch.Infrastructure/ # EF Core, repositories, migrations │ └── CleanArch.Api/ # Controllers, middleware, DI config ├── tests/ │ ├── CleanArch.Unit/ # Handler tests with Moq │ └── CleanArch.Integration/ # Testcontainers + WebApplicationFactory └── docker-compose.yml
Setup Guide
Clone the repository
Clone CleanArch Starter and navigate into the solution.
git clone https://github.com/asmanasir/CleanArch-Starter.git cd CleanArch-Starter
Start PostgreSQL with Docker
Spin up the database — the app uses PostgreSQL via EF Core.
docker-compose up -d db
Run EF Core migrations
Create the database schema from the existing migrations.
dotnet ef database update --project src/CleanArch.Infrastructure
Running the Project
Run the API
Start the API — Scalar docs open at /scalar/v1.
dotnet run --project src/CleanArch.Api
Run the test suite
Execute unit tests (Moq) and integration tests (Testcontainers). Testcontainers spins up a real PostgreSQL instance for integration tests.
dotnet test
Project Info
Tech Stack
Prerequisites
- .NET 8 SDK installed
- Docker Desktop installed
- Basic C# knowledge (classes, interfaces, async/await)
Learnixo
Project Author
The starting point most teams wish they had from day one. Clone it, rename the namespace, and you have a production-ready architecture — not a tutorial that falls apart the moment you add a second feature.