fastify

Installation
SKILL.md

Apply these conventions when working with Fastify code in node.js projects.

Server Setup

  • Create the Fastify instance with explicit options: logger: true (or Pino config object), trustProxy when behind a reverse proxy.
  • Separate app construction (app.ts) from server startup (server.ts / cluster.ts) to enable testing via inject() without starting the server.

Plugins & Encapsulation

  • Everything is a plugin. Register features with fastify.register(plugin, options).
  • Plugins are encapsulated by default — decorators, hooks, and routes registered inside a plugin are invisible to parent scopes.
  • Use fastify-plugin wrapper only when a plugin must expose decorators or hooks to the parent scope (e.g., database connection, authentication decorator).
  • Declare decorator dependencies in the dependencies array to fail fast at boot, not at runtime.
  • Plugin loading order matters — plugins registered first are available to later plugins in the same scope.

Routes

  • Use shorthand methods: fastify.get(), fastify.post(), etc.
  • Always use async handlers that return the response body. Do not mix return with reply.send() — pick one.
  • Group related routes in a plugin and apply a prefix via register options.
  • Use route-level schema for request validation (body, querystring, params, headers) and response serialization (response).
Installs
1
Repository
avbel/ai-skills
GitHub Stars
2
First Seen
May 16, 2026