fastify-best-practices — Claude Code skill: setup and guide
Guides AI assistants in building Fastify backend servers with TypeScript or JavaScript. It covers plugin encapsulation, schemas, logging, and deployment patterns.
npx skills add mcollina/skills --skill fastify-best-practices -a claude-code
npx skills add mcollina/skills --skill fastify -a claude-codeWhat fastify-best-practices does
This skill equips your coding agent with architectural guidelines for Fastify REST APIs in JavaScript and TypeScript. It walks through the complete request lifecycle, including hooks, content-type parsing, response serialization, and structured logging via Pino. Route testing relies on Fastify's native inject() method without opening network ports.
The knowledge base breaks down into individual rule files for schemas, error handling, authentication, WebSockets, and HTTP proxying via reply.from(). It enforces a schema-first mindset, requiring JSON Schema definitions for request validation and response output. Because of this focus on strict encapsulation, handlers that bypass plugin scopes or omit schema definitions will be flagged for restructuring.
TypeScript integration assumes the strip types approach. Recommended reading paths help organize complex projects from initial setup to production monitoring.
What it helps with
- structure modular Fastify plugins with strict encapsulation
- validate incoming requests and serialize responses using JSON Schema
- test endpoints without opening network sockets using
inject() - configure structured logging with Pino and custom error handlers
Example prompts for the agent
- Create a Fastify auth plugin that validates tokens in an onRequest hook
- Define a JSON Schema for validating POST request bodies on `/api/items`
- Write a test suite for the `/health` route using Fastify's inject method
How to install fastify-best-practices
1Skills CLI (Vercel)
npx skills add mcollina/skills --skill fastify-best-practices -a claude-codenpx skills add mcollina/skills --skill fastify -a claude-code2Manually: put the files in place
~/.claude/skills/fastify/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/fastify/
1Skills CLI (Vercel)
npx skills add mcollina/skills --skill fastify -a codex2Manually: put the files in place
.agents/skills/fastify/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add mcollina/skills --skill fastify -a cursor2Manually: put the files in place
.cursor/skills/fastify/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install mcollina/skills fastify2Manually: put the files in place
.github/skills/fastify/SKILL.md1Skills CLI (Vercel)
npx skills add mcollina/skills --skill fastify -a gemini-cli2Platform CLI
gemini skills install https://github.com/mcollina/skills --path skills/fastifyManually: put the files in place
.devin/skills/fastify/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add mcollina/skills --skill fastify -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Similar
Questions about fastify-best-practices
How do I install fastify-best-practices in Claude Code?
Run npx skills add mcollina/skills --skill fastify-best-practices -a claude-code in your terminal.
What does fastify-best-practices do?
It instructs the agent on proper Fastify architecture, covering plugin encapsulation, hooks, schemas, database integrations, and Pino logging.
How does the skill handle endpoint testing?
The skill directs the assistant to use Fastify's built-in inject() method. This runs simulated HTTP requests directly against the app instance without binding to a network port.
Source text
SKILL.md · MIT
---
name: fastify-best-practices
description: "Guides development of Fastify Node.js backend servers and REST APIs using TypeScript or JavaScript. Use when building, configuring, or debugging a Fastify application — including defining routes, implementing plugins, setting up JSON Schema validation, handling errors, optimising performance, managing authentication, configuring CORS and security headers, integrating databases, working with WebSockets, and deploying to production. Covers the full Fastify request lifecycle (hooks, serialization, logging with Pino) and TypeScript integration via strip types. Trigger terms: Fastify, Node.js server, REST API, API routes, backend framework, fastify.config, server.ts, app.ts."
metadata:
tags: fastify, nodejs, typescript, backend, api, server, http
---
## When to use
Use this skill when you need to:
- Develop backend applications using Fastify
- Implement Fastify plugins and route handlers
- Get guidance on Fastify architecture and patterns
- Use TypeScript with Fastify (strip types)
- Implement testing with Fastify's inject method
- Configure validation, serialization, and error handling
## Quick Start
A minimal, runnable Fastify server to get started immediately:
```ts
import Fastify from 'fastify'
const app = Fastify({ logger: true })
app.get('/health', async (request, reply) => {
return { status: 'ok' }
})
const start = async () => {
await app.listen({ port: 3000, host: '0.0.0.0' })
}
start()
```
## Recommended Reading Order for Common Scenarios
- **New to Fastify?** Start with `plugins.md` → `routes.md` → `schemas.md`
- **Adding authentication:** `plugins.md` → `hooks.md` → `authentication.md`
- **Improving performance:** `schemas.md` → `serialization.md` → `performance.md`
- **Setting up testing:** `routes.md` → `testing.md`
- **Going to production:** `logging.md` → `configuration.md` → `deployment.md`
## How to use
Read individual rule files for detailed explanations and code examples:
- [rules/plugins.md](rules/plugins.md) - Plugin development and encapsulation
- [rules/routes.md](rules/routes.md) - Route organization and handlers
- [rules/schemas.md](rules/schemas.md) - JSON Schema validation
- [rules/error-handling.md](rules/error-handling.md) - Error handling patterns
- [rules/hooks.md](rules/hooks.md) - Hooks and request lifecycle
- [rules/authentication.md](rules/authentication.md) - Authentication and authorization
- [rules/testing.md](rules/testing.md) - Testing with inject()
- [rules/performance.md](rules/performance.md) - Performance optimization
- [rules/logging.md](rules/logging.md) - Logging with Pino
- [rules/typescript.md](rules/typescript.md) - TypeScript integration
- [rules/decorators.md](rules/decorators.md) - Decorators and extensions
- [rules/content-type.md](rules/content-type.md) - Content type parsing
- [rules/serialization.md](rules/serialization.md) - Response serialization
- [rules/cors-security.md](rules/cors-security.md) - CORS and security headers
- [rules/websockets.md](rules/websockets.md) - WebSocket support
- [rules/database.md](rules/database.md) - Database integration patterns
- [rules/configuration.md](rules/configuration.md) - Application configuration
- [rules/deployment.md](rules/deployment.md) - Production deployment
- [rules/http-proxy.md](rules/http-proxy.md) - HTTP proxying and reply.from()
## Core Principles
- **Encapsulation**: Fastify's plugin system provides automatic encapsulation
- **Schema-first**: Define schemas for validation and serialization
- **Performance**: Fastify is optimized for speed; use its features correctly
- **Async/await**: All handlers and hooks support async functions
- **Minimal dependencies**: Prefer Fastify's built-in features and official plugins
© mcollina · MIT · mcollina/skills