agentleFS
ardalisardalis/CleanArchitecture/.github/copilot-instructions.md

CleanArchitecture

Copilot instructions19k starsChanged 6 years agoMITView on GitHub

We split this copilot-instructions.md into the rules it gives an agent

18 rules. About 0 are common, 7 are distinctive, and 11 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 11

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use standard Microsoft naming conventions

    line 9
  2. Very specific:

    Use PascalCase for types and methods, camelCase for parameters and private fields

    line 10
  3. Very specific:

    Use I prefix for interfaces (e.g., IRepository)

    line 11
  4. Very specific:

    Use Async suffix for async methods (e.g., GetByIdAsync)

    line 12
  5. Very specific:

    Always use {} for blocks except single-line exits (e.g.

    line 14
  6. Very specific:

    Always keep single line blocks on one line (e.g., if (x) return y;)

    line 15
  7. Distinctive:

    Prefer primary constructors for required dependencies

    line 16
  8. Distinctive:

    Never use primary constructor parameters directly - always assign to private fields for clarity and testability

    line 17
  9. Distinctive:

    Never allow Core to depend on outer layers

    line 22
  10. Very specific:

    Use Endpoint<TRequest, TResponse> base class

    line 35
  11. Very specific:

    Use Value Objects (e.g., ContributorName.From())

    line 41
  12. Distinctive:

    Use Mediator (source generator) for command/query handling

    line 48
  13. Very specific:

    All package versions in Directory.Packages.props

    line 89
  14. Very specific:

    Use <PackageReference Include="..." /> without Version attribute

    line 90
  15. Very specific:

    Use Microsoft.AspNetCore.Mvc.Testing for API tests

    line 96
  16. Distinctive:

    Don't include hyphens in project names (template limitation)

    line 117
  17. Distinctive:

    Use absolute paths in EF migration commands

    line 120
  18. Very specific:

    Use the predefined tasks: build, publish, watch instead of manual dotnet commands when possible.

    line 124

≈ “Common” is an estimate: at least 1 in 5 of the 3,669 Copilot instructions 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

GitHub Copilot Instructions for Clean Architecture Template

Project Overview

This is a Clean Architecture template for .NET 9 that demonstrates Domain-Driven Design (DDD) patterns. It's a starter template, not a reference application - delete sample code once you understand the patterns.

Architecture & Project Structure

C# Conventions

  • Use standard Microsoft naming conventions
  • Use PascalCase for types and methods, camelCase for parameters and private fields
  • Use I prefix for interfaces (e.g., IRepository)
  • Use Async suffix for async methods (e.g., GetByIdAsync)
  • Prefix private fields with _ (e.g., _repository)
  • Always use {} for blocks except single-line exits (e.g. return, throw)
  • Always keep single line blocks on one line (e.g., if (x) return y;)
  • Prefer primary constructors for required dependencies
  • Never use primary constructor parameters directly - always assign to private fields for clarity and testability

Core Dependencies Flow

  • Core ← UseCases ← Infrastructure
  • Core ← UseCases ← Web
  • Never allow Core to depend on outer layers

Key Projects

  • Core: Domain entities, aggregates, value objects, specifications, interfaces
  • UseCases: Commands/queries (CQRS), Mediator handlers, application logic
  • Infrastructure: EF Core, external services, email, file access
  • Web: FastEndpoints API, REPR pattern, validation

Development Patterns

API Endpoints (FastEndpoints + REPR)

  • One endpoint per file: Create.cs, Update.cs, Delete.cs, GetById.cs
  • Separate request/response/validator files: Create.CreateRequest.cs, Create.CreateValidator.cs
  • Use Endpoint<TRequest, TResponse> base class
  • Example: src/Clean.Architecture.Web/Contributors/Create.cs

Domain Model (Core)

  • Entities use encapsulation - minimize public setters
  • Group related entities into Aggregates
  • Use Value Objects (e.g., ContributorName.From())
  • Domain Events for cross-aggregate communication
  • Repository interfaces defined in Core, implemented in Infrastructure

Use Cases (CQRS)

  • Commands for mutations, Queries for reads
  • Queries can bypass repository pattern for performance
  • Use Mediator (source generator) for command/query handling
  • Chain of responsibility for cross-cutting concerns (logging, validation)

Validation Strategy

  • API Level: FluentValidation on request DTOs (FastEndpoints integration)
  • Use Case Level: Validate commands/queries (defensive coding)
  • Domain Level: Business invariants throw exceptions, assume pre-validated input

Essential Commands

Build & Test

dotnet build Clean.Architecture.slnx
dotnet test Clean.Architecture.slnx

Entity Framework Migrations

# From Web project directory
dotnet ef migrations add MigrationName -c AppDbContext -p ../Clean.Architecture.Infrastructure/Clean.Architecture.Infrastructure.csproj -s Clean.Architecture.Web.csproj -o Data/Migrations

dotnet ef database update -c AppDbContext -p ../Clean.Architecture.Infrastructure/Clean.Architecture.Infrastructure.csproj -s Clean.Architecture.Web.csproj

Template Installation & Usage

dotnet new install Ardalis.CleanArchitecture.Template
dotnet new clean-arch -o Your.ProjectName

Key Dependencies & Patterns

Primary Libraries

  • FastEndpoints: API endpoints (replaced Controllers/Minimal APIs)
  • Mediator: Command/query handling in UseCases
  • EF Core: Data access (SQLite default, easily changed to SQL Server)
  • Ardalis.Specification: Repository query specifications
  • Ardalis.Result: Error handling pattern
  • Serilog: Structured logging

Central Package Management

  • All package versions in Directory.Packages.props
  • Use <PackageReference Include="..." /> without Version attribute

Test Organization

  • UnitTests: Core business logic, use cases
  • IntegrationTests: Database, infrastructure components
  • FunctionalTests: API endpoints (subcutaneous testing)
  • Use Microsoft.AspNetCore.Mvc.Testing for API tests

File Organization Conventions

Web Project Structure

Contributors/
  Create.cs                    # Endpoint
  Create.CreateRequest.cs      # Request DTO
  Create.CreateResponse.cs     # Response DTO  
  Create.CreateValidator.cs    # FluentValidation
  Update.cs, Delete.cs, etc.

Sample vs Template

  • /sample folder: Complete working example (NimblePros.SampleToDo)
  • /src folder: Clean template ready for your project
  • Study sample for patterns, use src for new projects

Common Gotchas

  • Don't include hyphens in project names (template limitation)
  • Replace Ardalis.SharedKernel with your own shared kernel
  • Database path in appsettings.json for SQLite
  • Use absolute paths in EF migration commands
  • FastEndpoints uses different validation approach than Controller-based APIs

VS Code Tasks

Use the predefined tasks: build, publish, watch instead of manual dotnet commands when possible.

Download now (ZIP)

Trending

Less talk lately.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 1 mentionMay 2026: 1 mentionJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 4 mentionsSep 2026: 0 mentionsOct 2026: 2 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the ardalis/CleanArchitecture repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about ardalis/CleanArchitecture

The biggest 5 of 84 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 84

Talked about on GitHub, YouTube, Stack Overflow, Bluesky and the web (84 times).

On GitHub · 44

39 more on GitHub

On YouTube · 18

13 more on YouTube

On Stack Overflow · 16

11 more on Stack Overflow
  • Where files are headingNew Copilot instructions files have more rules about branches and pull requests, and fewer about code style.

    Of the Copilot instructions files we read, the 2,297 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

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.