Skip to content

luccasfr/fastify-boilerplate

Repository files navigation

Fastify Boilerplate

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

Features

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

Getting Started

  1. Install dependencies:
pnpm install
  1. Configure your environment variables by creating a .env file in the root directory. You can use the provided .env.example as a reference.
cp .env.example .env
  1. Create the database and apply migrations:
pnpm migrate
  1. Enable JWT authentication (optional):
// Uncomment these lines in index.ts to enable authentication:
import authHandler from '@/handlers/authHandler'

fastify.addHook('onRequest', authHandler)
  1. Start the development server:
pnpm dev

Authors

Lucas Ferreira

About

Modern backend API template using Fastify, Zod, and Prisma, providing integrated data validation and self-documentation using Zod-type-provider

Topics

Resources

Stars

Watchers

Forks

Contributors