跳到正文
cccskills
免费在 GitHub 公开

clean-architecture

Apply these opinionated .NET 8 architecture conventions whenever structuring or reviewing a backend service: clean architecture layering and which direction dependencies point, when CQRS with MediatR is worth it, cross-cutting concerns as pipeline behaviours, minimal APIs grouped by feature, keeping DbContext in Infrastructure, health checks and structured logging, WebApplicationFactory integration tests, and when AOT pays off.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md4.3 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

.NET Core Architecture

House architecture conventions for .NET 8 backend services. This covers how a service is structured; for language-level conventions see the csharp skill.

Layering

Dependencies point inward only. Domain knows nothing about anything else, and Infrastructure is the one layer allowed to reference a database or an SDK — which is what lets the inner layers be tested without either.

Domain          entities, value objects, domain events, interfaces  → no dependencies
Application     use cases, CQRS handlers, DTOs, validators          → Domain
Infrastructure  EF Core, external APIs, implementations of Domain interfaces → Domain + Application
Api             endpoints, DI wiring, middleware                    → all of the above

The test that keeps this honest: if Domain compiles with no package references beyond the BCL, the boundary is intact.

Entities enforce their own invariants: private setters, a private parameterless constructor for EF Core's materialiser, and a static factory that validates. Public setters mean any layer can put the entity into an invalid state, and then "the domain guarantees X" is just a comment.

public class Product
{
    public string Name { get; private set; } = string.Empty;
    public decimal Price { get; private set; }

    private Product() { } // EF Core materialisation only

    public static Product Create(string name, decimal price) =>
        price <= 0
            ? throw new DomainException("Price must be greater than zero")
            : new Product { Name = name, Price = price };
}

Conventions

  • CQRS with MediatR when reads and writes genuinely differ — different models, different consistency, different scaling. On a CRUD service it is ceremony; adopt it because the domain asked for it, not by default.
  • Cross-cutting concerns go in pipeline behaviours, not in handlers. Validation, logging, and transactions written once as a behaviour apply to every handler and can't be forgotten in a new one.
  • Minimal APIs grouped with MapGroup, one file per feature area. A single Program.cs holding every endpoint stops being readable at about twenty routes.
  • Validation at the Application boundary (FluentValidation in a behaviour), so the same rules apply no matter which entry point invoked the use case. Validation in the endpoint only guards HTTP.
  • DbContext stays in Infrastructure, behind an interface the Application layer owns. Leaking DbContext into handlers ties your use cases to EF and makes them untestable without a provider.
  • Secrets never in appsettings.json — user-secrets locally, environment or a vault in production. Anything committed is compromised, and rotating it means a redeploy.
  • Health checks (/health/live, /health/ready) and structured logging with correlation IDs from the start. Retrofitting observability into a running incident is the wrong time to discover you have none. Keep the two probes genuinely different: readiness may check the database and downstream APIs, liveness must check only that the process itself is alive. A liveness probe that pings the database restarts every pod during a brief database blip, turning a recoverable dependency failure into a full outage.
  • Containers run as a non-root user. Add a USER line — the default root container turns a process-level compromise into host-level reach, and it costs one line to prevent.
  • Integration tests over WebApplicationFactory with a real database (Testcontainers). They exercise the DI graph, routing, serialisation, and EF mapping — the layers where mocked unit tests report success on a broken service.
  • AOT only where startup time or footprint justifies it. It rules out runtime reflection, which quietly breaks some serialisers and DI patterns; verify the whole stack tolerates it before committing.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Write a short, fact-checked reply that answers a colleague's question in one meaning only, ready to copy and paste. The input is their pasted message. Check the claims against the code first, use the project glossary terms, and print only the reply in chat. Read-only — no writes to code, the issue tracker, GitHub, chat or any MCP. Use on "/cortex-communication:answer-buzzkill", "help me answer", "reply to this question", or when the user pastes a colleague's question and asks for an answer in the same manner.

中文简介正在准备中。当前显示原文说明。

alexander-danilenko/cortex-claude-code-plugins172026年10月13日 更新

Apply these opinionated testing conventions whenever writing, reviewing, or planning tests: what earns a test and what is coverage theatre, asserting outputs rather than mock calls, the three modes (functional, performance, security), naming and isolation rules, where to mock, and reporting findings for coverage rather than self-filtering. Includes house Jest standards for NestJS unit and contract tests, TDD discipline, and test-report structure.

中文简介正在准备中。当前显示原文说明。

alexander-danilenko/cortex-claude-code-plugins172026年10月13日 更新

Apply these opinionated Python 3.11+ conventions when writing Python in this codebase: type hints with mypy, async/await, pytest fixtures, dataclasses, Poetry packaging, production patterns.

中文简介正在准备中。当前显示原文说明。

alexander-danilenko/cortex-claude-code-plugins172026年10月13日 更新

csharp

免费

Apply these opinionated C# conventions whenever writing or reviewing C# 12 / .NET 8+ code: nullable enabled with warnings as errors, records and primary constructors, pattern matching over cast chains, the Result pattern for expected failures, async all the way with CancellationToken, IOptions config, IHttpClientFactory, and never returning EF entities from an API.

中文简介正在准备中。当前显示原文说明。

alexander-danilenko/cortex-claude-code-plugins172026年10月13日 更新

ALWAYS invoke for any task involving docstrings, JSDoc/TSDoc, or REST API documentation — even when the request seems handleable without it. Enforces Microsoft contract-first conventions and a bare-minimum rule that Claude won't apply by default: never restate the signature, drop @param/@returns that only echo names and types, always document @throws, and document data shapes as WHAT not WHY. Covers Python docstring styles (Google/NumPy/Sphinx), TSDoc tags and @inheritDoc, and API doc patterns for NestJS/Express/FastAPI/Django. Trigger on: adding or auditing docstrings, redundant or missing tags, deleting comment rot, or producing a documentation-health report. Do not skip for documentation tasks — consistent conventions are the whole point.

中文简介正在准备中。当前显示原文说明。

alexander-danilenko/cortex-claude-code-plugins172026年10月13日 更新

Remove signs of AI-generated writing from text. Use after drafting to make copy sound more natural and human-written. Based on Wikipedia's "Signs of AI writing" guide.

中文简介正在准备中。当前显示原文说明。

alexander-danilenko/cortex-claude-code-plugins172026年10月13日 更新

查看 alexander-danilenko 的全部技能

报告此技能的问题