skills/dotnet-clean-architecture/SKILL.md
Scaffolds and extends .NET 8 Minimal API BFF modules using Clean Architecture (Application/Core/Infrastructure), Hexagonal port/adapter boundaries, and reflection-based module isolation. Use when creating new .NET modules, adding endpoints/use-cases with infrastructure integration, or refactoring toward ports/adapters and module isolation.
npx skillsauth add fmflurry/settings-opencode dotnet-clean-architectureInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
api/
├── Module/
│ ├── IModule.cs # Module contract
│ ├── ModuleExtensions.cs # Reflection-based auto-discovery
│ ├── <ModuleName>/
│ │ ├── <ModuleName>Module.cs # DI entrypoint (implements IModule)
│ │ ├── Application/ # Driving side (HTTP)
│ │ │ ├── Endpoint/ # MinimalApi.Endpoint implementations
│ │ │ └── Validator/ # FluentValidation rules (optional)
│ │ ├── Core/ # Domain hexagon (pure logic, zero infra deps)
│ │ │ ├── <UseCase>.cs # Use case implementation
│ │ │ ├── Exception/ # Module-specific domain exceptions
│ │ │ ├── Model/ # Domain models
│ │ │ │ └── Endpoint/ # Request/Response DTOs
│ │ │ └── Ports/
│ │ │ ├── Incoming/ # What domain exposes (use case interfaces)
│ │ │ └── Outgoing/ # What domain needs (infra abstractions)
│ │ └── Infrastructure/ # Driven side (DB, external services)
│ │ ├── Adapter/ # Implements outgoing ports
│ │ └── Mapping/ # AutoMapper profiles
├── Core/ # Shared kernel
│ ├── Data/
│ │ ├── Entities/ # EF Core entities
│ │ └── Repositories/ # Repository interfaces + implementations
│ ├── Endpoint/ # Base request/response (CorrelationId)
│ └── Interface/ # Shared interfaces
├── Infrastructure/ # Cross-cutting infrastructure
│ ├── Context/ # DbContext + EF configurations
│ ├── Identity/ # Auth middleware, JWT, passwords
│ └── ExceptionHandler.cs # Global ProblemDetails handler
├── Shared/
│ └── Exceptions/ # Domain exception hierarchy
├── Constants/ # Auth, Roles, Policies constants
└── Program.cs # Composition root
tests/
├── narrow/ # Unit tests (mocked ports)
│ └── <ModuleName>/
└── wide/ # Integration tests (WebApplicationFactory)
└── <ModuleName>/
Endpoint --> [Incoming Port] --> Use Case --> [Outgoing Port] <-- Adapter --> Repository/EF
| ^ ^ |
Application Core Core Infrastructure
// api/Module/IModule.cs
public interface IModule
{
IServiceCollection RegisterModule(IServiceCollection services);
}
Modules are auto-discovered via reflection in ModuleExtensions.cs. Constraints: parameterless constructor, same assembly as IModule.
public class BaseMessage { public Guid CorrelationId { get; init; } = Guid.NewGuid(); }
public class BaseRequest(Guid correlationId) : BaseMessage;
public class BaseResponse(Guid correlationId) : BaseMessage;
All domain exceptions extend ProblemDetailsException. The global ExceptionHandler converts them to RFC 7807 ProblemDetails responses (400 for domain, 500 for unexpected).
public class ProblemDetailsException(string detail) : Exception(detail);
public class <Name>Exception(string detail)
: ProblemDetailsException($"<User-friendly message>: {detail}");
Follow these steps in order. For full templates with code: See implementation-playbook.md.
<ModuleName>Module.cs implementing IModule)Core/Model/Endpoint/Core/Ports/Incoming/I<VerbNoun>.csCore/Ports/Outgoing/I<VerbNoun>Port.csCore/<VerbNoun>.cs — pure business logicInfrastructure/Adapter/<VerbNoun>Adapter.csInfrastructure/Mapping/<VerbNoun>Profile.csApplication/Validator/<VerbNoun>Validator.csApplication/Endpoint/<VerbNoun>Endpoint.cs<ModuleName>Module.csFor full testing patterns: See testing-patterns.md.
| Test Type | Scope | Approach | |-----------|-------|----------| | Narrow (unit) | Use case logic | Mock outgoing ports with NSubstitute | | Wide (integration) | Full HTTP pipeline | WebApplicationFactory + service overrides |
Target 80%+ coverage.
| Artifact | Pattern | Example |
|----------|---------|---------|
| Module class | <ModuleName>Module | UserModule |
| Incoming port | I<VerbNoun> | IRegisterUser |
| Outgoing port | I<VerbNoun>Port | IRegisterUserPort |
| Use case | <VerbNoun> | RegisterUser |
| Adapter | <VerbNoun>Adapter | RegisterUserAdapter |
| Endpoint | <VerbNoun>Endpoint | RegisterUserEndpoint |
| Validator | <VerbNoun>Validator | RegisterUserValidator |
| Mapper profile | <VerbNoun>Profile | RegisterUserProfile |
| Request DTO | <VerbNoun>Request | RegisterUserRequest |
| Response DTO | <VerbNoun>Response | RegisterUserResponse |
| Domain exception | <Noun>Exception | UserAlreadyExistsException |
| Narrow test class | <VerbNoun>Should | RegisterUserShould |
| Wide test class | <VerbNoun>EndpointShould | RegisterUserEndpointShould |
DiscoverModules() if modules move to other assemblies.Module/<ModuleName>/Core/Model/Endpoint/Core/Ports/Incoming/I<VerbNoun>.csCore/Ports/Outgoing/I<VerbNoun>Port.csCore/<VerbNoun>.csInfrastructure/Adapter/<VerbNoun>Adapter.csInfrastructure/Mapping/<VerbNoun>Profile.csApplication/Validator/<VerbNoun>Validator.csApplication/Endpoint/<VerbNoun>Endpoint.cs<ModuleName>Module.csdevelopment
Scaffolds and extends Angular 18+ standalone features using Clean Architecture with DDD layering (presentation/application/domain/infrastructure), custom signal-based stores, facade pattern, and ports/adapters dependency inversion. Use when creating new Angular features/domains, adding use cases/facades/stores/ports/adapters, refactoring legacy NgModule/NgRx code toward clean architecture, or working with cross-domain communication via context registry.
development
Pre-merge code review for Angular + TypeScript pull requests. Diffs current branch against a target branch, applies Angular-specific checklists (signals, RxJS, clean architecture, flurryx, TS strict), runs lint + tsc, and emits a tiered report (verbose for juniors, terse for seniors). Auto-loads project AGENTS.md rules. Use when user runs /cop-review, says "pre-merge review", "review before merging", "check my PR against <branch>", or invokes the merge-cop agent.
testing
Use this skill for any git work such as creating branches, staging changes, writing commit messages, pushing branches, or preparing pull requests. Delegates git execution to the git-specialist agent.
development
Signal-first reactive state management for Angular. Bridge RxJS streams into cache-aware stores, keyed resources, mirrored state, and replayable history. Use when generating or modifying Angular code that uses flurryx for state management, or when scaffolding new feature modules that follow the flurryx facade pattern.