.NET 9 Clean Architecture Project + Architecture Tests (NetArchTest & ArchUnitNET)
Ship with confidence and keep your architecture clean—automatically.
This .NET 9 Clean Architecture solution includes a fully working Web API and a comprehensive architecture test suite using NetArchTest and ArchUnitNET. Enforce boundaries, naming conventions, dependency flow, and design rules from day one—so your team scales without architectural debt.
What you’ll build with
- Clean Architecture layers: Domain / Application / Infrastructure / Web
- CQRS + MediatR for clear command/query flows
- EF Core (code-first) with proper DI setup
- Architecture tests that guard your rules (NetArchTest + ArchUnitNET)
- Docker support for local & CI runs
- GitHub Actions workflow for automated build & tests
- Structured logging & sensible defaults
Why this template
- Prevent drift: tests verify layer independence, dependency direction, and framework isolation.
- Team-friendly: crystal-clear patterns for new contributors.
- Production-ready: JWT-ready scaffolding, rate-limiting/middleware patterns, repository + spec pattern.
- Learn by doing: real, working examples of entities, services, use cases, and controllers.
What’s Included (files & projects)
Solution (5 projects)
- MyApp.Domain — core entities, value objects, events, specs, interfaces
- MyApp.Application — use cases, DTOs, behaviors, mappings, interfaces
-
MyApp.Infrastructure — EF Core
AppDbContext
, repositories, external services -
MyApp.Web — REST controllers, middleware, startup (
Program.cs
) - MyApp.Tests.Architecture — full architecture test suite
Architecture Tests
-
NetArchTest (basics):
- Domain independence
- Application dependency constraints
- Repository naming conventions
- Domain service interface checks
- Entity immutability
- Framework dependency restrictions
-
ArchUnitNET (advanced):
- Deep dependency analysis
- Entity design enforcement
- Microservice boundary validation
- Use-case isolation
- Controller dependency verification
Extras
- GitHub Actions CI workflow
- Dockerfile + docker-compose
- README with clear usage docs
-
.gitignore
, complete.csproj
targeting .NET 9
Requirements: .NET 9 SDK, Visual Studio 2022 or VS Code. Docker (optional).
Who it’s for
- .NET teams standardizing on Clean Architecture
- Tech leads/architects who want enforceable rules (not just docs)
- Agencies/contractors kicking off client projects with guardrails
- Learners who need a production-style reference implementation
FAQ (SEO-friendly)
How do the tests prevent architecture drift?
They fail the build when rules are violated (e.g., Domain referencing Infrastructure, wrong dependency direction, naming violations).
Can I add my own rules?
Yes—extend NetArchTest/ArchUnitNET specs for custom boundaries, namespaces, naming, or forbidden references.
Is EF Core mandatory?
It’s the default infra; swap or add providers with minimal changes thanks to clear boundaries.
Does it include CI?
Yes—GitHub Actions workflow runs build and tests on push/PR.
Production-ready solution with CQRS/MediatR, EF Core, DI, Docker, and CI—complete architecture test suite to enforce rules and prevent drift.