Claude Cursor GitHub Copilot Skill

clean-architecture-dotnet

Use when laying out or extending a .NET / ASP.NET Core solution — which project a class belongs in, which project may reference which, and how an endpoint reaches a use case.

LLM Mart · 0 points · 0 views 0 listing impressions 0 install-command copies
Download sebastiendegodez-skraft-plugin-plugins_skraft-framework_skills_clean-architecture-dotnet-c6117c6.zip · 35 KB

Install

skills CLI npx skills add https://github.com/SebastienDegodez/skraft-plugin/tree/main/plugins/skraft-framework/skills/clean-architecture-dotnet
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install sebastiendegodez-skraft-plugin@llmmart
Git git clone https://github.com/SebastienDegodez/skraft-plugin.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole sebastiendegodez/skraft-plugin collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

Clean Architecture — .NET / ASP.NET Core

The layer rules are those of architecture-patterns. This skill maps them onto .NET projects.

One project per layer

Project Holds Only <ProjectReference> to
<Context>.Domain aggregates, value objects, domain events nothing
<Context>.Application use cases and the interfaces they call <Context>.Domain
<Context>.Infrastructure implementations of those interfaces, DI registration (AddInfrastructure()) <Context>.Application
<Context>.Api endpoints, Program.cs <Context>.Infrastructure
  • Inside each project, one folder per feature (Application/Loans/BorrowBookUseCase.cs, Infrastructure/Loans/SqlLoanRepository.cs), never a technical one (Persistence, Repositories, Services). The DbContext and DependencyInjection.cs stay at the project root. A feature uses no other feature's Application namespace; what two features use moves to a Shared folder.
  • Use types reached transitively; never add a <ProjectReference> to reach them.
  • EF Core, ASP.NET Core and HttpClient appear only in Infrastructure and Api. Domain uses nothing beyond the BCL.
  • Tests live in the test projects clean-architecture-testing defines, never in a layer project.
  • node "<skill>/scripts/init-project.mjs" <Context>, run from the repository root, creates this layout (<skill> is this skill's folder).

Use cases

  • A use case is a sealed class in Application named *UseCase, never *Service. The endpoint injects it directly.
  • A command method returns Task; the caller creates the new id and passes it in. A query returns a *ViewModel record built in Application (never a *Dto, never a domain object), or comes from a read-service interface in Application that Infrastructure implements.
  • Application declares an interface only where it calls out (repository, read service, gateway, ICurrentUser). A repository interface sits in Domain when it persists an aggregate, in Application otherwise.
  • Who may read a resource is checked in the use case. Who may change it is an aggregate rule: the mutation method takes the caller's id and throws.
  • A use case orchestrates. Every other if/throw that protects state belongs in a Domain method.
  • No ICommandBus / IQueryBus unless all three hold: a pipeline every command or query needs (validation, logging), more than three use cases, and read and write models that differ. With a bus, endpoints go through it and never inject a handler.
  • A domain event is raised by the aggregate and dispatched by the use case after the save, never from Domain or a repository.

Domain

  • An aggregate is a sealed class created through a static factory over a private constructor, and identified by a typed id record (OrderId), never a raw Guid.
  • Data with no rule to protect stays a plain record: no aggregate base class, no domain events.

Guard

The project graph and a framework-free core are enforced by NetArchTest: templates/IntegrationTests/ArchitectureTests.cs and references/netarchtest-rules.md, placed as clean-architecture-testing says.

References

  • references/patterns.md: code for a plain use case, CQRS with DDD and domain events, plus the red flags and common mistakes.
  • references/interface-placement.md: repository, read-service, authorization and ICurrentUser placement, with read-policy and cancel-invariant examples.
  • references/ddd.md: aggregates, factories, value objects, domain events.
  • references/cqrs-patterns.md and references/convention-based-di.md: the bus, handlers and DI registration, once a bus is justified.
  • references/layer-responsibilities.md, references/architecture-layers.md, references/project-structure.md: full rules per layer and the folder layout.
Files (skraft-plugin)
  • references
    • architecture-layers.md 1.6 KB
      Loading…
    • convention-based-di.md 10 KB
      Loading…
    • cqrs-patterns.md 3.2 KB
      Loading…
    • ddd.md 10.4 KB
      Loading…
    • interface-placement.md 9 KB
      Loading…
    • layer-responsibilities.md 14.4 KB
      Loading…
    • netarchtest-rules.md 10.3 KB
      Loading…
    • patterns.md 15.7 KB
      Loading…
    • project-structure.md 1.9 KB
      Loading…
  • scripts
    • init-project.mjs 5.6 KB · in bundle
  • templates
    • Api
      • IApiMarker.cs 179 B · in bundle
    • Application
      • Shared
        • ICommandBus.cs 259 B · in bundle
        • ICommandHandler.cs 310 B · in bundle
        • IQueryBus.cs 265 B · in bundle
        • IQueryHandler.cs 264 B · in bundle
      • IApplicationMarker.cs 211 B · in bundle
    • Domain
      • IDomainMarker.cs 191 B · in bundle
    • Infrastructure
      • CQRS
        • CommandBus.cs 780 B · in bundle
        • QueryBus.cs 789 B · in bundle
      • DependencyInjection.cs 1.7 KB · in bundle
      • IInfrastructureMarker.cs 223 B · in bundle
    • IntegrationTests
      • ArchitectureTests.cs 4.5 KB · in bundle
  • SKILL.md 4 KB
    ---
    name: clean-architecture-dotnet
    description: Use when laying out or extending a .NET / ASP.NET Core solution — which project a class belongs in, which project may reference which, and how an endpoint reaches a use case.
    ---
    
    # Clean Architecture — .NET / ASP.NET Core
    
    The layer rules are those of `architecture-patterns`. This skill maps them onto .NET projects.
    
    ## One project per layer
    
    | Project | Holds | Only `<ProjectReference>` to |
    |---|---|---|
    | `<Context>.Domain` | aggregates, value objects, domain events | nothing |
    | `<Context>.Application` | use cases and the interfaces they call | `<Context>.Domain` |
    | `<Context>.Infrastructure` | implementations of those interfaces, DI registration (`AddInfrastructure()`) | `<Context>.Application` |
    | `<Context>.Api` | endpoints, `Program.cs` | `<Context>.Infrastructure` |
    
    - Inside each project, one folder per feature (`Application/Loans/BorrowBookUseCase.cs`, `Infrastructure/Loans/SqlLoanRepository.cs`), never a technical one (`Persistence`, `Repositories`, `Services`). The `DbContext` and `DependencyInjection.cs` stay at the project root. A feature uses no other feature's Application namespace; what two features use moves to a `Shared` folder.
    - Use types reached transitively; never add a `<ProjectReference>` to reach them.
    - EF Core, ASP.NET Core and `HttpClient` appear only in Infrastructure and Api. Domain uses nothing beyond the BCL.
    - Tests live in the test projects `clean-architecture-testing` defines, never in a layer project.
    - `node "<skill>/scripts/init-project.mjs" <Context>`, run from the repository root, creates this layout (`<skill>` is this skill's folder).
    
    ## Use cases
    
    - A use case is a `sealed` class in Application named `*UseCase`, never `*Service`. The endpoint injects it directly.
    - A command method returns `Task`; the caller creates the new id and passes it in. A query returns a `*ViewModel` record built in Application (never a `*Dto`, never a domain object), or comes from a read-service interface in Application that Infrastructure implements.
    - Application declares an interface only where it calls out (repository, read service, gateway, `ICurrentUser`). A repository interface sits in Domain when it persists an aggregate, in Application otherwise.
    - Who may *read* a resource is checked in the use case. Who may *change* it is an aggregate rule: the mutation method takes the caller's id and throws.
    - A use case orchestrates. Every other `if`/`throw` that protects state belongs in a Domain method.
    - No `ICommandBus` / `IQueryBus` unless all three hold: a pipeline every command or query needs (validation, logging), more than three use cases, and read and write models that differ. With a bus, endpoints go through it and never inject a handler.
    - A domain event is raised by the aggregate and dispatched by the use case after the save, never from Domain or a repository.
    
    ## Domain
    
    - An aggregate is a `sealed` class created through a static factory over a `private` constructor, and identified by a typed id record (`OrderId`), never a raw `Guid`.
    - Data with no rule to protect stays a plain record: no aggregate base class, no domain events.
    
    ## Guard
    
    The project graph and a framework-free core are enforced by NetArchTest: `templates/IntegrationTests/ArchitectureTests.cs` and `references/netarchtest-rules.md`, placed as `clean-architecture-testing` says.
    
    ## References
    
    - `references/patterns.md`: code for a plain use case, CQRS with DDD and domain events, plus the red flags and common mistakes.
    - `references/interface-placement.md`: repository, read-service, authorization and `ICurrentUser` placement, with read-policy and cancel-invariant examples.
    - `references/ddd.md`: aggregates, factories, value objects, domain events.
    - `references/cqrs-patterns.md` and `references/convention-based-di.md`: the bus, handlers and DI registration, once a bus is justified.
    - `references/layer-responsibilities.md`, `references/architecture-layers.md`, `references/project-structure.md`: full rules per layer and the folder layout.
    

Comments (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.