fastify
Fastify high-performance Node.js framework. Covers routing, plugins, validation, and serialization. Use when building fast Node.js APIs. USE WHEN: user mentions "Fastify", "fastify", "TypeBox", "schema validation", asks about "fast Node.js framework", "high-throughput API", "JSON schema validation", "performance-critical backend", "plugin-based architecture" DO NOT USE FOR: Enterprise DI patterns - use `nestjs` instead, Minimalist approach - use `express` instead, Edge runtimes - use `hono` instead, Deno - use `oak` or `fresh` instead
What this skill does
# Fastify Core Knowledge
> **Full Reference**: See [advanced.md](advanced.md) for WebSocket authentication, room management, heartbeat patterns, message validation, and Redis scaling.
> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `fastify` for comprehensive documentation.
## Basic Setup
```ts
import Fastify from 'fastify';
import cors from '@fastify/cors';
const app = Fastify({ logger: true });
await app.register(cors);
await app.register(userRoutes, { prefix: '/api/users' });
app.listen({ port: 3000, host: '0.0.0.0' });
```
## Route with Schema Validation
```ts
import { FastifyPluginAsync } from 'fastify';
import { Type, Static } from '@sinclair/typebox';
const UserSchema = Type.Object({
name: Type.String(),
email: Type.String({ format: 'email' }),
});
type User = Static<typeof UserSchema>;
const routes: FastifyPluginAsync = async (app) => {
app.post<{ Body: User }>('/', {
schema: {
body: UserSchema,
response: { 201: UserSchema }
}
}, async (request, reply) => {
const user = await db.users.create(request.body);
reply.status(201).send(user);
});
};
```
## Plugins
```ts
import fp from 'fastify-plugin';
// Custom plugin with fastify-plugin
export default fp(async (app) => {
app.decorate('db', db);
app.addHook('onRequest', async (request) => {
request.startTime = Date.now();
});
});
app.register(myPlugin);
```
## Error Handling
```ts
import { FastifyError, FastifyReply, FastifyRequest } from 'fastify';
export class AppError extends Error {
constructor(public statusCode: number, message: string) {
super(message);
}
}
app.setErrorHandler((error: FastifyError, request, reply) => {
request.log.error({ err: error }, 'Request error');
if (error.validation) {
return reply.status(400).send({ error: 'Validation failed', details: error.validation });
}
return reply.status(error.statusCode || 500).send({ error: error.message });
});
```
## Health Checks
```ts
app.get('/health', async () => ({ status: 'healthy' }));
app.get('/ready', async (request, reply) => {
try {
await app.pg.query('SELECT 1');
return { status: 'ready', database: 'connected' };
} catch (error) {
reply.status(503);
return { status: 'not ready' };
}
});
```
## Testing
```ts
import { test } from 'vitest';
import { buildApp } from '../src/app';
test('GET /api/users returns users', async () => {
const app = await buildApp();
const response = await app.inject({
method: 'GET',
url: '/api/users',
});
expect(response.statusCode).toBe(200);
await app.close();
});
```
## WebSocket Setup
```ts
import websocket from '@fastify/websocket';
await app.register(websocket);
app.get('/ws', { websocket: true }, (socket, req) => {
socket.on('message', (data) => {
const message = JSON.parse(data.toString());
handleMessage(socket, message);
});
});
```
## When NOT to Use This Skill
- **Enterprise Architecture** - Use NestJS for DI and modular design
- **Simple CRUD APIs** - Use Express if performance is not critical
- **Edge Runtimes** - Use Hono for Cloudflare Workers
- **Deno Projects** - Use Oak or Fresh instead
## Anti-Patterns
| Anti-Pattern | Why It's Bad | Correct Approach |
|--------------|--------------|------------------|
| Not using schema validation | Loses performance advantage | Define schemas for routes |
| Missing `fastify-plugin` wrapper | Encapsulation issues | Use `fp()` for shared plugins |
| Using `app.listen()` in tests | Slow, port conflicts | Use `app.inject()` |
| Ignoring response schema | Slower serialization | Define response schemas |
## Quick Troubleshooting
| Issue | Likely Cause | Solution |
|-------|--------------|----------|
| "Cannot call reply.send twice" | Multiple sends | Return after first `reply.send()` |
| Plugin not accessible | Missing fastify-plugin | Wrap with `fp()` |
| Schema not working | Not registered | Add `schema: {}` to route options |
| Type errors with schemas | Provider missing | Use `withTypeProvider<TypeBoxTypeProvider>()` |
## Production Checklist
- [ ] TypeBox schema validation
- [ ] Helmet security headers
- [ ] Rate limiting configured
- [ ] Structured logging (Pino)
- [ ] Request ID tracing
- [ ] Custom error handler
- [ ] Health/readiness endpoints
- [ ] Graceful shutdown
- [ ] Database connection pooling
## Monitoring Metrics
| Metric | Target |
|--------|--------|
| Response time (p99) | < 50ms |
| Error rate (5xx) | < 0.1% |
| Request throughput | > 10k/s |
## Reference Documentation
- [Schema Validation](quick-ref/schemas.md)
- [Plugins](quick-ref/plugins.md)
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.