jgamaraalv/ts-dev-kit/fastify-best-practices
Claude Code and agent skill by jgamaraalv/ts-dev-kit
- community
Checking that the SKILL.md file is still in the repository.
Fastify 5 best practices, API reference, and patterns for routes, plugins, hooks, validation, error handling, and TypeScript. Use when: (1) writing new Fastify routes, plugins, or hooks, (2) looking up Fastify API signatures or options, (3) debugging Fastify issues (lifecycle, encapsulation, validation, plugin timeout), (4) reviewing Fastify code for anti-patterns. Triggers: 'add a route', 'create plugin', 'Fastify hook', 'validation schema', 'Fastify error', 'setErrorHandler', 'fastify-plugin'.
Install
npx vskill@latest install jgamaraalv/ts-dev-kit/fastify-best-practicesSKILL.md
Fastify 5 Best Practices
Table of Contents
<quick_reference>
Request lifecycle (exact order)
Error at any stage → onError hooks → error handler → onSend → response → onResponse.
</quick_reference>
<anti_patterns>
Top anti-patterns
- Mixing async/callback in handlers — Use
asyncOR callbacks, never both. With async,returnthe value; don't callreply.send()AND return.
- Returning `undefined` from async handler — Fastify treats this as "no response yet". Return the data or call
reply.send().
- Using arrow functions when you need `this` — Arrow functions don't bind
thisto the Fastify instance. Usefunctiondeclarations for handlers that needthis.
- Forgetting `fastify-plugin` wrapper — Without it, decorators/hooks stay scoped to the child context. Parent and sibling plugins won't see them.
- Decorating with reference types directly —
decorateRequest('data', {})shares the SAME object across all requests. Usenullinitial +onRequesthook to assign per-request.
- Sending response in `onError` hook —
onErroris read-only for logging. UsesetErrorHandler()to modify error responses.
- Not handling `reply.send()` in async hooks — Call
return replyafterreply.send()in async hooks to prevent "Reply already sent" errors.
- Ignoring encapsulation — Decorators/hooks registered in child plugins are invisible to parents. Design your plugin tree carefully.
- String concatenation in SQL from route params — Always use parameterized queries. Fastify validates input shape, not content safety.
- Missing response schema — Without
responseschema, Fastify serializes withJSON.stringify()(slow) and may leak sensitive fields. Usefast-json-stringifyvia response schemas.
</anti_patterns>
<examples>
Quick patterns
Plugin with fastify-plugin (FastifyPluginCallback)
Project convention: use FastifyPluginCallback + done() (avoids require-await lint errors).
Route with validation
Hook (application-level)
Error handler
</examples>
<references>
Reference files
Load the relevant file when you need detailed API information:
- Server factory & options — constructor options, server methods, properties: references/server-and-options.md
- Routes & handlers — declaration, URL params, async patterns, constraints: references/routes-and-handlers.md
- Hooks & lifecycle — all 16 hook types, signatures, scope, early response: references/hooks-and-lifecycle.md
- Plugins & encapsulation — creating plugins, fastify-plugin, context inheritance: references/plugins-and-encapsulation.md
- Validation & serialization — JSON Schema, Ajv, response schemas, custom validators: references/validation-and-serialization.md
- Request, Reply & errors — request/reply API, error handling, FST_ERR codes: references/request-reply-errors.md
- TypeScript & logging — route generics, type providers, Pino config, decorators: references/typescript-and-logging.md
</references>
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/fastify-best-practices/SKILL.md
Popularity
- Repository stars
- 15
- Repository npm downloads, 7 days
- 41
- 7-day trend score
- 23
Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 11 May 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/jgamaraalv/ts-dev-kit/fastify-best-practices)