clean-architecture-layers
Skill1 starsChanged 7 days agoMITView on GitHub
The dependency rule and what belongs in each layer (Application, Infrastructure, Presentation) of this Clean Architecture solution. Use when deciding where new code goes, adding a project reference, or reviewing a change that crosses layers.
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-a-use-caseSkill
- api-conventionsSkill
- branches-and-pull-requestsSkill
- cancellationSkill
- ci-for-your-solutionSkill
- ci-pipelineSkill
- configuration-and-environmentsSkill
- coverageSkill
- csharp-house-styleSkill
- data-access-ef-coreSkill
- database-migrationsSkill
- docker-and-composeSkill
- docs-and-voiceSkill
- errors-and-exceptionsSkill
- expose-a-use-caseSkill
- family-syncSkill
- health-checksSkill
- integration-testsSkill
- json-serializationSkill
- mapping-with-mapperlySkill
- mcp-inspectorSkill
- mediatorSkill
- optional-token-authSkill
- packages-and-dependenciesSkill
- pagingSkill
- presentation-integration-testsSkill
- releasesSkill
- sample-dataSkill
- security-findingsSkill
- serilogSkill
- telemetrySkill
- template-authoringSkill
- test-designSkill
- time-providerSkill
- unit-testsSkill
- validationSkill
- writing-a-skillSkill
- xml-docs-and-openapiSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 49
Put validation in an endpoint.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Clean architecture layers
The rule
Three projects, and dependencies only point inwards. Application knows nothing about the database, HTTP or any framework. Infrastructure implements the interfaces Application declares. Presentation wires everything together and turns use cases into endpoints.
Presentation ──► Application ◄── Infrastructure
└───────────────────────────────►┘ (startup wiring only)| Layer | Holds | Never holds |
src/Application | Commands, queries, handlers, validators, entities (records), repository interfaces, paging, exceptions, pipeline behaviours | EF Core, ASP.NET Core, Serilog, anything about HTTP or SQL |
src/Infrastructure | DbContext, database models, EF configuration, migrations, the repository, Mapperly mappers, sample data, AddInfrastructure() | Business rules, validation, HTTP types |
src/Presentation | Endpoints, tools, resolvers or function handlers, request and response models, exception-to-response mapping, API documentation, authentication, health check endpoints, startup | Database access, business rules |
Infrastructure keeps its types internal. The only public surface is AddInfrastructure(), AddInfrastructureHealthChecks() and InitialiseInfrastructure() in src/Infrastructure/DependencyInjection.cs.
Steps
- Is it a rule about the domain (what's valid, what exists, what a use case does)? It goes in Application.
- Is it about how data is stored or fetched? Infrastructure, behind an interface in Application (
IMoviesRepository,IAuthorsRepository,IReviewsRepository). - Is it about how a caller talks to us (routes, status codes, JSON, tokens)? Presentation.
- Need a new dependency between projects? Only Presentation → Application, Presentation → Infrastructure and Infrastructure → Application are allowed. Tests reference the layer they test.
Example
The handler depends on an interface, not on EF Core:
// src/Application/Movies/Queries/GetMovies/GetMoviesHandler.cs
public class GetMoviesHandler(IMoviesRepository repository) : IRequestHandler<GetMoviesQuery, Page<MovieSummary>>EntityFrameworkMovieReviewsRepository in Infrastructure implements all three repository interfaces, and AddInfrastructure() registers it for each.
Don't
- Reference
Microsoft.EntityFrameworkCoreorMicrosoft.AspNetCore.*from Application. - Return database models (
Infrastructure/.../Models) from the repository. Map them to Application entities first (mapping-with-mapperly). - Put validation in an endpoint. It belongs in an Application validator (
validation). - Make an Infrastructure type
publicso Presentation can use it. Add what's needed toDependencyInjection.csinstead.
Check
dotnet build
grep -rn "EntityFrameworkCore\|AspNetCore" src/Application --include=*.cs --include=*.csproj # expect nothingDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

