Preface¶
When building REST APIs with Fastify, figuring out how to split routes, encapsulate plugins, and configure request validation and response serialization often requires flipping back and forth between the official documentation and repository examples. When involving an AI assistant in collaboration, the code it provides sometimes leans towards Express habits or ignores Fastify’s encapsulation boundaries and Schema-first conventions. The following introduces the fastify-best-practices Skill: a set of rule files that enables the assistant to provide suggestions and examples based on a unified set of rules when building, configuring, or troubleshooting Fastify applications.
What is this¶
fastify-best-practices is a documentation set for AI-assisted development (consisting of SKILL.md and topic-specific rules under rules/) designed to guide the development of Fastify backends and REST APIs using JavaScript or TypeScript. The official directory is located at mcollina/skills repository’s skills/fastify; this repository is maintained by Matteo Collina, and the fastify Skill is described as “Comprehensive best practices for Fastify development” in the repository index.
The trigger scenarios in the Skill metadata include: defining routes, implementing plugins, JSON Schema validation, error handling, performance, authentication, CORS and security headers, databases, WebSocket, production deployment, the complete request lifecycle (hooks, serialization, Pino logging), and TypeScript integration via strip types.
Core Functions¶
The Skill breaks down practices into individual rule files that can be read separately, allowing the assistant to load the corresponding sections as needed for relevant tasks.
Rule Topics (Consistent with the Official List)¶
| File | Focus |
|---|---|
rules/plugins.md |
Plugin development and encapsulation |
rules/routes.md |
Route organization and handlers |
rules/schemas.md |
JSON Schema validation |
rules/error-handling.md |
Error handling patterns |
rules/hooks.md |
Hooks and request lifecycle |
rules/authentication.md |
Authentication and authorization |
rules/testing.md |
Testing using inject() |
rules/performance.md |
Performance optimization |
rules/logging.md |
Logging using Pino |
rules/typescript.md |
TypeScript integration |
rules/decorators.md |
Decorators and extensions |
rules/content-type.md |
Content-Type parsing |
rules/serialization.md |
Response serialization |
rules/cors-security.md |
CORS and security headers |
rules/websockets.md |
WebSocket |
rules/database.md |
Database integration patterns |
rules/configuration.md |
Application configuration |
rules/deployment.md |
Production deployment |
rules/http-proxy.md |
HTTP proxy and reply.from() |
Principles Emphasized in the Documentation¶
- Encapsulation: The plugin system automatically encapsulates scope.
- Schema-first: Use Schema for validation and serialization.
- Performance: Leverage the framework’s performance-oriented approach provided correct built-in capabilities are used.
- Async/await: Both handlers and hooks support asynchronous functions.
- Minimal dependencies: Prioritize Fastify’s built-in capabilities and official plugins.
Reading Order for Common Scenarios¶
The official Skill provides scenario-based paths to facilitate jumping into tasks for assistants or humans:
- New to Fastify:
plugins.md→routes.md→schemas.md - Adding Authentication:
plugins.md→hooks.md→authentication.md - Performance Tuning:
schemas.md→serialization.md→performance.md - Writing Tests:
routes.md→testing.md - Going to Production:
logging.md→configuration.md→deployment.md
Installation and Activation¶
Agent Skills are essentially text instruction packages, and loading methods vary by platform. The following methods are based on general instructions from the community index awesome-agent-skills, with the installation target pointing to the Skill source on GitHub (the path for this Skill is skills/fastify under mcollina/skills).
- npx skills CLI (see vercel-labs/skills):
npx skills find fastify
npx skills add mcollina/skills
npx skills list
-
Claude Code: Run
/skills addin the environment, using the Skill’s GitHub address as the parameter (e.g., repository URL or raw path pointing toskills/fastify, subject to your current Claude Code documentation). -
Claude.ai: Paste the raw URL of
SKILL.mdin a new conversation to let the model read the complete instructions. -
Codex / GitHub Copilot, etc.: Follow the Agent Skills section in each product’s documentation to add the repository or Skill directory to the skills list; the community index lists Cursor, Copilot, Gemini CLI, etc. as compatible environments, though specific menus depend on the corresponding documentation.
Once activated, describe Fastify-related tasks in the conversation (e.g., “Add a POST route with Schema using TypeScript”). The assistant should match trigger words in the Skill description (such as Fastify, REST API, server.ts) and read the corresponding rules/*.md.
Typical Usage¶
The Skill comes with a Quick Start that is a minimal, runnable service: enabling Pino logging, registering /health, and listening on 0.0.0.0:3000.
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()
In real projects, a more common usage is to have the assistant combine capabilities according to the rule files. For example: registering route modules following the encapsulation methods in plugins.md; defining JSON Schemas for body/query in schemas.md; standardizing error responses in error-handling.md; and using inject() for portless HTTP testing in testing.md. The file names and capabilities mentioned above are taken directly from the official Skill directory without fabricating additional business cases.
Use Cases and Notes¶
Who it is for
- Teams currently using or planning to use Fastify to write Node.js backends or REST APIs, who want AI output to align with framework conventions.
- Developers who need to cover the entire chain from routing, plugins, and deployment to WebSockets and databases, rather than just scattered code snippets.
When to Activate the Skill (Official “When to use”)
- Developing Fastify backends, implementing plugins and route handlers.
- Need Fastify-oriented suggestions on architecture and patterns.
- Using TypeScript (including strip types),
inject()testing, or configuration validation, serialization, and error handling.
Notes
- The Skill is an instruction on “how to do it”; it does not install Node dependencies or select cloud vendors for you. Deployment details should refer to
deployment.mdand your own environment. - The same repository mcollina/skills also provides adjacent Skills such as
nodeandoauth. When integrating OAuth with Fastify, it can be combined with theoauthSkill, but this article only verifies the content of thefastifydirectory. - Whether the assistant correctly selects this Skill every time depends on the platform’s skill discovery and description matching; it is safer to include words like Fastify, routes, and Schema in your task descriptions.
Conclusion¶
fastify-best-practices breaks down the practices maintained by the Fastify author into searchable rule files, covering everything from request lifecycle, Schema, and plugin encapsulation to production deployment. If you want to avoid the pitfalls of “code that looks like Express but isn’t Fastify” in AI collaboration, you can add this Skill to your list of commonly used skills. Official address: https://github.com/mcollina/skills/tree/main/skills/fastify.