Loading...
Loading...
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 skill4agent add thecodepace/fastify-skills fastify-best-practiserules/| 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 |
| Create Plugin | create-plugin.md | LOW-MEDIUM | Encapsulate reusable functionality in plugins with |
| Autoload | autoload.md | HIGH | Automatically load plugins and routes from the filesystem with |
| 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 + |
| Encapsulation | encapsulation.md | HIGH | Proper scope isolation and when to use |
| Error Handling | error-handling.md | HIGH | Custom error handlers, |
| 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 |
| Testing | testing.md | HIGH | Test with |
| TypeScript | typescript-integration.md | MEDIUM | Type providers, module augmentation, typed decorators |
| Decorators | decorators.md | MEDIUM | Extend the Fastify instance, request, and reply with |
| Content Type Parser | content-type-parser.md | HIGH | Custom content type parsers, body limits, multipart uploads, catch-all and regex matching |
create-server.mdconfiguration.mdautoload.mdencapsulation.mdtypescript-integration.mdroute-best-practices.mdautoload.mdschema-validation-zod.mdcreate-plugin.mdautoload.mdencapsulation.mdconfiguration.mderror-handling.mdauthentication.mdhooks-lifecycle.mdencapsulation.mddecorators.mdtypescript-integration.mdlogging.mdcontent-type-parser.mdtesting.mdcreate-server.md@fastify/autoloadsrc/
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() helperApplied Fastify best practices:
- Route organization: Routes grouped by resource with prefixes
- Zod validation: Request/response schemas with type inference
- Encapsulation: Shared plugins use
, routes stay scopedfastify-plugin- Error handling: Custom error handler with
@fastify/error