Fastify API

Refactor Fastify APIs into plugin-first architecture with TypeBox schema validation.

1|Updated May 2, 2026
One-click install
npx skills add https://github.com/Levironexe/architect --skill fastify-api
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Fastify API
Source: https://github.com/Levironexe/architect/tree/main/skills/stacks/fastify-api
Command: npx skills add https://github.com/Levironexe/architect --skill fastify-api

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Fastify codebases often drift into inconsistent patterns, duplicated route logic, scattered validation, and hard-to-change handlers that make refactors risky.

Core Features & Use Cases

  • Phased architectural rules for structuring routes, plugins, schemas, and services so concerns stay separated (validation in schemas, cross-cutting in plugins, business logic in services).
  • Safe Fastify best practices including TypeBox schema validation, global error handling, and startup-time config validation to prevent runtime surprises.
  • Use Case: You are inheriting a Fastify API where routes manually parse inputs, auth logic is duplicated, and failures return inconsistent shapes; use this Skill to standardize structure and error/validation behavior while keeping behavior stable.

Quick Start

Tell your agent: implement the Fastify API structure by moving schema validation into src/schemas, encapsulating auth/DB/error handling into src/plugins, and refactoring route handlers to call pure services in src/services.

Frequently Asked Questions about Fastify API

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

FAQPage Schema
How do I refactor a Fastify API to separate validation logic from route handlers?

To refactor a Fastify API safely, move request and response validation into TypeBox JSON schemas, encapsulate cross-cutting concerns like auth into Fastify plugins, and extract business logic into pure services free from FastifyRequest coupling.

What is the best way to handle inconsistent error responses in a Fastify codebase?

The best way to standardize inconsistent Fastify error responses is by implementing a centralized setErrorHandler within a Fastify plugin, ensuring all failures return consistent shapes while keeping route handlers focused on core logic.

How do I structure a Fastify API to prevent duplicated auth and database logic across routes?

Prevent duplicated auth and database logic by encapsulating these cross-cutting concerns into dedicated Fastify plugins under a src/plugins directory, allowing routes to remain lightweight and consistent across the codebase.

Can I use TypeBox schemas for both request and response validation in Fastify?

Yes, you can use TypeBox schemas for strict request and response validation in Fastify. Defining these schemas in a dedicated src/schemas directory ensures data consistency and separates validation from business logic.

How do I validate environment configuration when starting a Fastify server?

Validate environment configuration at startup time to prevent runtime surprises. This ensures missing or invalid environment variables halt the Fastify application immediately rather than causing unexpected failures during request processing.

Why should I decouple Fastify services from FastifyRequest and FastifyReply objects?

Decoupling services from FastifyRequest and FastifyReply objects keeps business logic pure and framework-agnostic. This separation of concerns makes the codebase easier to test, maintain, and refactor without modifying core service functionality.