Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/add-authentication-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thecodepace/fastify-skills": minor
---

Add authentication rule for Fastify with @fastify/jwt and @fastify/auth patterns
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Rules are stored in `skills/fastify-best-practise/rules/`:
| Encapsulation | `encapsulation.md` | HIGH |
| Error Handling | `error-handling.md` | HIGH |
| Hooks & Lifecycle | `hooks-lifecycle.md` | MEDIUM |
| Logging | `logging.md` | HIGH |
| Authentication | `authentication.md` | HIGH |
| Testing | `testing.md` | HIGH |
| TypeScript | `typescript-integration.md` | MEDIUM |
| Decorators | `decorators.md` | MEDIUM |
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Apply Fastify best practices when creating servers, plugins, routes, schemas, ho
| Encapsulation | HIGH | Proper scope isolation and when to use `fastify-plugin` |
| Error Handling | HIGH | Custom error handlers, `@fastify/error`, `@fastify/sensible`, 404 handling |
| Hooks & Lifecycle | MEDIUM | Full lifecycle hook coverage: request pipeline (`onRequest` → `onResponse`), application hooks (`onReady`, `onClose`), scoped hooks, and async/callback patterns |
| Logging | HIGH | Built-in Pino logger, request correlation, redaction, child loggers |
| Authentication | HIGH | JWT auth with `@fastify/jwt`, multi-strategy with `@fastify/auth` |
| Testing | HIGH | Test with `inject()`, buildServer pattern, vitest/node:test |
| TypeScript | MEDIUM | Type providers, module augmentation, typed decorators |
| Decorators | MEDIUM | Extend the Fastify instance, request, and reply with `decorate` / `decorateRequest` / `decorateReply` |
Expand Down
27 changes: 14 additions & 13 deletions skills/fastify-best-practise/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ A curated set of rules and patterns for building production-ready Fastify applic

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 |
| ----------------------- | ------------------------------------------------------------ | ---------- | ----------------------------------------------------------------------------------------------------- |
| Create Server | [create-server.md](rules/create-server.md) | LOW-MEDIUM | Use a `buildServer()` factory function for reusable, testable server setup |
| Create Plugin | [create-plugin.md](rules/create-plugin.md) | LOW-MEDIUM | Encapsulate reusable functionality in plugins with `fastify-plugin` |
| Autoload | [autoload.md](rules/autoload.md) | HIGH | Automatically load plugins and routes from the filesystem with `@fastify/autoload` |
| Route Best Practices | [route-best-practices.md](rules/route-best-practices.md) | MEDIUM | Organize routes with plugins/prefixes, use async handlers, full route options |
| Schema Validation (Zod) | [schema-validation-zod.md](rules/schema-validation-zod.md) | HIGH | Type-safe validation with Zod + `fastify-type-provider-zod` |
| Encapsulation | [encapsulation.md](rules/encapsulation.md) | HIGH | Proper scope isolation and when to use `fastify-plugin` |
| Error Handling | [error-handling.md](rules/error-handling.md) | HIGH | Custom error handlers, `@fastify/error`, 404 handling, structured responses |
| Hooks & Lifecycle | [hooks-lifecycle.md](rules/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 |
| Rule | File | Impact | Description |
| ----------------------- | ------------------------------------------------------------ | ---------- | ---------------------------------------------------------------------------------- |
| Create Server | [create-server.md](rules/create-server.md) | LOW-MEDIUM | Use a `buildServer()` factory function for reusable, testable server setup |
| Create Plugin | [create-plugin.md](rules/create-plugin.md) | LOW-MEDIUM | Encapsulate reusable functionality in plugins with `fastify-plugin` |
| Autoload | [autoload.md](rules/autoload.md) | HIGH | Automatically load plugins and routes from the filesystem with `@fastify/autoload` |
| Route Best Practices | [route-best-practices.md](rules/route-best-practices.md) | MEDIUM | Organize routes with plugins/prefixes, use async handlers, full route options |
| Schema Validation (Zod) | [schema-validation-zod.md](rules/schema-validation-zod.md) | HIGH | Type-safe validation with Zod + `fastify-type-provider-zod` |
| Encapsulation | [encapsulation.md](rules/encapsulation.md) | HIGH | Proper scope isolation and when to use `fastify-plugin` |
| Error Handling | [error-handling.md](rules/error-handling.md) | HIGH | Custom error handlers, `@fastify/error`, 404 handling, structured responses |
| Hooks & Lifecycle | [hooks-lifecycle.md](rules/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](rules/logging.md) | HIGH | Built-in Pino logger, request correlation, redaction, child loggers |
| Testing | [testing.md](rules/testing.md) | HIGH | Test with `inject()`, buildServer pattern, vitest/node:test |
| TypeScript | [typescript-integration.md](rules/typescript-integration.md) | MEDIUM | Type providers, module augmentation, typed decorators |
| Authentication | [authentication.md](rules/authentication.md) | HIGH | JWT auth with `@fastify/jwt`, multi-strategy with `@fastify/auth` |
| Testing | [testing.md](rules/testing.md) | HIGH | Test with `inject()`, buildServer pattern, vitest/node:test |
| TypeScript | [typescript-integration.md](rules/typescript-integration.md) | MEDIUM | Type providers, module augmentation, typed decorators |
| Decorators | [decorators.md](rules/decorators.md) | MEDIUM | Extend the Fastify instance, request, and reply with `decorate` / `decorateRequest` / `decorateReply` |

## Usage
Expand All @@ -40,7 +41,7 @@ When generating Fastify code, read the relevant rule file(s) for the topic and a
- **Adding routes**: `route-best-practices.md`, `autoload.md`, `schema-validation-zod.md`
- **Adding shared services**: `create-plugin.md`, `autoload.md`, `encapsulation.md`
- **Error handling**: `error-handling.md`
- **Auth/middleware**: `hooks-lifecycle.md`, `encapsulation.md`
- **Auth/middleware**: `authentication.md`, `hooks-lifecycle.md`, `encapsulation.md`
- **Custom decorators**: `decorators.md`, `typescript-integration.md`
- **Logging**: `logging.md`
- **Writing tests**: `testing.md`, `create-server.md`
Expand Down
Loading