StartXKit docs
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/repository

Optional Features

FeatureWhat it adds
CORS@fastify/cors and src/config/cors.ts
Env configdotenv and src/config/env.ts
Error handlerapp.setErrorHandler(...) and shared error files
LoggerFastify logger enabled when requested
Zod validationzod dependency and validator-ready module files
Vitesttest 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.