fastify-best-practices

Comprehensive guidance for building Fastify Node.js backends with TypeScript, covering routes, plugins, validation, and production deployment. Covers 16+ core topics including plugins, route organization, JSON Schema validation, error handling, hooks, authentication, testing, logging with Pino, and TypeScript integration via strip types Includes recommended reading paths for common scenarios: new projects, adding authentication, performance optimization, testing setup, and production deployment Addresses full request lifecycle management, response serialization, CORS and security headers, WebSocket support, database integration, and HTTP proxying Emphasizes schema-first development, plugin encapsulation, async/await patterns, and Fastify's built-in performance optimizations with minimal external dependencies

INSTALLATION
npx skills add https://github.com/mcollina/skills --skill fastify-best-practices
Run in your project or agent environment. Adjust flags if your CLI version differs.

SKILL.md

$2c

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
BrowserAct

Let your agent run on any real-world website

Bypass CAPTCHA & anti-bot for free. Start local, scale to cloud.

Explore BrowserAct Skills →

Stop writing automation&scrapers

Install the CLI. Run your first Skill in 30 seconds. Scale when you're ready.

Start free
free · no credit card