CleanArchitectureGenerator 2.1.0
dotnet tool install --global CleanArchitectureGenerator --version 2.1.0
dotnet new tool-manifest
dotnet tool install --local CleanArchitectureGenerator --version 2.1.0
#tool dotnet:?package=CleanArchitectureGenerator&version=2.1.0
nuke :add-package CleanArchitectureGenerator --version 2.1.0
CleanArchitectureGenerator
A dotnet global tool that scaffolds production-ready Clean Architecture solutions for .NET — with a single command, an interactive CLI, and your choice of database provider.
No boilerplate hunting. No wiring up layers from scratch. Run
cleanarch new, answer two questions, and ship.
Features
- Interactive CLI — prompts for project name and database provider; no flags to memorise
- Single-provider output — generates a genuinely clean codebase: SQL Server or PostgreSQL, with zero dead code from the unchosen provider
- Build-verified scaffold — runs
dotnet buildbefore handing control back; a non-compiling project is never delivered - Production patterns baked in — CQRS, Result pattern, domain events, FluentValidation, Serilog structured logging, health checks, and Scalar API docs out of the box
- EF Core migrations-ready — connection strings, schema configuration, and retry policies pre-wired for both providers
- Minimal APIs — endpoint-per-file pattern under
WebApi/Endpoints/
Installation
dotnet tool install --global CleanArchitectureGenerator
Requires the .NET 10 SDK or later.
Quick Start
cleanarch new MyApp -d postgres -o ./MyApp
cleanarch new MyApp -d sqlserver -o ./MyApp
| Option | Alias | Description |
|---|---|---|
<name> |
Project name (PascalCase), passed as a positional argument. | |
--database |
-d |
sqlserver or postgres. |
--output |
-o |
Output directory. Defaults to the current working directory. |
What Gets Scaffolded
Project Structure
MyApp/
├── SharedKernel/ # Entity base, Result<T>, domain event contracts
├── MyApp.Domain/ # Aggregates, value objects, domain events
├── MyApp.Application/ # Use cases (commands & queries), validation
├── MyApp.Infrastructure/ # EF Core, migrations, domain event dispatcher
├── MyApp.WebApi/ # Minimal API endpoints, Serilog, health checks
├── Directory.Packages.props # Centralised NuGet version management
└── MyApp.slnx # Solution file
Architecture
Each layer has a single responsibility and depends only inward:
| Layer | Project | Responsibility |
|---|---|---|
| Domain | MyApp.Domain |
Aggregates, value objects, domain events — no framework dependencies |
| Application | MyApp.Application |
Commands, queries, validators, use-case orchestration |
| Infrastructure | MyApp.Infrastructure |
EF Core context, migrations, domain event dispatcher, health checks |
| Presentation | MyApp.WebApi |
Minimal API endpoint registration, Serilog configuration, DI composition root |
Tech Stack
| Concern | Library |
|---|---|
| ORM | Entity Framework Core |
| CQRS mediator | Custom ICommandHandler<T> / IQueryHandler<T,R> (no MediatR dependency) |
| Validation | FluentValidation (pipeline decorator pattern) |
| Logging | Serilog (console + optional DB sink) |
| API documentation | Scalar (OpenAPI) |
| Health checks | Microsoft.Extensions.Diagnostics.HealthChecks |
| CLI | Spectre.Console.Cli |
Patterns
- Result pattern — all use-case handlers return
Result<T>orResult; no thrown exceptions for business failures - Domain events — aggregates raise events via
Entity.Raise(IDomainEvent);DomainEventsDispatcherdelivers them post-SaveChangesAsync - Validation decorator — FluentValidation validators are automatically discovered and composed around command handlers
- Endpoint-per-file — each HTTP endpoint lives in its own sealed class implementing
IEndpoint, registered via assembly scanning
Getting Started with Your Scaffolded Project
Prerequisites
- .NET 10 SDK
dotnet tool install --global dotnet-ef- A running SQL Server or PostgreSQL instance
1. Set the connection string
Edit MyApp.WebApi/appsettings.json:
"ConnectionStrings": {
"LocalDb": "Server=localhost;Database=MyApp;Trusted_Connection=True;"
}
For PostgreSQL:
"ConnectionStrings": {
"LocalDb": "Host=localhost;Database=MyApp;Username=postgres;Password=yourpassword"
}
2. Add the initial migration
dotnet ef migrations add InitialCreate \
--project MyApp.Infrastructure \
--startup-project MyApp.WebApi
3. Apply migrations
dotnet ef database update \
--project MyApp.Infrastructure \
--startup-project MyApp.WebApi
4. Run the API
dotnet run --project MyApp.WebApi
5. Explore the API
Open https://localhost:{port}/scalar for interactive API docs.
Health check endpoint: GET /health
Provider Pruning
When you select a database provider, the generator removes all traces of the unchosen provider from the scaffolded output:
| Artefact | SQL Server selection removes | PostgreSQL selection removes |
|---|---|---|
Directory.Packages.props |
Npgsql packages | SqlServer + Serilog.MSSqlServer packages |
*.Infrastructure.csproj |
Npgsql EF provider | SqlServer EF provider |
*.WebApi.csproj |
— | Serilog.Sinks.MSSqlServer |
DatabaseProvider.cs |
PostgreSQL enum value + resolver branch | SqlServer enum value + resolver branch |
DependencyInjection.cs |
UseNpgsql branch |
UseSqlServer branch |
appsettings.json |
PostgreSQL connection string key | LocalDb / SQL Server connection string key |
The result is a codebase with no dead code, no #if directives, and no multi-provider switch statements.
Best Practices
For recommended patterns and production guidance when working with the generated solution, visit the Best Practices section on the official website:
cleanarchitecturegenerator.com — Best Practices
License
MIT © Tsholofelo
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.