scaffold

scaffold

熱門

Architecture-aware scaffolding (/scaffold) for .NET 10: generates a Features/<VerbPhrase>/ slice (IEndpoint, IHandler, validator, integration tests) or a new module (implementation + Contracts, ModuleDbContext), matching existing conventions. Use for "scaffold", "add feature", "new endpoint", "add entity", "new module". Do NOT use for deciding architecture (use modular-slices or architecture-advisor) or project setup (use dotnet-init).

853星標
185分支
更新於 2026/11/28
要求的譯文尚未完成,目前顯示原始英文。
SKILL.md
唯讀
名稱
scaffold
描述

Architecture-aware scaffolding (/scaffold) for .NET 10: generates a Features/<VerbPhrase>/ slice (IEndpoint, IHandler, validator, integration tests) or a new module (implementation + Contracts, ModuleDbContext), matching existing conventions. Use for "scaffold", "add feature", "new endpoint", "add entity", "new module". Do NOT use for deciding architecture (use modular-slices or architecture-advisor) or project setup (use dotnet-init).

/scaffold: Architecture-Aware Feature Scaffolding

What

Generates a complete feature, or a new module, with every file it needs. It never generates half a feature: the endpoint, handler, request, validator, response, EF configuration and integration tests come as one unit, in modern C# 14 (primary constructors, collection expressions, records, sealed internal classes, TypedResults).

The default shape is modular slices (ADR-008, modular-slices skill). Other architectures are supported when the codebase already uses them. File placement maps and code templates live in references/architecture-patterns.md:

  • Modular slices (default): src/Modules/<Module>/<Module>/Features/<VerbPhrase>/, one class per file
  • Single-project VSA: the same slice files in Features/, without modules
  • Clean Architecture: files across Domain, Application, Infrastructure, Api
  • DDD: aggregate methods and domain events, with a thin handler

When

  • "Scaffold a [feature]", "create an endpoint for", "add a feature"
  • "Generate CRUD for", "add entity", "new module", "scaffold a module"
  • Starting a new feature after /spec has produced an approved plan
  • Customizing generation templates or defining what a complete slice includes

How

Step 1: Detect the architecture

  • src/Modules/<Name>/<Name> and <Name>.Contracts projects, IModule classes: modular slices
  • A single API project with Features/ folders and no modules: single-project VSA
  • Domain / Application / Infrastructure / Api projects: Clean Architecture (plus DDD if aggregates raise domain events)
  • An empty or new solution: modular slices, unless the architecture-advisor recommended something else

If it is ambiguous, ask rather than guess. Load the matching skill (modular-slices, or architecture-advisor for single-project VSA, Clean Architecture, DDD).

Step 2: Clarify scope

Confirm before generating (skip what the plan already answers):

  1. Operations needed, named as verb phrases (PlaceOrder, CancelOrder, ListOrders)
  2. Key fields and invariants for any new entity
  3. Which module owns it, or whether it needs a new module (decide by who owns the data)
  4. The permission each endpoint needs, and whether the data is tenant-owned
  5. Events other modules need from this change, if any

Step 3: Learn conventions

Use the instinct-system skill and Roslyn MCP tools (find_symbol, get_file_outline) on one existing feature folder:

  • Naming (*Endpoint, *Handler, *Request, *RequestValidator, *Response)
  • How handlers report errors (Problems.* codes, or an existing Result<T>)
  • Permission constants and test helper style ({Module}Api.cs)

Match what exists. Do not bring the default conventions into a codebase that uses different ones.

Step 4: Generate

