This skill provides comprehensive guidance for developing Fastify backends using TypeScript. It covers essential topics like plugins, route organization, and production deployment, making it suitable for Node.js developers.
$ npx skills add https://github.com/mcollina/skills --skill fastify-best-practicesThe fastify skill provides comprehensive best practices for developing Fastify backends with guidance on plugins, route organization, and production deployment. It targets Node.js developers building scalable server applications who need structured patterns and proven approaches. This skill covers essential Fastify development workflows, helping teams establish consistent practices across their backend codebases. By following these best practices, developers can improve code maintainability, optimize performance, and prepare applications for production environments more effectively.
Install the skill using the command: `$ npx skills add https://github.com/mcollina/skills --skill fastify-best-practices`
Develop backend applications using Fastify
Implement Fastify plugins and route handlers
Get guidance on Fastify architecture and patterns
Use TypeScript with Fastify
$ npx skills add https://github.com/mcollina/skills --skill fastify-best-practicesgit clone https://github.com/mcollina/skillsCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Generate a Fastify backend in TypeScript following best practices for [COMPANY]. Use [INDUSTRY] standards and integrate with [DATA SOURCE]. Follow Fastify's plugin system, TypeScript typing, and production-ready patterns.
# Fastify Backend for Acme Corp (E-commerce)
## Project Structure
```
/src
├── routes/
│ ├── products.ts
│ ├── orders.ts
│ └── auth.ts
├── plugins/
│ ├── db.ts
│ ├── logger.ts
│ └── auth.ts
├── types/
│ └── schemas.ts
└── server.ts
```
## Key Features
### 1. Type-Safe Routes
```typescript
// routes/products.ts
import { FastifyPluginAsync } from 'fastify'
import { ProductSchema } from '../types/schemas'
const productRoutes: FastifyPluginAsync = async (fastify) => {
fastify.get('/', {
schema: {
response: {
200: ProductSchema
}
}
}, async (request, reply) => {
return { id: '123', name: 'Wireless Headphones', price: 99.99 }
})
}
```
### 2. Plugin System
```typescript
// plugins/db.ts
import fp from 'fastify-plugin'
import { FastifyPluginAsync } from 'fastify'
import mongoose from 'mongoose'
const dbPlugin: FastifyPluginAsync = async (fastify) => {
await mongoose.connect(process.env.MONGODB_URI!)
fastify.decorate('db', mongoose.connection)
}
export default fp(dbPlugin)
```
### 3. Production Config
```typescript
// server.ts
import fastify from 'fastify'
import dbPlugin from './plugins/db'
const server = fastify({
logger: true,
trustProxy: true,
ignoreTrailingSlash: true
})
await server.register(dbPlugin)
server.listen({ port: 3000, host: '0.0.0.0' })
```
## Deployment Notes
- Use PM2 for process management
- Configure environment variables via `.env`
- Enable HTTPS with Let's Encrypt
- Set up health checks at `/health`
- Implement request logging with WinstonTake a free 3-minute scan and get personalized AI skill recommendations.
Take free scan