Fastify best practices skill
93
97%
Does it follow best practices?
Impact
85%
1.37xAverage score across 4 eval scenarios
Passed
No known issues
Minimal server:
import Fastify from 'fastify'
const app = Fastify({ logger: true })
app.get('/health', async () => ({ status: 'ok' }))
await app.listen({ port: 3000, host: '0.0.0.0' })Plugin with shared decorators via fastify-plugin (escapes encapsulation):
import fp from 'fastify-plugin'
export default fp(async function dbPlugin(app, options) {
const db = await createConnection(options.connectionString)
app.decorate('db', db)
app.addHook('onClose', async () => db.close())
}, { name: 'db-plugin' })Route with TypeBox schema validation (preferred over raw JSON Schema):
import { Type, type Static } from '@sinclair/typebox'
const Body = Type.Object({ name: Type.String({ minLength: 1 }) })
type BodyType = Static<typeof Body>
app.post<{ Body: BodyType }>('/users', {
schema: { body: Body, response: { 201: Type.Object({ id: Type.String() }) } }
}, async (request, reply) => {
reply.code(201)
return { id: await createUser(request.body) }
})plugins.md → routes.md → schemas.mdplugins.md → hooks.md → authentication.mdschemas.md → serialization.md → performance.mdroutes.md → testing.mdlogging.md → configuration.md → deployment.mdRead individual rule files for detailed explanations and code examples: