Skip to content

Genocs/clean-architecture-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

License Build Packages Downloads Prev Downloads Contributors Forks Stargazers Issues Discord Gitter Twitter Twitterx LinkedIn

Exagonal Architecture

Genocs Clean Architecture Template

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.

✨ Features

  • 🏗️ 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

📋 Table of Contents

📋 Prerequisites

🚀 Quick Start

Install the Template

# 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 full

🏗️ Architecture Overview

The 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

Key Components

  • 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

How to build and install the template locally

To build the package run the following commands:

custom-templates

dotnet-templating

# 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 rebus

Miscellaneous

Useful commands:

# How to get the list of installed templates
dotnet new -u

# How to get the list of templates
dotnet new list

🔧 Development Workflow

Local Development

# 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

💬 Community & Support

Get Help

Stay Connected

Show Your Support

🔧 Troubleshooting

Common Issues

For more details on getting started, read the documentation

Please check the documentation for more details.

Changelogs

View Complete Changelogs.

License

This project is licensed with the MIT license.

Community

Code Contributors

This project exists thanks to all the people who contribute. Submit your PR and join the team!

genocs contributors

Financial Contributors

Become a financial contributor and help me sustain the project.

Support the Project on Opencollective

Acknowledgements

⚙️ Template Options

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