A modern Node.js boilerplate configured with Fastify, TypeScript, Prisma ORM, and PostgreSQL. Provides a solid foundation for building scalable and well-structured backend applications.
- Fastify (v5.7.4) - Fast and efficient web framework
- TypeScript - Static typing for safety
- Prisma (v7.4.2) - Modern ORM for PostgreSQL
- PostgreSQL (v15) - Relational database
- Docker & Docker Compose - Containerization
- Swagger/OpenAPI - Automatic API documentation
- Node.js >= 20.x
- npm >= 10.x
- PostgreSQL >= 15.x
- Docker
- Docker Compose
git clone <your-repo>
cd node-boilerplatenpm installCreate a .env file in the project root:
DATABASE_URL="postgresql://user:password@localhost:5432/appdb?schema=public"
PORT=3000
NODE_ENV=developmentExample with default PostgreSQL:
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/appdb?schema=public"
PORT=3000
NODE_ENV=development# Generate Prisma client
npm run prisma:generate
# Run migrations
npm run prisma:migrate# Development mode (watch)
npm run dev
# Server will be available at http://localhost:3000git clone <your-repo>
cd node-boilerplatedocker-compose up -dThis will start:
- API at
http://localhost:3000 - PostgreSQL at
localhost:5432
docker-compose ps
# View API logs
docker-compose logs -f api
# View database logs
docker-compose logs -f dbdocker-compose down
# With data volume
docker-compose down -v # Removes the databasenode-boilerplate/
βββ src/
β βββ app.ts # Main Fastify configuration
β βββ server.ts # Server entry point
β βββ config/
β β βββ env.ts # Environment variables config
β βββ hooks/
β β βββ error-handler.ts # Global error handling
β βββ modules/
β β βββ user/ # User module
β β βββ user.controller.ts
β β βββ user.routes.ts
β β βββ user.service.ts
β β βββ user.repository.ts
β β βββ user.schema.ts
β β βββ user.types.ts
β βββ plugins/
β β βββ prisma.ts # Prisma plugin
β β βββ swagger.ts # Swagger/OpenAPI config
β βββ types/
β β βββ fastify.d.ts # Extended Fastify types
β βββ utils/
β βββ errors.ts # Error utilities
βββ prisma/
β βββ schema.prisma # Database schema
β βββ migrations/ # Migration history
βββ docker-compose.yml # Container orchestration
βββ Dockerfile # Docker image build
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ .env # Environment variables (don't commit)
# Development
npm run dev # Start server in watch mode
# Build
npm run build # Compile TypeScript to JavaScript
# Production
npm start # Run compiled application
# Prisma
npm run prisma:generate # Generate Prisma client
npm run prisma:migrate # Run migrations (development)
npm run prisma:deploy # Run migrations (production)The project comes with a basic User model:
model User {
id String @id @default(uuid())
email String @unique
name String
}After modifying prisma/schema.prisma:
npm run prisma:migrateThis will:
- Detect changes in the schema
- Create a new migration
- Apply changes to the database
Visual interface for managing data:
npx prisma studioOpens at http://localhost:5555
GET /users- List all usersGET /users/:id- Get a userPOST /users- Create a userPUT /users/:id- Update a userDELETE /users/:id- Delete a user
Interactive documentation available at:
http://localhost:3000/documentation
npm run build
npm start# Manual build
docker build -t node-boilerplate .
# Run
docker run -p 3000:3000 \
-e DATABASE_URL="postgresql://user:pass@host:5432/db?schema=public" \
node-boilerplate
# Or with Docker Compose
docker-compose -f docker-compose.yml up -dMake sure to configure:
DATABASE_URL- PostgreSQL connectionPORT- Port (default: 3000)NODE_ENV-production
-
Create folder in
src/modules/<module-name>/ -
Create files:
<name>.types.ts- Types/Interfaces<name>.schema.ts- Validation schemas (TypeBox)<name>.repository.ts- Database access (Prisma)<name>.service.ts- Business logic<name>.controller.ts- HTTP handlers<name>.routes.ts- Route definitions
-
Register in
src/app.ts:
await app.register(myModuleRoutes, { prefix: "/my-route" })# Verify PostgreSQL is running
# If using Docker:
docker-compose ps
# If local, restart PostgreSQL and verify DATABASE_URL# Reset database (β οΈ Deletes data)
npx prisma migrate reset
# Or sync the schema
npx prisma db pushChange in .env:
PORT=3001ISC
Need help? Check the official project documentation or open an issue in the repository.