/stackwise:fastify-expertfrom stackwise
Builds and debugs Fastify 5 services with schema-first TypeScript, correct plugin encapsulation, TypeBox type provider, JWT auth, and inject-based tests. Scaffolds routes, wires databases, and fixes Express-isms.
Ships in stackwise. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Turns Claude into a senior Node.js backend engineer who ships Fastify 5 services on Node 22 with schema-first TypeScript, correct plugin encapsulation, and inject-based tests - and who never smuggles Express idioms into a Fastify codebase.
fastify-plugin is (and is not) needed@fastify/jwt) and per-route authorization via hookspg behind a decorated, lifecycle-managed pluginsetErrorHandler and @fastify/sensibleapp.inject() (no port binding) and fix failing onesapp.use middleware, res.send, monkey-patched request objectspackage.json (confirm fastify is 5.x and which @fastify/* plugins exist), the app factory (buildApp/app.ts), how plugins are registered (manual vs @fastify/autoload), the type provider in use, and tsconfig.json. Match the existing plugin layout and naming before writing anything. Note which decorators already exist and where their declare module 'fastify' merges live.FastifyPluginAsyncTypebox for encapsulated route plugins, fastify-plugin only for cross-cutting infrastructure (db, auth, config). Define every route's schema (body, querystring, params, response) with TypeBox and let the type provider infer handler types. Async handlers return the payload; never mix reply.send() with a returned value.npx tsc --noEmit, then the project's linter (npx eslint . or npm run lint); fix all reported issues and re-run until clean before proceeding. Do not paper over type errors with as any on request/reply - fix the schema or the declaration merge instead.app.inject() (see references/testing.md); run the project's test command (npx vitest run or node --test); fix every failure and re-run until all tests pass.npm run dev or node --run dev), hit the changed routes with curl, including one invalid payload to confirm the 400 validation shape and one unauthorized request to confirm the 401. Check the response actually contains the fields you expect - the response schema silently drops unlisted fields. Fix and re-verify until live behavior matches the spec.Load detailed guidance only when the task needs it:
| Topic | Reference | Load When |
|---|---|---|
| Plugin system, encapsulation contexts, fastify-plugin, decorators + declaration merging | references/plugins-encapsulation.md | Creating/registering any plugin; a decorator or hook is "undefined" in another file; deciding whether to use fp(); typing fastify.x or request.x |
| TypeBox type provider, schema-first validation, response serialization | references/validation-typebox.md | Writing any route schema; typing handlers from schemas; shared schemas/$ref; fields missing from responses; validation error shapes |
| Hooks lifecycle, @fastify/jwt auth, error handling, pino + request correlation | references/hooks-auth.md | Choosing onRequest vs preValidation vs preHandler; adding login/protected routes; role checks; centralizing errors; configuring logging or request ids |
| Prisma / Drizzle / pg integration and lifecycle | references/database.md | Wiring any database client; connection pooling; graceful shutdown; transactions per request; health checks |
| Testing with app.inject(), test app factories, auth/db in tests | references/testing.md | Writing or fixing any test; testing protected routes; overriding db/config for tests; testing plugins in isolation |
Route plugin with TypeBox - types are inferred from the schema, never hand-annotated:
import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox'
const usersRoutes: FastifyPluginAsyncTypebox = async (app) => {
app.post('/users', {
schema: {
body: Type.Object({ email: Type.String({ format: 'email' }), name: Type.String() }),
response: { 201: Type.Object({ id: Type.String(), email: Type.String() }) },
},
}, async (request, reply) => {
const { email, name } = request.body // typed from the schema
const user = await app.db.user.create({ data: { email, name } })
reply.code(201)
return user // serialized by the 201 schema
})
}
export default usersRoutes
Infrastructure plugin - fp() breaks encapsulation on purpose, with declaration merging:
import fp from 'fastify-plugin'
import { PrismaClient } from '@prisma/client'
declare module 'fastify' {
interface FastifyInstance { db: PrismaClient }
}
export default fp(async (app) => {
const db = new PrismaClient()
await db.$connect()
app.decorate('db', db)
app.addHook('onClose', async () => { await db.$disconnect() })
}, { name: 'db', fastifyVersion: '5.x' })
Auth as a decorated onRequest hook, applied per route - not global middleware:
app.decorate('authenticate', async (request: FastifyRequest, reply: FastifyReply) => {
try { await request.jwtVerify() }
catch { return reply.unauthorized('invalid or missing token') }
})
app.get('/me', { onRequest: [app.authenticate] }, async (request) => request.user)
register() creates a child encapsulation context; decorators and hooks added there are invisible to siblings and the parent. Wrap infrastructure plugins in fp() - but do not reflexively wrap route plugins, which should stay encapsulated (that is how per-prefix hooks and scoped auth work).app.use(middleware) in Fastify 5 without @fastify/middie (avoid it); use hooks and plugins. res.send/res.json/res.status do not exist - return the payload from an async handler or use reply.code().send(), never both (returning a value and calling reply.send causes "Reply was already sent" / hung requests).schema and let the TypeBox type provider infer request.body/query/params. Manual zod.parse inside handlers duplicates work and skips fast-json-stringify serialization.response: { 200: ... } is a serializer, not documentation - any property not in the schema is silently stripped from the response. If a field "disappears", the response schema is missing it.onRequest (body not yet parsed - cheap rejects); use preHandler only when authorization needs the parsed body. preValidation is for mutating the raw request before schema validation, not for auth.app.decorateRequest('user', { ... }) shares one object across all requests. Decorate with null and assign per-request in a hook.request.routerPath is gone (use request.routeOptions.url); custom logger instances go in loggerInstance, not logger; reply.redirect(url, code) takes the URL first.listen() and fetch localhost in tests - app.inject() dispatches requests in-process with no port binding, and it awaits ready() for you.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub aarvion-ai/stackwise-skills --plugin stackwiseOther plugins' skills for the same job
16 skills in this plugin
/docker-expertUse when working with Dockerfile, docker-compose.yml, .dockerignore, or multi-stage builds. Build, debug, secure, and optimize Docker 27+ images and Docker Compose services./engineering-rulesUse when writing, modifying, or reviewing code in any language or framework. Applies to every code task in this repo and every code sample inside a skill: new features, bug fixes, refactors, generated snippets, tests, scripts, docs with code. Enforces the seven repo-wide rules: reusable code, maintainable structure, top-notch readability, no AI slop, dead code removal, why-only comments, no em dashes. Invoke for implementing changes, self-reviewing a diff, cleaning up generated code, writing reference examples, or reviewing a PR./fastapi-expert