
A modern, feature-rich boilerplate for building APIs with Fastify 5.
What's new compared to the previous version?
- Upgraded packages to the latest versions (including Fastify 5, ESLint 9, Prisma 6, and preparing for Zod 4)
- Removed JEST and tests (can be added as needed)
- Removed Husky and pre-commit hooks (can be added as needed)
- Switched back to pnpm as the package manager for better stability and broader adoption
- Improved error handling with Prisma's most common errors
- Added JSDoc comments throughout the codebase for better documentation
This boilerplate includes:
- Fastify - High-performance web framework
- Fastify Swagger - OpenAPI documentation
- Fastify CORS - Cross-Origin Resource Sharing plugin with an environment-based allowlist
- Fastify JWT - JSON Web Token authentication
- Pino & Pino Pretty - High-performance logging
- Prisma - Modern database ORM
- Zod - Schema validation
- Zod Type Provider - TypeScript integration
- Custom Error Handler - Comprehensive error handling
- Install dependencies:
- Configure your environment variables by creating a
.env file in the root directory. You can use the provided .env.example as a reference.
- Create the database and apply migrations:
- Configure browser origins allowed to call the API:
CORS_ORIGINS="http://localhost:3000,https://app.example.com"
CORS_ORIGINS is required when NODE_ENV=production.
- Authenticate protected routes:
All routes except /health and /docs require a Bearer JWT signed with JWT_SECRET.
- Start the development server: