-
Notifications
You must be signed in to change notification settings - Fork 4
Fastify
Francois edited this page Jan 4, 2026
·
2 revisions
Fastify is a web framework for Node.js
Key advantages for our project are
- performance : handles up to 30 000 requests per second
- modularity : extensible via hooks, plugins, decorator
- type safety : TS integration and built-in support for JSON schema validation
npm install fastify fastify-type-provider-zod zod
npm install --save-dev @types/node typescriptNote
Fastify uses an encapsulation model. Plugins registered inside a context (scope) are not visible to parents or siblings unless wrapped with fastify-plugin.
- requires
fastify-type-provider-zod
Tip
Use shared @transcendence/core shemas and DTOs to have single source of truth between exposed API and their consumers
Tip
Use fastify.printRoutes() in development to visualize your entire routing tree and debug 404 errors.
| โ Do | โ Don't |
|---|---|
Encapsulate plugins: Use fastify-plugin (or fp) to break encapsulation when registering shared plugins (Db, Auth) so they are available globally. |
Register every plugin without fastify-plugin; this isolates them to the current scope/file, often breaking dependency chains. |
Use Zod Schemas: Define validation schemas for every route (body, querystring, params). |
Manually validate data inside the handler function (e.g., if (!req.body.name)...). |
Use Hooks for Logic: Use onRequest or preHandler for authentication and logging. |
Put authentication logic directly inside every single route handler. |
Await Plugins: Always use await fastify.register(...) to ensure plugins load in order. |
Forget await during registration, which leads to race conditions at startup. |
| Throw Errors: Throw standard Error objects; Fastify catches them and sends 500 (or custom codes). | Send manual 500 responses (res.code(500).send(...)) for unexpected crashes; let the framework handle it. |
| Type | Resource | Notes |
|---|---|---|
| ๐ | Fastify Documentation | Official Reference |
| ๐ฆ | fastify-type-provider-zod | Zod integration docs |
| ๐ฅ | Fastify Project structure | - |
| ๐ป | Awesome Fastify | - |
- Gateway Service - API Gateway & JWT validation
- Auth Service - Authentication & 2FA/TOTP
- AI Service - AI opponent
- API Documentation - OpenAPI/Swagger
- Fastify - Web framework
- Prisma - ORM
- WebSockets - Real-time communication
- Restful API - API standards
- React - UI library
- CSS - Styling
- Tailwind - CSS framework
- Accessibility - WCAG compliance
- TypeScript - Language
- Zod - Schema validation
- Nginx - Reverse proxy
- Logging and Error management - Observability
- OAuth 2.0 - Authentication flows
- Two-factor authentication - 2FA/TOTP
- Avalanche - Blockchain network
- Hardhat - Development framework
- Solidity - Smart contracts language
- Open Zeppelin - Security standards
- ESLint - Linting
- Vitest - Testing
- GitHub Actions - CI/CD
- Husky, Commit lints and git hooks - Git hooks
- ELK - Logging stack
๐ Page model