A feature (default): in Features/<VerbPhrase>/ create

  • <VerbPhrase>Endpoint.cs: internal sealed, implements IEndpoint, relative route, .RequirePermission(...), .WithName(), .WithSummary(), injects the handler
  • <VerbPhrase>Handler.cs: internal sealed, implements IHandler, primary constructor with the module DbContext and TimeProvider, HandleAsync returning a Results<...> union
  • <VerbPhrase>Request.cs and <Noun>Response.cs: public sealed record (shared responses go in Features/Common/)
  • <VerbPhrase>RequestValidator.cs: internal sealed, rules with meaning
  • tests/<Module>.Tests/Features/<VerbPhrase>/<VerbPhrase>Tests.cs

A new module: create <Module> and <Module>.Contracts projects, <Module>Module : IModule, <Module>Permissions, <Module>DbContext : ModuleDbContext, add builder.AddModule<<Module>Module>() to the Api, Worker and Migrator hosts, add the projects to the .slnx, add a test project, and create the first migration.

If the Modularity building blocks are missing, scaffold them first from skills/modular-slices/references/building-blocks.md.

Step 5: Completeness checklist (mandatory)

Every scaffolded feature must satisfy all of these:

  • [ ] Endpoint: one IEndpoint per feature, discovered automatically; nothing added to Program.cs or the module class
  • [ ] Permission: .RequirePermission(...) or an explicit .AllowAnonymous() on every endpoint
  • [ ] Handler: internal sealed, implements IHandler, returns a TypedResults union; no mediator, no repository
  • [ ] Errors: Problems.NotFound() / Conflict(code, ...) / RuleBroken(code, ...) with <module>.<reason> codes; never bare strings
  • [ ] Validator: FluentValidation with real rules, run by the shared endpoint filter
  • [ ] Contracts: request/response records public; everything else internal; anything other modules need goes in <Module>.Contracts
  • [ ] Data: entities paired with IEntityTypeConfiguration<T>; reads use AsNoTracking() and projections; lists are paged (page size capped at 50)
  • [ ] Events: cross-module side effects published with db.Publish(evt, clock) before SaveChangesAsync
  • [ ] CancellationToken: on every async method and passed to every async call
  • [ ] Tests: success, permission refusal (403), validation refusal (400 validation-failed), each business rule code, and cross-tenant 404 for tenant-owned data

For single-project VSA the same list applies minus the Contracts and module items. For Clean Architecture or DDD codebases, follow their error and dispatch conventions (for example Result<T> with Mediator) but keep the endpoint, validation, data, cancellation and test items.

Step 6: Verify

dotnet build --no-restore
dotnet test --no-build --filter "FullyQualifiedName~{FeatureName}"
dotnet test --no-build --filter "FullyQualifiedName~Architecture"

If the build or tests fail, fix and re-run before presenting results. The architecture tests catch a public handler or a reference to another module's implementation.

Example

User: /scaffold cancelling an order

Claude: Detected architecture: modular slices (src/Modules/Orders). Feature goes in Orders.

Created files:
  src/Modules/Orders/Orders/Features/CancelOrder/CancelOrderEndpoint.cs
  src/Modules/Orders/Orders/Features/CancelOrder/CancelOrderHandler.cs
  src/Modules/Orders/Orders/Features/CancelOrder/CancelOrderRequest.cs
  src/Modules/Orders/Orders/Features/CancelOrder/CancelOrderRequestValidator.cs
  src/Modules/Orders/Orders.Contracts/OrderCancelled.cs        -- event for Billing
  tests/Orders.Tests/Features/CancelOrder/CancelOrderTests.cs

Handler returns Results<Ok<OrderResponse>, ProblemHttpResult>
Error codes: orders.cannot-cancel (409)
Tests: success, 403 without orders.manage, 400 empty reason, 409 shipped order, 404 other tenant

Checklist: 10/10 | Build: PASS | Tests: 5/5 PASS | Architecture tests: PASS

Related

  • modular-slices: the default architecture and its building blocks
  • architecture-advisor: single-project slices, Clean Architecture and DDD references
  • dotnet-init: set up the project and CLAUDE.md before scaffolding
  • tdd: write the feature's tests first, then scaffold to make them pass