{"slug":"clean-architecture-dotnet","title":"clean-architecture-dotnet","summary":"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.","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-11-29T00:42:28.901366Z","repo":{"url":"https://github.com/SebastienDegodez/skraft-plugin","stars":17,"forks":3,"license":"GPL-3.0","updatedAt":"2026-11-29T00:18:21Z"},"bodyHtml":"<hr>\n<h2>name: clean-architecture-dotnet\ndescription: 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.</h2>\n<h1>Clean Architecture — .NET / ASP.NET Core</h1>\n<p>The layer rules are those of <code>architecture-patterns</code>. This skill maps them onto .NET projects.</p>\n<h2>One project per layer</h2>\n<table>\n<thead>\n<tr>\n<th>Project</th>\n<th>Holds</th>\n<th>Only <code>&lt;ProjectReference&gt;</code> to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>&lt;Context&gt;.Domain</code></td>\n<td>aggregates, value objects, domain events</td>\n<td>nothing</td>\n</tr>\n<tr>\n<td><code>&lt;Context&gt;.Application</code></td>\n<td>use cases and the interfaces they call</td>\n<td><code>&lt;Context&gt;.Domain</code></td>\n</tr>\n<tr>\n<td><code>&lt;Context&gt;.Infrastructure</code></td>\n<td>implementations of those interfaces, DI registration (<code>AddInfrastructure()</code>)</td>\n<td><code>&lt;Context&gt;.Application</code></td>\n</tr>\n<tr>\n<td><code>&lt;Context&gt;.Api</code></td>\n<td>endpoints, <code>Program.cs</code></td>\n<td><code>&lt;Context&gt;.Infrastructure</code></td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>Inside each project, one folder per feature (<code>Application/Loans/BorrowBookUseCase.cs</code>, <code>Infrastructure/Loans/SqlLoanRepository.cs</code>), never a technical one (<code>Persistence</code>, <code>Repositories</code>, <code>Services</code>). The <code>DbContext</code> and <code>DependencyInjection.cs</code> stay at the project root. A feature uses no other feature's Application namespace; what two features use moves to a <code>Shared</code> folder.</li>\n<li>Use types reached transitively; never add a <code>&lt;ProjectReference&gt;</code> to reach them.</li>\n<li>EF Core, ASP.NET Core and <code>HttpClient</code> appear only in Infrastructure and Api. Domain uses nothing beyond the BCL.</li>\n<li>Tests live in the test projects <code>clean-architecture-testing</code> defines, never in a layer project.</li>\n<li><code>node \"&lt;skill&gt;/scripts/init-project.mjs\" &lt;Context&gt;</code>, run from the repository root, creates this layout (<code>&lt;skill&gt;</code> is this skill's folder).</li>\n</ul>\n<h2>Use cases</h2>\n<ul>\n<li>A use case is a <code>sealed</code> class in Application named <code>*UseCase</code>, never <code>*Service</code>. The endpoint injects it directly.</li>\n<li>A command method returns <code>Task</code>; the caller creates the new id and passes it in. A query returns a <code>*ViewModel</code> record built in Application (never a <code>*Dto</code>, never a domain object), or comes from a read-service interface in Application that Infrastructure implements.</li>\n<li>Application declares an interface only where it calls out (repository, read service, gateway, <code>ICurrentUser</code>). A repository interface sits in Domain when it persists an aggregate, in Application otherwise.</li>\n<li>Who may <em>read</em> a resource is checked in the use case. Who may <em>change</em> it is an aggregate rule: the mutation method takes the caller's id and throws.</li>\n<li>A use case orchestrates. Every other <code>if</code>/<code>throw</code> that protects state belongs in a Domain method.</li>\n<li>No <code>ICommandBus</code> / <code>IQueryBus</code> 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.</li>\n<li>A domain event is raised by the aggregate and dispatched by the use case after the save, never from Domain or a repository.</li>\n</ul>\n<h2>Domain</h2>\n<ul>\n<li>An aggregate is a <code>sealed</code> class created through a static factory over a <code>private</code> constructor, and identified by a typed id record (<code>OrderId</code>), never a raw <code>Guid</code>.</li>\n<li>Data with no rule to protect stays a plain record: no aggregate base class, no domain events.</li>\n</ul>\n<h2>Guard</h2>\n<p>The project graph and a framework-free core are enforced by NetArchTest: <code>templates/IntegrationTests/ArchitectureTests.cs</code> and <code>references/netarchtest-rules.md</code>, placed as <code>clean-architecture-testing</code> says.</p>\n<h2>References</h2>\n<ul>\n<li><code>references/patterns.md</code>: code for a plain use case, CQRS with DDD and domain events, plus the red flags and common mistakes.</li>\n<li><code>references/interface-placement.md</code>: repository, read-service, authorization and <code>ICurrentUser</code> placement, with read-policy and cancel-invariant examples.</li>\n<li><code>references/ddd.md</code>: aggregates, factories, value objects, domain events.</li>\n<li><code>references/cqrs-patterns.md</code> and <code>references/convention-based-di.md</code>: the bus, handlers and DI registration, once a bus is justified.</li>\n<li><code>references/layer-responsibilities.md</code>, <code>references/architecture-layers.md</code>, <code>references/project-structure.md</code>: full rules per layer and the folder layout.</li>\n</ul>\n","files":[{"path":"references/architecture-layers.md","sizeBytes":1642,"isText":true},{"path":"references/convention-based-di.md","sizeBytes":10223,"isText":true},{"path":"references/cqrs-patterns.md","sizeBytes":3243,"isText":true},{"path":"references/ddd.md","sizeBytes":10632,"isText":true},{"path":"references/interface-placement.md","sizeBytes":9231,"isText":true},{"path":"references/layer-responsibilities.md","sizeBytes":14733,"isText":true},{"path":"references/netarchtest-rules.md","sizeBytes":10553,"isText":true},{"path":"references/patterns.md","sizeBytes":16037,"isText":true},{"path":"references/project-structure.md","sizeBytes":1905,"isText":true},{"path":"scripts/init-project.mjs","sizeBytes":5748,"isText":false},{"path":"SKILL.md","sizeBytes":4061,"isText":true},{"path":"templates/Api/IApiMarker.cs","sizeBytes":179,"isText":false},{"path":"templates/Application/IApplicationMarker.cs","sizeBytes":211,"isText":false},{"path":"templates/Application/Shared/ICommandBus.cs","sizeBytes":259,"isText":false},{"path":"templates/Application/Shared/ICommandHandler.cs","sizeBytes":310,"isText":false},{"path":"templates/Application/Shared/IQueryBus.cs","sizeBytes":265,"isText":false},{"path":"templates/Application/Shared/IQueryHandler.cs","sizeBytes":264,"isText":false},{"path":"templates/Domain/IDomainMarker.cs","sizeBytes":191,"isText":false},{"path":"templates/Infrastructure/CQRS/CommandBus.cs","sizeBytes":780,"isText":false},{"path":"templates/Infrastructure/CQRS/QueryBus.cs","sizeBytes":789,"isText":false},{"path":"templates/Infrastructure/DependencyInjection.cs","sizeBytes":1778,"isText":false},{"path":"templates/Infrastructure/IInfrastructureMarker.cs","sizeBytes":223,"isText":false},{"path":"templates/IntegrationTests/ArchitectureTests.cs","sizeBytes":4571,"isText":false}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-11-29T00:43:39.430046Z","sha256":"1F8D629ACEB645FE6AB603FFA165F8DC8AD93BF67C369ACE134D3FEDEAD2BC25","sizeBytes":35883},"review":null,"source":{"repositoryUrl":"https://github.com/SebastienDegodez/skraft-plugin","path":"plugins/skraft-framework/skills/clean-architecture-dotnet","license":"GPL-3.0","commit":"c6117c6236a25490bf1916b131866069740c9b22","subtreeSha":"3159C89450813FCF6226578397AD5090932E3F48C4BEC81CDE194FA462087049","lastSyncedAt":"2026-11-29T00:42:27.348488Z"},"reviewedAt":"2026-11-29T00:46:36.105119Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/SebastienDegodez/skraft-plugin/tree/main/plugins/skraft-framework/skills/clean-architecture-dotnet"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install sebastiendegodez-skraft-plugin@llmmart"},{"target":"git","command":"git clone https://github.com/SebastienDegodez/skraft-plugin.git"}]}