fastify-best-practices

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

When to use

适用场景

Use this skill when you need to:
  • Develop backend applications using Fastify
  • Implement Fastify plugins and route handlers
  • Get guidance on Fastify architecture and patterns
  • Use TypeScript with Fastify (strip types)
  • Implement testing with Fastify's inject method
  • Configure validation, serialization, and error handling
在以下场景中可使用本技能:
  • 使用Fastify开发后端应用
  • 实现Fastify插件和路由处理器
  • 获取Fastify架构与设计模式指导
  • 在Fastify中结合TypeScript使用(剥离类型)
  • 使用Fastify的inject方法实现测试
  • 配置验证、序列化与错误处理

How to use

使用方法

Read individual rule files for detailed explanations and code examples:
  • rules/plugins.md - Plugin development and encapsulation
  • rules/routes.md - Route organization and handlers
  • rules/schemas.md - JSON Schema validation
  • rules/error-handling.md - Error handling patterns
  • rules/hooks.md - Hooks and request lifecycle
  • rules/authentication.md - Authentication and authorization
  • rules/testing.md - Testing with inject()
  • rules/performance.md - Performance optimization
  • rules/logging.md - Logging with Pino
  • rules/typescript.md - TypeScript integration
  • rules/decorators.md - Decorators and extensions
  • rules/content-type.md - Content type parsing
  • rules/serialization.md - Response serialization
  • rules/cors-security.md - CORS and security headers
  • rules/websockets.md - WebSocket support
  • rules/database.md - Database integration patterns
  • rules/configuration.md - Application configuration
  • rules/deployment.md - Production deployment
  • rules/http-proxy.md - HTTP proxying and reply.from()
阅读单个规则文件获取详细说明与代码示例:
  • rules/plugins.md - 插件开发与封装
  • rules/routes.md - 路由组织与处理器
  • rules/schemas.md - JSON Schema验证
  • rules/error-handling.md - 错误处理模式
  • rules/hooks.md - 钩子与请求生命周期
  • rules/authentication.md - 身份认证与授权
  • rules/testing.md - 使用inject()进行测试
  • rules/performance.md - 性能优化
  • rules/logging.md - 结合Pino实现日志
  • rules/typescript.md - TypeScript集成
  • rules/decorators.md - 装饰器与扩展
  • rules/content-type.md - 内容类型解析
  • rules/serialization.md - 响应序列化
  • rules/cors-security.md - CORS与安全头
  • rules/websockets.md - WebSocket支持
  • rules/database.md - 数据库集成模式
  • rules/configuration.md - 应用配置
  • rules/deployment.md - 生产环境部署
  • rules/http-proxy.md - HTTP代理与reply.from()

Core Principles

核心原则

  • Encapsulation: Fastify's plugin system provides automatic encapsulation
  • Schema-first: Define schemas for validation and serialization
  • Performance: Fastify is optimized for speed; use its features correctly
  • Async/await: All handlers and hooks support async functions
  • Minimal dependencies: Prefer Fastify's built-in features and official plugins
  • 封装性:Fastify的插件系统提供自动封装机制
  • 优先定义Schema:为验证和序列化定义Schema
  • 性能优先:Fastify针对速度进行了优化;请正确使用其功能
  • Async/await:所有处理器和钩子均支持异步函数
  • 最小依赖:优先使用Fastify的内置功能和官方插件