fastify-best-practices

Guides building, configuring, and deploying Fastify Node.js backend servers and REST APIs.

1|Updated Jul 2, 2026
One-click install
npx skills add https://github.com/filippolmt/skills --skill fastify-best-practices-filippolmt
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastify-best-practices
Source: https://github.com/filippolmt/skills/tree/main/skills/fastify-best-practices
Command: npx skills add https://github.com/filippolmt/skills --skill fastify-best-practices-filippolmt

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building production-grade Fastify applications requires correct use of plugins, hooks, schemas, authentication, and deployment patterns, and mistakes in any of these lead to security holes, poor performance, or broken encapsulation. ## Core Features & Use Cases - Structured rule references: Nineteen topic files covering plugins, routes, JSON Schema validation, error handling, hooks, authentication, testing, performance, logging, TypeScript, decorators, content types, serialization, CORS/security, WebSockets, databases, configuration, deployment, and HTTP proxying. - Scenario-based reading paths: Recommended reading orders for common goals such as adding authentication, improving performance, setting up testing, and going to production. - Use Case: When implementing JWT authentication in a Fastify API, consult the authentication rules to set up @fastify/jwt, refresh token rotation, role-based access control, and Redis-backed rate limiting on auth endpoints. ## Quick Start Ask the assistant to help you build a Fastify route with schema validation and JWT authentication following best practices.

Frequently Asked Questions about fastify-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement JWT authentication in Fastify?

Use @fastify/jwt to sign and verify tokens, then decorate the instance with an authenticate function that calls request.jwtVerify(). Protect routes by adding that decorator to the onRequest hook, and implement refresh token rotation for longer sessions.

How do I validate request bodies in Fastify?

Define a JSON Schema on the route's schema.body property and Fastify validates the payload automatically before the handler runs. The same schema approach works for params, querystring, headers, and response serialization.

Does Fastify support TypeScript?

Yes, Fastify works with TypeScript via strip types and declaration merging. You extend the FastifyInstance, FastifyRequest, and FastifyReply interfaces through declare module to get type safety on decorators and custom properties.

How do I structure a Fastify application with plugins?

Register routes and services as plugins using app.register, which provides automatic encapsulation of decorators and hooks. Use fastify-plugin (fp) when a decorator or connection must be shared across sibling plugins, and declare plugin dependencies explicitly.

Why is in-memory rate limiting unsafe in production Fastify apps?

In-memory rate limiting only tracks requests per process, so limits are bypassed when running multiple instances behind a load balancer. Configure @fastify/rate-limit with a Redis backend so counters are shared across all instances.

How do I deploy a Fastify app to production?

Use close-with-grace for graceful shutdown, expose /health/live and /health/ready endpoints for orchestrator probes, and configure trustProxy when behind a load balancer. The deployment rules include Dockerfile, Kubernetes manifest, and Prometheus metrics examples.