CleanArchPro 1.0.1

dotnet tool install --global CleanArchPro --version 1.0.1
                    
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 CleanArchPro --version 1.0.1
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=CleanArchPro&version=1.0.1
                    
nuke :add-package CleanArchPro --version 1.0.1
                    

CleanArch Pro

Generate and enforce Clean Architecture automatically.

CleanArch Pro is an enterprise-grade C# ecosystem designed to help engineering teams quickly establish, validate, and enforce Clean Architecture boundaries in .NET 8 applications. It consists of a Global .NET CLI Tool, a Roslyn Analyzer, and automated Code Fix Providers.


Architecture Overview

Clean Architecture separates software into layers to achieve high maintainability, testability, and independence from external frameworks (UI, databases, APIs).

graph TD
    API[API Layer / Web UI] --> Infrastructure[Infrastructure Layer]
    API --> Application[Application Layer]
    Infrastructure --> Application
    Infrastructure --> Domain[Domain Layer]
    Application --> Domain
    
    style Domain fill:#4CAF50,stroke:#388E3C,stroke-width:2px,color:#fff
    style Application fill:#2196F3,stroke:#1976D2,stroke-width:2px,color:#fff
    style Infrastructure fill:#FF9800,stroke:#F57C00,stroke-width:2px,color:#fff
    style API fill:#9C27B0,stroke:#7B1FA2,stroke-width:2px,color:#fff

Dependency Flow Rule

Dependencies must always flow inward.

  • Domain is the core, representing business entities and rules. It has zero dependencies on outer layers.
  • Application defines use cases and interfaces, depending only on Domain.
  • Infrastructure implements database persistence, external integrations, etc., depending on Application and Domain.
  • API/Presentation acts as the entry point, depending on Application and Infrastructure (for dependency injection wireup).

Project Structure

A typical project created using CleanArch Pro will follow this directory layout:

<SolutionName>
├── src
│   ├── <SolutionName>.Domain          # Core business entities, value objects
│   ├── <SolutionName>.Application     # Use cases, MediatR handlers, DTOs, interfaces
│   ├── <SolutionName>.Infrastructure  # EF Core, repository implementations
│   └── <SolutionName>.API             # Swagger, controllers, health checks, middleware
├── tests
│   ├── <SolutionName>.UnitTests       # Domain and application unit tests
│   └── <SolutionName>.IntegrationTests# API endpoint integration tests
├── docker                             # Dockerfile and compose configurations
└── .github                            # CI/CD GitHub Actions workflow

Global CLI Tool Installation & Commands

Installation

Install the CLI tool globally via NuGet:

dotnet tool install -g CleanArchPro

Commands

1. Create a New Solution

Generate a new Clean Architecture solution preconfigured with MediatR, FluentValidation, EF Core, and Swagger:

cleanarchpro create MyProjectName --all

Options:

  • --docker : Include Dockerfile and docker-compose configurations.
  • --tests : Include xUnit unit and integration test projects.
  • --github-actions : Include GitHub Actions CI workflow template.
  • --azure-devops : Include Azure DevOps pipeline template.
  • --all : Include all options above.
2. Validate Architecture Boundaries

Scan the current solution's project references and C# files for architectural violations:

cleanarchpro validate
3. Run Architecture Doctor

Generate an architectural health score (out of 100) and receive actionable refactoring recommendations:

cleanarchpro doctor

Roslyn Analyzer Rule Reference

The analyzer package (CleanArchPro.Analyzers) actively enforces architectural boundaries during local builds and directly inside your IDE (Visual Studio, VS Code, Rider).

Rule ID Title Severity Description
CAP001 Domain Layer Must Not Reference API Layer Error Domain layer must have zero dependencies on presentation layer.
CAP002 Domain Layer Must Not Reference Infrastructure Error Core domain logic must remain independent of infrastructure implementations.
CAP003 Controllers Cannot Access DbContext Directly Warning Controllers must use Application abstractions (use cases, MediatR) instead of exposing database context directly.
CAP004 Application Layer Cannot Reference API Layer Error Application logic must not depend on presentation details.
CAP005 Prevent Circular Project Dependencies Error Detects circular references between layers in the dependency graph.
CAP006 Repositories Must Implement Interface Warning Repository classes in Infrastructure must implement a corresponding abstraction interface (e.g., IUserRepository).

Rule Examples & Code Fixes

CAP001: Domain Layer referencing API
  • Invalid Code:
    // Inside GiftCardSystem.Domain
    using GiftCardSystem.API.Controllers; // Diagnostic emitted
    
    namespace GiftCardSystem.Domain.Entities
    {
        public class GiftCard { }
    }
    
  • Code Fix: Automatic removal of the invalid using directive.

CAP003: Direct DbContext Usage in Controller
  • Invalid Code:
    // Inside GiftCardSystem.API
    public class UsersController : ControllerBase
    {
        private readonly AppDbContext _db; // Diagnostic: Controllers must use Application abstractions.
    
        public UsersController(AppDbContext db)
        {
            _db = db;
        }
    }
    
  • Code Fix (Refactor): Injects a use-case or user service representation (IUserService) and rewrites the constructor initialization automatically.
  • Fixed Code:
    public class UsersController : ControllerBase
    {
        private readonly IUserService _userService;
    
        public UsersController(IUserService userService)
        {
            _userService = userService;
        }
    }
    

CAP006: Repository Class missing Interface
  • Invalid Code:
    // Inside GiftCardSystem.Infrastructure
    namespace GiftCardSystem.Infrastructure.Repositories
    {
        public class UserRepository // Diagnostic: UserRepository should implement IUserRepository.
        {
            // DbContext operations...
        }
    }
    
  • Code Fix: Automatically declares inheritance for the interface:
    public class UserRepository : IUserRepository
    {
    }
    

Contributing

We welcome contributions to CleanArch Pro! Please follow these steps:

  1. Fork the repository.
  2. Create a feature branch: git checkout -b feature/amazing-feature.
  3. Ensure all tests compile and pass: dotnet test.
  4. Commit your changes and submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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
1.0.1 146 6/6/2026
1.0.0 119 6/6/2026

Initial release of CleanArch Pro CLI tool, analyzers, and code fixes.