A modern, feature-rich boilerplate for building APIs with Fastify 5.
- 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
- 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:
pnpm install- Configure your environment variables by creating a
.envfile in the root directory. You can use the provided.env.exampleas a reference.
cp .env.example .env- Create the database and apply migrations:
pnpm migrate- Enable JWT authentication (optional):
// Uncomment these lines in index.ts to enable authentication:
import authHandler from '@/handlers/authHandler'
fastify.addHook('onRequest', authHandler)- Start the development server:
pnpm dev
Lucas Ferreira |
