skills/fastify-best-practise/SKILL.md
Apply Fastify best practices when creating servers, plugins, routes, schemas, hooks, configuration, decorators, error handling, testing, and TypeScript integration. Use when writing or reviewing Fastify code, setting up a new Fastify project, or asking "How should I structure my Fastify app?"
npx skillsauth add thecodepace/fastify-skills fastify-best-practiseInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A curated set of rules and patterns for building production-ready Fastify applications. Each rule includes incorrect and correct examples with explanations.
The rules are organized by topic in the rules/ directory. Each rule follows a consistent format with impact rating, incorrect/correct examples, and references to official docs.
| Rule | File | Impact | Description |
| ----------------------- | ------------------------------------------------------------ | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Configuration | configuration.md | HIGH | Environment config, logger setup, security options, and graceful shutdown |
| Create Server | create-server.md | LOW-MEDIUM | Use a buildServer() factory function for reusable, testable server setup |
| Create Plugin | create-plugin.md | LOW-MEDIUM | Encapsulate reusable functionality in plugins with fastify-plugin |
| Autoload | autoload.md | HIGH | Automatically load plugins and routes from the filesystem with @fastify/autoload |
| Route Best Practices | route-best-practices.md | MEDIUM | Organize routes with plugins/prefixes, use async handlers, full route options |
| Schema Validation (Zod) | schema-validation-zod.md | HIGH | Type-safe validation with Zod + fastify-type-provider-zod |
| Encapsulation | encapsulation.md | HIGH | Proper scope isolation and when to use fastify-plugin |
| Error Handling | error-handling.md | HIGH | Custom error handlers, @fastify/error, 404 handling, structured responses |
| Hooks & Lifecycle | hooks-lifecycle.md | MEDIUM | All request/reply and application hooks: onRequest, preParsing, preValidation, preHandler, preSerialization, onError, onSend, onResponse, onTimeout, onRequestAbort, onReady, onListen, onClose, onRoute, onRegister |
| Logging | logging.md | HIGH | Built-in Pino logger, request correlation, redaction, child loggers |
| Authentication | authentication.md | HIGH | JWT auth with @fastify/jwt, multi-strategy with @fastify/auth |
| Testing | testing.md | HIGH | Test with inject(), buildServer pattern, vitest/node:test |
| TypeScript | typescript-integration.md | MEDIUM | Type providers, module augmentation, typed decorators |
| Decorators | decorators.md | MEDIUM | Extend the Fastify instance, request, and reply with decorate / decorateRequest / decorateReply |
| Content Type Parser | content-type-parser.md | HIGH | Custom content type parsers, body limits, multipart uploads, catch-all and regex matching |
When generating Fastify code, read the relevant rule file(s) for the topic and apply the patterns shown. For a new project, all rules are relevant. For specific tasks, load only what's needed:
create-server.md, configuration.md, autoload.md, encapsulation.md, typescript-integration.mdroute-best-practices.md, autoload.md, schema-validation-zod.mdcreate-plugin.md, autoload.md, encapsulation.mdconfiguration.mderror-handling.mdauthentication.md, hooks-lifecycle.md, encapsulation.mddecorators.md, typescript-integration.mdlogging.mdcontent-type-parser.mdtesting.md, create-server.mdUsing @fastify/autoload, plugins and routes are loaded automatically from their directories:
src/
plugins/ # Autoloaded — shared plugins (use fastify-plugin)
db.ts
auth.ts
config.ts
routes/ # Autoloaded — encapsulated route plugins (NO fastify-plugin)
_hooks.ts # Global route hooks (with autoHooks: true)
users/
index.ts # → /users
_hooks.ts # Hooks for /users scope only
schema.ts
posts/
index.ts # → /posts
schema.ts
server.ts # buildServer() with autoload registration
app.ts # Entry point — calls buildServer() and listen()
test/
routes/
users.test.ts
posts.test.ts
helpers.ts # createTestServer() helper
When applying these best practices, mention which rule(s) you followed:
Applied Fastify best practices:
- Route organization: Routes grouped by resource with prefixes
- Zod validation: Request/response schemas with type inference
- Encapsulation: Shared plugins use
fastify-plugin, routes stay scoped- Error handling: Custom error handler with
@fastify/error
tools
Use when work should span one or more detached tasks but still behave like one job with a single owner context. TaskFlow is the durable flow substrate under authoring layers like Lobster, ACPX, plugins, or plain code. Keep conditional logic in the caller; use TaskFlow for flow identity, child-task linkage, waiting state, revision-checked mutations, and user-facing emergence.
tools
# Lobster Lobster executes multi-step workflows with approval checkpoints. Use it when: - User wants a repeatable automation (triage, monitor, sync) - Actions need human approval before executing (send, post, delete) - Multiple tool calls should run as one deterministic operation ## When to use Lobster | User intent | Use Lobster? | | ------------------------------------------------------ | --------------------------
tools
# Lobster Lobster executes multi-step workflows with approval checkpoints. Use it when: - User wants a repeatable automation (triage, monitor, sync) - Actions need human approval before executing (send, post, delete) - Multiple tool calls should run as one deterministic operation ## When to use Lobster | User intent | Use Lobster? | | ------------------------------------------------------ | --------------------------
tools
A CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.