Clean Architecture template · .NET 8

Start your next API from a solved foundation, not a blank folder

A production-ready ASP.NET Core Web API template — Clean Architecture layering, CQRS, validation, and the PowerCSharp Features engine already wired up. Available as a GitHub template and a dotnet new template.

Strict dependency rule

Inner layers never reference outer layers

Domain and Shared sit at the center with zero external dependencies. Application and Operational wrap them with use cases and resilience. Infrastructure adapts to the outside world. Presentation and WebApi are the composition root — dependencies only ever point inward.

Layer stack, outermost first

WebApi

composition root · Program.cs · middleware

Presentation

controllers · ApiResponse<T> envelope

Application & Operational

CQRS/MediatR · validators · Polly resilience

Infrastructure

adapters · DateTimeProvider · DI wiring

Domain & Shared

BaseEntity<TId>, IAggregateRoot · enums & constants

CQRS & validation

MediatR handlers, FluentValidation, one response envelope

Commands and Queries are separated into dedicated folders. BaseApiController.SendAsync<T>() dispatches through MediatR and maps results to HTTP via an Ardalis.Result extension. A LoggingBehavior pipeline logs every request and response automatically, and FluentValidation validators run before a request ever reaches its handler.

  • ApiResponse<T>

    A consistent response envelope on every endpoint, mapped automatically from Ardalis.Result.

  • LoggingBehavior<TRequest, TResponse>

    A MediatR pipeline behavior that logs every request and response without per-handler boilerplate.

  • Polly retry policies

    IRetryPolicyProvider in the Operational layer, ready to wire into any infrastructure adapter.

PowerCSharp Features, wired in

Flag-gated capabilities from day one

CORS, an in-memory BitFaster cache, and a disk-backed cache are already registered as pluggable PowerCSharp features, toggled via PowerFeatures:<Key>:Enabled. A host-local Samples feature ships living-documentation endpoints — enabled in Development, disabled in production by default.

appsettings.json
{
  "PowerFeatures": {
    "Cors": { "Enabled": true, "AllowedOrigins": [ "https://localhost" ] },
    "Cache": { "Enabled": true, "Provider": "BitFaster", "Capacity": 1000 },
    "DiskCache": { "Enabled": true, "DirectoryPath": "./cache" },
    "Samples": { "Enabled": false }
  }
}

Two ways to start

Clone and run

Includes Docker Compose for local development and CI workflows for build, test, and release.

terminal
git clone https://github.com/marioarce/PowerCSharp.CleanArchitecture.git
cd PowerCSharp.CleanArchitecture

dotnet restore
dotnet build
dotnet run --project src/CleanArchitecture.WebApi

Scaffold with dotnet new

--name replaces CleanArchitecture everywhere — filenames, namespaces, and the solution file.

terminal
dotnet new install PowerCSharp.CleanArchitecture.Template

dotnet new powercsharp-cleanarchitecture --name MyAwesomeApi --output ./MyAwesomeApi
cd MyAwesomeApi
dotnet run --project src/MyAwesomeApi.WebApi

MIT licensed, ready to fork

Health checks at /health, WebApplicationFactory-based integration tests, and a multi-stage Dockerfile are already in place.

View PowerCSharp.CleanArchitecture