Frameworks
Fastify
Generate Fastify APIs with plugin-style route registration and strong performance defaults.
Fastify is a high-performance Node.js framework with a plugin-oriented design. It is a good choice when you want fast request handling and a structured way to register route groups.
Choose Fastify When
- Performance matters
- You like plugin-style route registration
- You want built-in structured logging support
- You want a framework that ships its own TypeScript types
Generated Entry Point
Fastify projects generate a src/server.ts file that creates the app, registers optional features, mounts routes, and starts the server.
src/
server.ts
routes/ or modules/
config/
shared/Route Example
import type { FastifyInstance } from "fastify";
import { UsersController } from "./users.controller";
export async function usersRoutes(app: FastifyInstance) {
app.get("/", UsersController.getAll);
app.post("/", UsersController.create);
app.get("/:id", UsersController.getById);
app.patch("/:id", UsersController.update);
app.delete("/:id", UsersController.remove);
}The server registers the route group with a prefix:
app.register(usersRoutes, { prefix: "/api/v1/users" });Request Flow
request
|
v
Fastify app
|
v
registered route plugin
|
v
controller
|
v
optional service/repositoryOptional Features
| Feature | What it adds |
|---|---|
| CORS | @fastify/cors and src/config/cors.ts |
| Env config | dotenv and src/config/env.ts |
| Error handler | app.setErrorHandler(...) and shared error files |
| Logger | Fastify logger enabled when requested |
| Zod validation | zod dependency and validator-ready module files |
| Vitest | test script and vitest dependency |
Architecture Notes
- Minimal Fastify projects use route files with inline handlers.
- Modular Fastify projects use
src/modules/{feature}. - Layered Fastify projects use top-level route, controller, service, repository, interface, and validator folders.