https://github.com/ibnabdullah1/fastify-prisma-starter
Production-ready Node.js Fastify Prisma starter for REST API with authentication, Docker, and TypeScript
https://github.com/ibnabdullah1/fastify-prisma-starter
authentication backend clean-architecture docker fastify fastify-prisma fastify-starter jwt-auth nodejs nodejs-api prisma prisma-starter rest-api scaffold starter starter-template typescript
Last synced: 9 days ago
JSON representation
Production-ready Node.js Fastify Prisma starter for REST API with authentication, Docker, and TypeScript
- Host: GitHub
- URL: https://github.com/ibnabdullah1/fastify-prisma-starter
- Owner: ibnabdullah1
- Created: 2025-12-15T04:25:16.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-12-15T06:23:34.000Z (3 months ago)
- Last Synced: 2026-01-13T19:36:59.943Z (2 months ago)
- Topics: authentication, backend, clean-architecture, docker, fastify, fastify-prisma, fastify-starter, jwt-auth, nodejs, nodejs-api, prisma, prisma-starter, rest-api, scaffold, starter, starter-template, typescript
- Language: TypeScript
- Homepage:
- Size: 452 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: DOCS/CONTRIBUTING.md
Awesome Lists containing this project
README
# Node.js Fastify Prisma Starter
**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.
## Why this Fastify Prisma starter?
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.
## ๐ Features
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
## ๐ Prerequisites
- **Node.js** (v16 or higher)
- **npm** or **yarn** package manager
- **PostgreSQL** database
- **Git**
## โก Getting Started with Node.js Fastify Prisma Boilerplate
### 1. Clone the Repository
```bash
git clone https://github.com/ibnabdullah1/nodejs-fastify-prisma-starter.git
cd nodejs-fastify-prisma-starter
```
### 2. Install Dependencies
```bash
npm install
```
### 3. Environment Setup
```bash
# Copy environment template
cp env.example .env
# Edit .env with your configuration
nano .env
```
### 4. Database Setup
```bash
# Generate Prisma client
npm run db:generate
# Run database migrations
npm run migrate
# (Optional) Seed the database
npm run db:seed
```
### 5. Start Development Server
```bash
npm run dev
```
Your server will be running at `http://localhost:5000`
## ๐ ๏ธ Available Scripts
### Development
- `npm run dev` - Start development server with hot reload
- `npm run build` - Build the project for production
- `npm run start` - Start production server
### Database
- `npm run migrate` - Run database migrations
- `npm run migrate:deploy` - Deploy migrations to production
- `npm run migrate:reset` - Reset database
- `npm run db:studio` - Open Prisma Studio
- `npm run db:generate` - Generate Prisma client
- `npm run db:seed` - Seed database with sample data
### Code Quality
- `npm run lint` - Run ESLint
- `npm run lint:fix` - Fix ESLint errors
- `npm run format` - Format code with Prettier
- `npm run type-check` - Run TypeScript type checking
### Module Scripts
- `npm run create-module ` - Create a new module with complete structure
- `npm run rename-module ` - Rename an existing module and update all references
### Testing
- `npm test` - Run tests
- `npm run test:watch` - Run tests in watch mode
- `npm run test:coverage` - Run tests with coverage
### Docker
- `npm run docker:build` - Build Docker image
- `npm run docker:run` - Run Docker container
- `npm run docker:compose` - Start with docker-compose
## ๐ Project Structure
```
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
```
## ๐ง Configuration
### Environment Variables
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
### Database Schema
The template includes the following models:
- **User**: User authentication and profile management
- **Media**: File upload and metadata storage
## ๐ ๏ธ Module Generation
This **Fastify Prisma starter template for Node.js** includes powerful scripts to quickly generate and manage modules with clean architecture patterns.
### Create a New Module
Generate a complete module structure with all necessary files:
```bash
npm run create-module
# Examples:
npm run create-module product
npm run create-module order
npm run create-module category
```
**Generated Files:**
- `module.routes.ts` - Fastify plugin routes with authentication
- `module.controller.ts` - Request handlers (FastifyRequest/FastifyReply)
- `module.service.ts` - Business logic with Prisma
- `module.interface.ts` - TypeScript interfaces
- `module.validation.ts` - Zod validation schemas
- `module.constant.ts` - Module constants
**After creating a module:**
1. **Register routes** in `src/app/routes/index.ts`:
```typescript
import { ProductRoutes } from "../modules/product/product.routes";
const router = async (fastify: FastifyInstance) => {
fastify.register(ProductRoutes, { prefix: "/product" });
};
```
2. **Update Prisma schema** (`prisma/schema.prisma`):
```prisma
model Product {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
```
3. **Run migrations**:
```bash
npm run migrate
```
### Rename a Module
Rename an existing module and update all references:
```bash
npm run rename-module
# Examples:
npm run rename-module product item
npm run rename-module order purchase
```
**What 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
## ๐ Deployment
### Docker Deployment
```bash
# Build and start with docker-compose
npm run docker:compose
# Or build and run manually
npm run docker:build
npm run docker:run
```
### Manual Deployment
1. **Build the application**:
```bash
npm run build
```
2. **Set up production environment**:
```bash
cp env.example .env
# Configure production environment variables
```
3. **Run database migrations**:
```bash
npm run migrate:deploy
```
4. **Start the application**:
```bash
npm start
```
## ๐ Documentation
Comprehensive documentation is available in the `DOCS/` directory:
- **[Quick Start Guide](./DOCS/QUICK_START.md)** - Get started in 5 minutes
- **[API Documentation](./DOCS/API_DOCUMENTATION.md)** - Complete API reference
- **[Project Structure](./DOCS/PROJECT_STRUCTURE.md)** - Detailed project organization
- **[Deployment Guide](./DOCS/DEPLOYMENT_GUIDE.md)** - Production deployment
- **[Troubleshooting](./DOCS/TROUBLESHOOTING.md)** - Common issues and solutions
## ๐งช Testing
```bash
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
```
## ๐ Code Quality
The project includes:
- **ESLint** for code linting
- **Prettier** for code formatting
- **Husky** for git hooks
- **lint-staged** for pre-commit checks
## ๐ค Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request
See [Contributing Guide](./DOCS/CONTRIBUTING.md) for detailed information.
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ๐ Support
- **Documentation**: Check the `DOCS/` directory
- **Issues**: Create an issue on GitHub
- **Discussions**: Use GitHub Discussions for questions
## ๐ Acknowledgments
- [Fastify](https://fastify.dev/) - Web framework
- [Prisma](https://www.prisma.io/) - Database ORM
- [TypeScript](https://www.typescriptlang.org/) - Type safety
- [PostgreSQL](https://www.postgresql.org/) - Database
---
**Happy Coding! ๐**