Skip to content
Back to skills

Clean Architecture Dotnet

ASecurity

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.

  • 8 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added October 7, 2026
ai-agentsgotestingapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 20 files and shows the line behind each finding

Scanned October 7, 2026

npx -y skills add SebastienDegodez/skraft-plugin --skill clean-architecture-dotnet --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Clean Architecture Dotnet?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Clean Architecture Dotnet
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sebastiendegodez-clean-architecture-dotnet/badge)](https://www.skillsdirectory.com/skills/sebastiendegodez-clean-architecture-dotnet)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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` |

- 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.
- `scripts/init-project.sh` (or `.ps1`) creates this layout.

## 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 in this skill

  • SKILL.md3.5 KB
  • references/architecture-layers.md1.6 KB
  • references/convention-based-di.md10 KB
  • references/cqrs-patterns.md3.2 KB
  • references/ddd.md10.4 KB
  • references/interface-placement.md9 KB
  • references/layer-responsibilities.md14.4 KB
  • references/netarchtest-rules.md10.3 KB
  • references/patterns.md15.7 KB
  • references/project-structure.md1.7 KB
  • scripts/init-project.ps114.5 KB
  • scripts/init-project.sh7.3 KB
  • templates/Api/IApiMarker.cs179 B
  • templates/Application/IApplicationMarker.cs211 B
  • templates/Application/Shared/ICommandBus.cs259 B
  • templates/Application/Shared/ICommandHandler.cs310 B
  • templates/Application/Shared/IQueryBus.cs265 B
  • templates/Application/Shared/IQueryHandler.cs264 B
  • templates/Domain/IDomainMarker.cs191 B
  • templates/Infrastructure/CQRS/CommandBus.cs780 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.