.NET 10 Template · Open Source · MIT License

Clean Architecture, CQRS & DDD Template

A complete .NET 10 CMMS starter with automated architecture tests, outbox pattern, and event-driven cross-aggregate coordination — pragmatic DDD without over-engineering.

Integration Tests passing Unit and Architecture Tests passing Docker Build passing

Microservices-ready · Evolved into CleanArchitecture-DDD-CQRS-Microservices

Enterprise Patterns, Ready to Use

Everything you need to start a maintainable .NET application — with tests that enforce the rules.

🏗

Clean Architecture

Domain, Application, Infrastructure, and API layers with dependency inversion and clear boundaries.

⚙

DDD Tactical Patterns

Aggregates, value objects, domain events, and rich domain models with encapsulated business rules.

⇄

CQRS

EF Core for writes, Dapper for reads. Flexible read sources — replicas, Redis, Elasticsearch.

📦

Outbox Pattern

Guaranteed integration event delivery. Swap the publisher for message bus when you go microservices.

⚡

Event-Driven

Dual handlers: transactional domain events and async integration events via outbox.

🛡

Architecture Tests

Automated boundary enforcement at compile time. The key differentiator of this template.

Architecture Overview

Clean Architecture layers with CQRS write and read paths, domain events, and outbox delivery.

System architecture overview showing Clean Architecture layers, CQRS command and query paths, domain events, and outbox pattern in a .NET CMMS application

High-level system architecture — layers, CQRS, and event flow.

CQRS command flow diagram from API through handler, domain events, transactional handlers, integration events, and outbox background worker

Write path — commands, domain events, integration events, and outbox.

CQRS query flow diagram showing flexible read sources including Dapper, read replicas, Redis cache, and Elasticsearch with eventual consistency

Read path — flexible data sources with eventual consistency.

Sequence diagram showing command execution flow through API, mediator, handler, domain, and event handlers

Command sequence — end-to-end request flow.

Core Patterns

See the patterns deep dive and ADRs for details.

Cross-Aggregate Coordination

Domain events coordinate state across aggregates within ACID transactions. See ADR-001.

Optimistic Concurrency

SQL Server RowVersion prevents lost updates on concurrent writes. See ADR-002.

Domain vs Integration Events

Clear separation between transactional and async side effects. See ADR-003.

Structured Error Management

Result pattern with exportable error codes for frontend localization. See ADR-005.

Who Is This For?

Quick Start

Run the full stack with Docker in two commands.

Terminal
git clone https://github.com/mohd2sh/CleanArchitecture-DDD-CQRS.git
cd CleanArchitecture-DDD-CQRS
docker-compose up

Includes: SQL Server 2022, API service, automatic migrations and seeding.

Local dev: dotnet run --project src/CleanArchitecture.Cmms.Api

Prerequisites: .NET 10 SDK, Docker Desktop (recommended)

Related Repositories

Frequently Asked Questions

The template separates Domain, Application, Infrastructure, and API layers with strict dependency rules. Automated architecture tests enforce boundaries at compile time.

Commands use EF Core with write repositories. Queries use Dapper with read repositories. Architecture tests prevent read/write coupling.

Integration events are written to an outbox table in the same transaction as business data. A background processor delivers them with at-least-once semantics.

Run docker-compose up or dotnet run --project src/CleanArchitecture.Cmms.Api. See the Quick Start section.

Yes. See CleanArchitecture-DDD-CQRS-Microservices for the evolved implementation with saga orchestration and MassTransit.

Automated tests enforcing DDD rules at compile time — value object immutability, layer dependencies, CQRS separation, and bounded context isolation.