CleanArchitectureGenerator 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global CleanArchitectureGenerator --version 2.0.0
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local CleanArchitectureGenerator --version 2.0.0
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=CleanArchitectureGenerator&version=2.0.0
                    
nuke :add-package CleanArchitectureGenerator --version 2.0.0
                    

CleanArchitectureGenerator

NuGet NuGet Downloads .NET License: MIT

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 build before 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

The tool will prompt you for:

  1. Project name — PascalCase, e.g. MyApp
  2. Database providerSQL Server or PostgreSQL

Your solution is scaffolded, pruned, and build-verified in the current directory under ./MyApp/.

Non-interactive usage

cleanarch new --name MyApp --provider sqlserver
cleanarch new --name MyApp --provider postgresql
cleanarch new --name MyApp --output /path/to/output
Option Alias Description
--name -n Project name (PascalCase). Prompted if omitted.
--provider -p sqlserver or postgresql. Prompted if omitted.
--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> or Result; no thrown exceptions for business failures
  • Domain events — aggregates raise events via Entity.Raise(IDomainEvent); DomainEventsDispatcher delivers 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.


License

MIT © Tsholofelo

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
2.1.0 49 6/22/2026
2.0.0 68 6/19/2026 2.0.0 is deprecated because it has critical bugs.
1.0.0 72 6/18/2026 1.0.0 is deprecated because it has critical bugs.