Fastify

From qauth-labs/qauth · View interactive version

Fastify is an AI agent skill from the GitHub repository qauth-labs/qauth. Fastify usage for QAuth — plugin authoring (encapsulation, decorators, lifecycle), route schemas with the Zod type provider, production/reverse-proxy setup, and the Fastify version/CVE requirement. Use when adding or modifying @qauth-labs/fastify-plugin-* libraries, auth-server routes, or deployment

How to use this skill

Skill file

Fastify (QAuth)

Standards-aligned Fastify usage for QAuth: plugin authoring, route validation,

and production deployment. Use this skill when creating plugins, wiring routes,

reviewing Fastify code, or configuring the server for production.

When to Use This Skill

Production

directly to the internet. Handle TLS, HTTP→HTTPS redirects, and static assets

at the proxy.

can reach the app (the default 127.0.0.1 is unreachable from the pod network).

request.ip and X-Forwarded-* headers are correct.

Routes and Validation

schema.response (e.g. response: { 200: responseSchema }). Fastify v5 uses

schemas for both validation and types.

defining routes when using Zod schemas.

fastify.withTypeProvider<ZodTypeProvider>().post(
  '/login',
  {
    schema: {
      body: loginSchema,
      response: { 200: loginResponseSchema },
    },
    config: { rateLimit: { max: env.LOGIN_RATE_LIMIT, timeWindow: env.LOGIN_RATE_WINDOW * 1000 } },
  },
  async (request, reply) => {
    /* ... */
  }
);

Security and Dependencies

(content-type parsing bypass in 5.0.0–5.3.0). Do not rely on

content-type-specific validation without normalizing the header.

vulnerabilities (see the security skill).

Quick Reference

| Concern | QAuth pattern |

| ---------------- | ------------------------------------------------------------------------------- |

| Distribution | Wrap with fastify-plugin so decorators are available to parent/children |

| Name | name: '@qauth-labs/fastify-plugin-<feature>' in fp options |

| Types | declare module 'fastify' { interface FastifyInstance { ... } } in plugin file |

| Options | Typed via fp<OptionsType>(async (fastify, options) => {...}, { name }) |

| Lifecycle | Use onReady for post-boot checks, onClose for cleanup (e.g. DB/cache) |

| Logging | fastify.log.debug/info/warn after registration or in hooks |

Plugin Structure (QAuth)

  1. Wrap with fp

All plugins that add decorators used outside their own context must use fastify-plugin. Otherwise decorators are encapsulated and not visible to the root app or sibling plugins.

  1. Name and TypeScript
  1. Options
  1. Decorators
  1. Lifecycle
  1. Errors

Encapsulation Rules

Project Layout

Checklist for New Plugins

Additional Resources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.