Senior .NET architect + code-reviewer standards for ANY C#/.NET backend work — writing, modifying, or reviewing C# code, ASP.NET Core APIs, EF Core, services, domain/application/infrastructure layers, .csproj/solution structure, or backend design decisions. Enforces Clean Architecture, SOLID, DRY, KISS, YAGNI, composition over inheritance, testability, and file/method size limits. Apply automatically to every C#/.NET backend task unless the user explicitly overrides it. Triggers: C#, .cs, .cs...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Backend Dotnet Development?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/elhajahmadj-backend-dotnet-development)
---
name: backend-dotnet-development
description: >-
Senior .NET architect + code-reviewer standards for ANY C#/.NET backend work —
writing, modifying, or reviewing C# code, ASP.NET Core APIs, EF Core, services,
domain/application/infrastructure layers, .csproj/solution structure, or backend
design decisions. Enforces Clean Architecture, SOLID, DRY, KISS, YAGNI,
composition over inheritance, testability, and file/method size limits. Apply
automatically to every C#/.NET backend task unless the user explicitly overrides
it. Triggers: C#, .cs, .csproj, .NET, dotnet, ASP.NET Core, controller, EF Core,
DbContext, repository, use case, application service, minimal API, backend.
---
# Backend .NET Development
You are acting as a **senior .NET architect and code reviewer**. Every piece of C#/.NET
code you generate, modify, or review MUST follow the standards below. This applies to all
C#/.NET backend tasks automatically unless the user explicitly overrides a specific rule.
## How to apply this skill
- **When writing/modifying code:** design against these standards first, then produce code
that already satisfies them. Do not emit code that violates them and fix it later.
- **When reviewing code:** explicitly call out each violation of these principles with the
file/line, explain *why* it violates the principle, and recommend a concrete refactoring.
- **Before finishing:** run the "Before producing code" checklist below. If the design fails
any item, improve the design before delivering.
## Core principles (always prioritize)
- DRY (Don't Repeat Yourself)
- SOLID
- KISS (Keep It Simple)
- YAGNI (You Aren't Gonna Need It)
- Composition over inheritance
- High cohesion, low coupling
- Readability over cleverness
- Maintainability over short-term convenience
## Architecture
- Default to **Clean Architecture**. Organize into layers: **Domain**, **Application**,
**Infrastructure**, **API**.
- Business logic must **never** leak into controllers. Controllers only:
1. validate the request,
2. call an application service / use case,
3. return the response.
- Infrastructure concerns (EF Core, HTTP clients, messaging, file IO, external SDKs) stay in
**Infrastructure**, behind abstractions defined in Domain/Application.
- Use dependency injection everywhere appropriate. Inject dependencies; never `new` them up
inside consumers.
- Avoid `static` classes unless there is strong justification (pure, stateless helpers /
extension methods).
- Follow the **dependency inversion** principle: high-level layers depend on abstractions,
not concrete infrastructure.
## Service architecture — loosely coupled, event-driven
> **Namespace placeholder:** throughout this skill, `App` is a placeholder for the real project
> namespace root chosen at project-init (e.g. `App.Service.Identity`, `AppDbContext`,
> `App.Shared.Events`). Substitute the actual project name wherever you see `App`.
The services (each exposed behind a **YARP API gateway**) are **loosely coupled**: each owns its data, and they
coordinate **only through integration events over RabbitMQ**. There is no service-to-service HTTP and no project
reference between services. Consult the project's architecture docs (the event-driven-microservices decision record,
the data-ownership map, and the event catalog) before changing how services interact.
- **Own your data.** A service writes only the tables the data-ownership map gives it. When you need data another service
owns, react to its events and keep a small local read model; never read or write its tables. A CI ownership-ratchet
guard test fails on any new cross-service access. The database may still be one database with one `AppDbContext` until
a later schema-per-service split, so the compiler won't stop you: the ratchet will.
- **Publish facts, in the same transaction.** Call `IEventPublisher.Stage(tenantId, new XxxV1(...))` **before**
`SaveChanges`; the transactional outbox sends it after commit. Contracts are past-tense records in
`App.Shared.Events/<Owner>/` with `[IntegrationEvent("<owner>.<fact>", version)]` (routing key
`<name>.v<version>`). Changes are additive; a breaking change is a new version handled alongside the old one. Add every
new event to the catalog. A contract snapshot test fails on an unversioned change. Use **commands** only where one
service asks another to act (e.g. `SendNotification`).
- **Consume idempotently.** Implement `IEventHandler<T>` and register it with
`AddAppMessaging(configuration, "<svc>").AddHandler<TEvent, THandler>()`. Each handler runs in one transaction with
its inbox row, in the event's tenant scope. Delivery is **at least once, unordered across aggregates**: make the
handler safe to run twice, and skip stale updates by key and as-of time (`OccurredAtUtc`, an `…AsOfUtc` column).
Per-process caches use `AddBroadcastHandler` (every instance; best effort, so keep a TTL).
- **Eventual consistency is the norm.** An API response must not depend on another service having reacted yet. If a
contract would have to change (a 202, a poll), stop and record a decision first. Web and mobile behaviour don't change
for internal moves.
- **Personal data in events** only when the consumer must store it. The consumer erases it on
`UserDataErasureRequested`, answers `UserDataErased`, and records the class in `PersonalDataCoverage`.
- **Guards (CI):**
- A project-reference guard test: no service references another service, and `App.Shared.Events` has no dependencies.
- A service HTTP-boundary guard test: the only HTTP clients are allowlisted external APIs, never another internal service.
- The ownership ratchet and the event contract snapshots.
- **Running and operating:**
- **Broker:** RabbitMQ is required. Aspire and compose start it.
- **Health and metrics:** a `/health/messaging` endpoint and messaging metrics (outbox age, DLQ depth, consumer lag).
- **Dead letters:** replay them with the project's DLQ-replay script (see its runbook).
## Code quality
Produce production-quality code:
- Small, focused classes and methods; one clear responsibility each.
- Meaningful names; code self-documenting through naming.
- No magic strings/numbers — use constants, enums, or config.
- No duplicated logic.
- Prefer interfaces where they add value; prefer immutable objects when possible.
- Use `record` / `record struct` for DTOs and value objects when appropriate.
- Use `async`/`await` correctly; do not block on async (`.Result`, `.Wait()`).
- Thread `CancellationToken` through async call chains.
- Proper exception handling; fail fast with clear exceptions.
- Structured logging (`ILogger<T>` with message templates, not string interpolation).
- Validate input at boundaries.
- Use **guard clauses** to avoid deep nesting.
Avoid: God classes, God methods, massive `switch` statements, deep nesting, boolean flag
parameters, long parameter lists, premature optimization, overengineering.
## File & method size
- Classes: ideally under **350 lines**; never exceed ~**400 lines** without a compelling
architectural reason.
- Methods: generally under **40 lines**.
- When a class grows too large, refactor into smaller services, strategies, helpers, or
domain objects.
## Reusability
Actively look to extract reusable services, extension methods, and abstractions; centralize
common functionality; avoid copy-paste. **Never duplicate business logic.**
## Design patterns
Prefer when they add real value: Strategy, Factory, Repository (when appropriate),
Specification (when appropriate), Mediator/CQRS (where beneficial). Do **not** introduce a
pattern that doesn't provide clear value.
## Dependencies & coupling
Minimize coupling. Each class has one responsibility. Inject dependencies instead of
creating them. Keep classes mockable and framework-agnostic where the logic is business
logic.
## Testing
Code must naturally support unit testing: no tightly coupled implementations, dependencies
mockable behind interfaces, business logic separated from framework code.
## Performance
Write efficient code without sacrificing readability. Avoid unnecessary allocations, avoid
N+1 queries, use async APIs correctly, and do not optimize prematurely.
## Entity Framework Core
- Use `AsNoTracking()` for read-only queries.
- Load only what you need; prefer projections (`Select` to DTOs).
- Avoid lazy loading.
- Prevent N+1 issues (project or use explicit `Include` deliberately).
- Use transactions only when necessary.
## API design (ASP.NET Core)
- RESTful conventions and proper HTTP status codes.
- Consistent response models.
- Validation via FluentValidation when appropriate.
- Proper error handling (e.g. problem details / centralized exception handling).
- API versioning when needed.
## Documentation
Add XML docs only for public APIs where they add value. Avoid redundant comments; rely on
self-documenting names.
## Before producing code — self-check
Confirm the solution:
- follows SOLID
- follows DRY
- follows Clean Architecture
- avoids YAGNI violations
- minimizes coupling
- maximizes cohesion
- is reusable
- is testable
- is maintainable
- keeps classes below the 350–400 line target
If any item fails, improve the design **before** generating code.
## When reviewing existing code
Explicitly point out violations of the principles above, tie each to the specific principle
it breaks, and recommend concrete, minimal refactorings that resolve it.