home / skills / partme-ai / full-stack-skills / fastify

fastify skill

/skills/fastify

This skill provides comprehensive guidance for Fastify to build high-performance Node.js APIs, including routing, plugins, schemas, hooks, and optimization.

npx playbooks add skill partme-ai/full-stack-skills --skill fastify

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
686 B
---
name: fastify
description: Provides comprehensive guidance for Fastify framework including routing, plugins, schemas, hooks, and performance optimization. Use when the user asks about Fastify, needs to create high-performance Node.js applications, implement Fastify plugins, or optimize API performance.
license: Complete terms in LICENSE.txt
---

## When to use this skill

Use this skill whenever the user wants to:
- [待完善:根据具体工具添加使用场景]

## How to use this skill

[待完善:根据具体工具添加使用指南]

## Best Practices

[待完善:根据具体工具添加最佳实践]

## Keywords

[待完善:根据具体工具添加关键词]

Overview

This skill provides comprehensive, practical guidance for building high-performance Node.js services with the Fastify framework. It covers routing, plugin authoring, schema-driven validation, lifecycle hooks, and proven performance optimization techniques. The material is focused on actionable patterns that help you design maintainable, fast APIs and plugins.

How this skill works

The skill inspects your use case and recommends Fastify patterns suited to it: route design, JSON schema validation, and plugin composition. It explains how to implement and register plugins, use hooks for request lifecycle control, and apply serialization and schema strategies to reduce overhead. It also offers profiling and benchmarking tips to identify and remove bottlenecks.

When to use it

  • When building a REST or JSON API that must handle high concurrency with low latency.
  • When creating reusable Fastify plugins or composing microservices with shared behavior.
  • When you need to add schema validation and serialization to improve safety and throughput.
  • When optimizing existing Express or Koa apps for better performance and lower memory use.
  • When introducing lifecycle hooks for authentication, logging, or request transformation.

Best practices

  • Define JSON schemas for requests and responses and reuse them to enable fast serialization.
  • Encapsulate features in plugins with clear decorators and exposed APIs to keep code modular.
  • Prefer fast-json-stringify-compatible schemas for response serialization to reduce CPU cost.
  • Use route-level schema and validation to fail fast and avoid unnecessary handler execution.
  • Profile with simple benchmarks (autocannon) and trace hot paths before micro-optimizing.

Example use cases

  • Create a user service with input validation, rate limiting plugin, and JWT authentication hook.
  • Migrate an Express API to Fastify to improve request throughput and reduce latency.
  • Author a Fastify plugin that provides database access and register it across multiple apps.
  • Optimize a JSON-heavy endpoint by adding response schemas and enabling fast serialization.
  • Set up lifecycle hooks for centralized logging, metrics collection, and error handling.

FAQ

Do I need to write JSON schemas for every route?

You should define schemas for routes where performance or data correctness matters; reuse shared schemas to minimize duplication.

How do Fastify plugins differ from middleware?

Plugins encapsulate behavior, can register routes, decorators, and hooks, and are designed for composition and isolation, while middleware is typically a function chain without the plugin lifecycle.