Production-ready Node.js Fastify Prisma starter for building scalable REST APIs with TypeScript, PostgreSQL, and modern development practices. A clean architecture Fastify Prisma boilerplate with JWT authentication, Docker support, and comprehensive documentation.
This Node.js Fastify Prisma starter template provides everything you need to build production-ready REST APIs quickly. Built with Fastify (high-performance web framework), Prisma ORM (type-safe database access), and TypeScript for a robust development experience.
This Fastify Prisma TypeScript starter includes:
- π§ Tech Stack: Node.js, Fastify, TypeScript, PostgreSQL, Prisma ORM
- π Authentication: JWT-based authentication with refresh tokens (Fastify Prisma authentication starter)
- π₯ User Management: Complete user CRUD with role-based access control
- π File Upload: Cloudinary integration for media management
- π§ Email Service: Nodemailer integration for email functionality
- π‘οΈ Security: Helmet, CORS, rate limiting, input validation
- π Database: PostgreSQL with Prisma ORM for type-safe operations
- π§ͺ Testing: Jest setup with coverage reporting
- π Code Quality: ESLint, Prettier, Husky for code standards
- π³ Docker: Dockerized Fastify Prisma starter with docker-compose
- π Documentation: Comprehensive documentation and API reference
- π CI/CD Ready: GitHub Actions workflow templates
- β‘ Module Generation: Automated module creation and renaming scripts
- Node.js (v16 or higher)
- npm or yarn package manager
- PostgreSQL database
- Git
git clone https://github.com/ibnabdullah1/nodejs-fastify-prisma-starter.git
cd nodejs-fastify-prisma-starternpm install# Copy environment template
cp env.example .env
# Edit .env with your configuration
nano .env# Generate Prisma client
npm run db:generate
# Run database migrations
npm run migrate
# (Optional) Seed the database
npm run db:seednpm run devYour server will be running at http://localhost:5000
npm run dev- Start development server with hot reloadnpm run build- Build the project for productionnpm run start- Start production server
npm run migrate- Run database migrationsnpm run migrate:deploy- Deploy migrations to productionnpm run migrate:reset- Reset databasenpm run db:studio- Open Prisma Studionpm run db:generate- Generate Prisma clientnpm run db:seed- Seed database with sample data
npm run lint- Run ESLintnpm run lint:fix- Fix ESLint errorsnpm run format- Format code with Prettiernpm run type-check- Run TypeScript type checking
npm run create-module <name>- Create a new module with complete structurenpm run rename-module <old> <new>- Rename an existing module and update all references
npm test- Run testsnpm run test:watch- Run tests in watch modenpm run test:coverage- Run tests with coverage
npm run docker:build- Build Docker imagenpm run docker:run- Run Docker containernpm run docker:compose- Start with docker-compose
src/
βββ controllers/ # Request handlers
βββ services/ # Business logic
βββ models/ # Data models
βββ middleware/ # fastify middleware
βββ utils/ # Utility functions
βββ types/ # TypeScript type definitions
βββ constants/ # Application constants
βββ validators/ # Request validation schemas
βββ database/ # Database configuration
βββ routes/ # Route definitions
βββ config/ # Configuration files
βββ scripts/ # Utility scripts
βββ templates/ # Email templates
βββ tests/ # Test files
βββ app.ts # fastify app configuration
βββ server.ts # Server entry point
See env.example for all available environment variables:
- Database: PostgreSQL connection string
- JWT: Authentication secrets and expiration times
- Email: SMTP configuration for email sending
- Cloudinary: File upload and storage
- Security: CORS, rate limiting, and other security settings
The template includes the following models:
- User: User authentication and profile management
- Media: File upload and metadata storage
This Fastify Prisma starter template for Node.js includes powerful scripts to quickly generate and manage modules with clean architecture patterns.
Generate a complete module structure with all necessary files:
npm run create-module <module-name>
# Examples:
npm run create-module product
npm run create-module order
npm run create-module categoryGenerated Files:
module.routes.ts- Fastify plugin routes with authenticationmodule.controller.ts- Request handlers (FastifyRequest/FastifyReply)module.service.ts- Business logic with Prismamodule.interface.ts- TypeScript interfacesmodule.validation.ts- Zod validation schemasmodule.constant.ts- Module constants
After creating a module:
- Register routes in
src/app/routes/index.ts:
import { ProductRoutes } from "../modules/product/product.routes";
const router = async (fastify: FastifyInstance) => {
fastify.register(ProductRoutes, { prefix: "/product" });
};- Update Prisma schema (
prisma/schema.prisma):
model Product {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}- Run migrations:
npm run migrateRename an existing module and update all references:
npm run rename-module <old-name> <new-name>
# Examples:
npm run rename-module product item
npm run rename-module order purchaseWhat it does:
- Renames the module directory
- Updates all file contents (lowercase and capitalized names)
- Renames files if they contain the module name
- Updates all references throughout the codebase
Important: After renaming, manually update:
- Route registrations in
src/app/routes/index.ts - Prisma schema if needed
- Any other external references
# Build and start with docker-compose
npm run docker:compose
# Or build and run manually
npm run docker:build
npm run docker:run-
Build the application:
npm run build
-
Set up production environment:
cp env.example .env # Configure production environment variables -
Run database migrations:
npm run migrate:deploy
-
Start the application:
npm start
Comprehensive documentation is available in the DOCS/ directory:
- Quick Start Guide - Get started in 5 minutes
- API Documentation - Complete API reference
- Project Structure - Detailed project organization
- Deployment Guide - Production deployment
- Troubleshooting - Common issues and solutions
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverageThe project includes:
- ESLint for code linting
- Prettier for code formatting
- Husky for git hooks
- lint-staged for pre-commit checks
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
See Contributing Guide for detailed information.
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Check the
DOCS/directory - Issues: Create an issue on GitHub
- Discussions: Use GitHub Discussions for questions
- Fastify - Web framework
- Prisma - Database ORM
- TypeScript - Type safety
- PostgreSQL - Database
Happy Coding! π