A comprehensive .NET 9 project template that follows Clean Architecture principles and Domain-Driven Design (DDD). This template helps you rapidly scaffold microservices applications with built-in support for multiple databases, message brokers, and enterprise patterns.
- 🏗️ Clean Architecture - Domain, Application, Infrastructure, and Presentation layers
- 🎯 Domain-Driven Design - Rich domain models with proper separation of concerns
- 📨 CQRS Pattern - Command Query Responsibility Segregation with MediatR
- 🚌 Message Brokers - Support for RabbitMQ, Azure Service Bus, and more
- 🗃️ Multiple Databases - SQL Server, MongoDB, Redis integration
- 🔍 Observability - OpenTelemetry tracing and monitoring
- 🐳 Containerization - Docker and Kubernetes ready
- ⚡ Background Services - Worker services for async processing
- 🧪 Comprehensive Testing - Unit, Integration, and Acceptance tests
- Features
- Prerequisites
- Quick Start
- Template Options
- Architecture Overview
- Development Workflow
- Examples
- Troubleshooting
- Community & Support
- Contributing
- License
- .NET 9 SDK (latest version)
- IDE (choose one):
- Visual Studio 2022 (recommended)
- Visual Studio Code with C# extension
- JetBrains Rider
- Optional for development:
- Docker Desktop for containerization
- MongoDB, SQL Server
# Install the latest version
dotnet new install Genocs.CleanArchitecture.Template
# Or install a specific version
dotnet new install Genocs.CleanArchitecture.Template::4.0.1
# View all available options
dotnet new cleanarchitecture --help
# Example with custom options
dotnet new cleanarchitecture \
--name "CompanyName.ServiceName" \
--database inmemory \
--service-bus rebus \
--use-cases fullThe template generates a solution with the following structure:
src/
├── AcceptanceTests/ # Acceptance Tests
├── Application/ # Use cases and application services
├── Contracts/ # API and ServiceBus contracts and commansd, events and messages
├── Contracts.NServiceBus/ # API and ServiceBus contracts and commansd, events and messages, used by NServiceBus
├── Domain/ # Core business logic and entities
├── Infrastructure/ # Data access and external services
├── IntegrationTests/ # Integration Tests
├── UnitTests/ # Unit Tests
├── WebApi/ # REST API controllers and middleware
├── Worker/ # Background services and message handlers
└── Contracts/ # API contracts and events- Domain Layer: Entities, value objects, domain services
- Application Layer: CQRS handlers, interfaces, DTOs
- Infrastructure Layer: Repositories, message brokers, databases
- Presentation Layer: Controllers, middleware, API documentation
To build the package run the following commands:
# To clone the repository
git clone https://github.com/Genocs/clean-architecture-template
cd clean-architecture-template
# To pack and install the template
dotnet pack ./src/Package.Template.csproj -p:PackageVersion=4.0.1 --configuration Release --output ./out
dotnet new install ./out/Genocs.CleanArchitecture.Template.4.0.1.nupkg
dotnet new cleanarchitecture --help
# To uninstall the template
dotnet new uninstall Genocs.CleanArchitecture.Template
# Example of creating a new project with InMemory database and Rebus as service bus
dotnet new cleanarchitecture --name {CompanyName.ServiceName} -da inmemory -sb rebusUseful commands:
# How to get the list of installed templates
dotnet new -u
# How to get the list of templates
dotnet new list# Start infrastructure services
docker-compose -f ./infrastructure/docker/docker-compose-infrastructure.yml up -d
# Run the API
dotnet run --project src/YourProject.WebApi
# Run the Worker
dotnet run --project src/YourProject.Worker
# Run all tests
dotnet test
# Run specific test projects
dotnet test src/UnitTests
dotnet test src/IntegrationTests
dotnet test src/AcceptanceTests- ⭐ Star this repository
- 🔄 Share with your team
- ☕ Buy me a coffee
For more details on getting started, read the documentation
Please check the documentation for more details.
View Complete Changelogs.
This project is licensed with the MIT license.
This project exists thanks to all the people who contribute. Submit your PR and join the team!
Become a financial contributor and help me sustain the project.
Support the Project on Opencollective
| Option | Description | Values | Default |
|---|---|---|---|
--name |
Project name | {Company.Project.Service} |
Required |
--database |
Database provider | inmemory, sqlserver, mongodb |
inmemory |
--servicebus |
Message broker | particular, masstransit, rebus |
masstransit |
--use-cases |
Use case complexity | basic, full, readonly |
basic |
