agentleFS
Facta-DevFacta-Dev/beautifulnodejs/.claude/skills/add-handler/SKILL.md

add-handler

Skill0 starsChanged 31 days agoMITView on GitHub

Scaffold a new Fastify route in <app>: handler decode shape, envelope mapping, specs/openapi.yaml entry, route registration in src/features/<slice>/module.ts, and Deps wiring, as one change across the slice.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do not activate for non-HTTP changes (domain logic, persistence, migrations) — those belong to other skills.

    line 18
  2. Very specific:

    Every stat needs a source.

    line 31
  3. Distinctive:

    Do not emit the final design as a fenced code block when raw output is expected — the sketch is plain text with labelled sections (handler …

    line 32
  4. Very specific:

    Verify the cited use-case method exists in src/features/<slice>/usecase.ts before wiring it.

    line 33
  5. Very specific:

    Every route must carry a matching specs/openapi.yaml entry.

    line 34

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

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

<app> Add Handler

A reusable scaffolding workflow for adding an HTTP capability to the <app> API. An agent (e.g. the API designer role) invokes this skill to produce the handler, the OpenAPI spec, the route registration, and the Deps wiring together — so a route never lands without its spec and its wiring. The output is a design sketch plus a registration checklist.

When to Activate

  • A new endpoint is requested on the <app> API (a new verb on an existing path, or a new path).
  • An existing handler needs a new decode shape or a new error code.
  • The OpenAPI spec must register a route that already exists in code (drift fix).
  • A reviewer asks for the handler + spec + wiring bundle before approving an API change.

Do not activate for non-HTTP changes (domain logic, persistence, migrations) — those belong to other skills.

Core Principles

  • The handler is an adapter, not a service. Decode, validate at the edge, call the slice's use case (src/features/<slice>/usecase.ts), map to the envelope, return. No SQL, no domain logic in the handler.
  • The spec is the contract; the models are generated. specs/openapi.yaml is hand-edited as the source of truth; src/gen/api is the artifact make gen refreshes. A route that lands without its spec entry is a defect.
  • The composition root stays thin. A new Deps field is a use case / small consumer-defined interface wired once in src/bin/api.ts; logic lives in the use cases.
  • Registration is centralized per slice. src/features/<slice>/module.ts register(app, d) is the one place a slice's routes are mounted.
  • Errors are typed, not stringy. Every domain error the use case can return maps to a stable apperr code with a deliberate status code.

Rules

  • Anti-hallucination: do not invent import paths, use-case methods, or error codes that are not in the tree. Every wiring step cites a file that exists.
  • Every stat needs a source. If you cite Fastify's one-handler-per-method+path rule (duplicates throw FST_ERR_DUPLICATED_ROUTE), cite the Fastify docs; if you cite a status code semantics, cite RFC 9110. No unsourced numbers.
  • Do not emit the final design as a fenced code block when raw output is expected — the sketch is plain text with labelled sections (handler / spec / wiring / checklist).
  • Verify the cited use-case method exists in src/features/<slice>/usecase.ts before wiring it; a handler that calls a method the use case does not expose is a hallucination.
  • Every route must carry a matching specs/openapi.yaml entry; make gen-check must stay green (committed src/gen/api has no drift).
  • Routes are registered in the slice's module.ts, never inline in src/bin/api.ts or in another slice's file.
  • Auth-protected handlers sit behind the authx require-auth preHandler / require-role guard; public handlers are explicitly marked and rare.

Research References

Provenance table — fill the link column from the primary source before relying on a claim. No claim may appear in a finding without a row here.

claimsourceyearlink
Fastify registers one handler per method+path (duplicates throw FST_ERR_DUPLICATED_ROUTE)Fastify documentation, Routing2024<TODO: primary doc link>
specs/openapi.yaml is the source of truth for src/gen/api modelsopenapi-typescript documentation2024<TODO: primary doc link>
HTTP status code semantics (400/401/403/404/409/500)RFC 9110, status codes2022<TODO: primary doc link>
httpx.decode validates the request body with a zod schema at the trust boundarysrc/platform/httpx (local)—local file

Output Format

A design sketch plus a registration checklist, anchored to the skeleton file layout. Plain text — not a fenced block:

DESIGN  POST /api/v1/widgets  (src/features/widgets/http.ts)

  handler:
    app.post("/api/v1/widgets", { preHandler: requireAuth }, async (req, reply) => {
      const body = httpx.decode(CreateWidgetRequest, req.body)
      // validate at the edge (zod), call the use case, write the envelope
    })

  spec:
    specs/openapi.yaml — add the request/response schemas + the
    POST /api/v1/widgets path (operationId: createWidget); run
    make gen and commit the regenerated src/gen/api.

  wiring:
    module.ts  -> register(app, d) mounts POST /api/v1/widgets
    deps       -> Deps.create use case (already wired; no new field)

CHECKLIST
  [ ] handler is a thin adapter — no business logic; calls the use case
  [ ] specs/openapi.yaml entry added; make gen run; src/gen/api committed
  [ ] route registered in module.ts register() (not inline in the bin)
  [ ] envelope {"error":{"code","message"}} covers the failure modes; no leaky 500s
  [ ] Deps unchanged OR new field is a use case / port wired in src/bin/api.ts

Summary line: add-handler: N handler(s) designed, M registration step(s) — verdict: APPROVE | REVISE.

Download now (ZIP)

Does 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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.