π A production-ready starter template with NestJS, TypeScript, Prisma, and comprehensive development tools
A production-ready NestJS starter template with TypeScript, Prisma, and comprehensive development tools. Built for modern web applications with best practices, automated quality checks, and complete CI/CD pipeline.
- π NestJS - Progressive Node.js framework
- π· TypeScript - Type-safe development
- ποΈ Prisma - Modern database toolkit with PostgreSQL/MySQL/SQLite support
- π Swagger/OpenAPI - Auto-generated API documentation
- π¨ Prettier - Code formatting
- π ESLint - Code linting with TypeScript support
- π Husky - Git hooks for automated quality checks
- π Commitlint - Conventional commit message linting
- π Lint-staged - Run linters on staged files
- β‘ pnpm - Fast, disk space efficient package manager
- π§ VSCode - Pre-configured settings and extensions
- π§ͺ Jest - Testing framework with E2E tests
- π GitHub Actions - Comprehensive CI/CD pipeline
- π³ Docker - Container support
- Node.js (v18 or higher)
- pnpm (v8 or higher)
- Database (PostgreSQL/MySQL/SQLite)
-
Clone the repository:
git clone https://github.com/dzikrisyairozi/nest-ts-prisma-starter.git cd nest-ts-prisma-starter
-
Install dependencies:
pnpm install
-
Set up environment:
cp env.example .env # Edit .env with your database configuration
-
Set up database:
# Generate Prisma client pnpm run db:generate # Push schema to database pnpm run db:push # Seed with example data (optional) pnpm run db:seed
-
Start development:
# Development mode with hot reload pnpm run start:dev
-
Access the application:
- API: http://localhost:3000
- Swagger UI: http://localhost:3000/api
# Production build
pnpm run build
# Production mode
pnpm run start:prod
# Development mode
pnpm run start:dev
## Run tests
```bash
# unit tests
$ pnpm run test
# e2e tests
$ pnpm run test:e2e
# test coverage
$ pnpm run test:cov
This starter includes a complete Prisma setup with PostgreSQL as the default database. You can easily switch to other databases.
-
Create a database (PostgreSQL, MySQL, or SQLite)
-
Copy environment file:
cp .env.example .env
-
Update DATABASE_URL in
.env
:# PostgreSQL (recommended) DATABASE_URL="postgresql://username:password@localhost:5432/nest_starter?schema=public" # MySQL DATABASE_URL="mysql://username:password@localhost:3306/nest_starter" # SQLite (for development) DATABASE_URL="file:./dev.db"
# Generate Prisma client
$ pnpm run db:generate
# Push schema changes to database (for prototyping)
$ pnpm run db:push
# Create and run migrations (for production)
$ pnpm run db:migrate
# Open Prisma Studio (database GUI)
$ pnpm run db:studio
# Seed database with example data
$ pnpm run db:seed
# Reset database (β οΈ deletes all data)
$ pnpm run db:reset
The starter includes example User
and Post
models with relationships:
// Example usage in a service
async findUsers() {
return this.prisma.user.findMany({
include: {
posts: true,
},
});
}
See src/users/users.service.ts
for complete CRUD examples.
- Edit
prisma/schema.prisma
- Add your models (follow the examples)
- Generate client:
pnpm run db:generate
- Create migration:
pnpm run db:migrate
This starter includes a comprehensive Swagger OpenAPI setup for automatic API documentation generation.
- Swagger UI: http://localhost:3000/api (when running locally)
- OpenAPI JSON: http://localhost:3000/api-json
- π Automatic Documentation: All endpoints are automatically documented
- π₯οΈ Interactive UI: Test APIs directly from the browser
- π Authentication Support: JWT Bearer token and API Key authentication
- π Response Examples: Comprehensive examples for all responses
- β Validation Integration: DTOs with validation automatically documented
- π Multi-Environment: Adapts to development, staging, and production
// Controller with Swagger decorators
@ApiTags('Users')
@ApiBearerAuth('JWT-auth')
@Controller('users')
export class UsersController {
@Post()
@ApiOperation({ summary: 'Create a new user' })
@ApiCreatedResponse({ type: UserResponseDto })
create(@Body() createUserDto: CreateUserDto) {
return this.usersService.create(createUserDto);
}
}
// DTO with validation and documentation
export class CreateUserDto {
@ApiProperty({
description: 'User email address',
example: 'dzikri@syairozi.com',
format: 'email',
})
@IsEmail()
email: string;
@ApiProperty({
description: 'User full name',
example: 'Dzikri Syairozi',
minLength: 2,
maxLength: 100,
})
@IsString()
@MinLength(2)
@MaxLength(100)
name: string;
}
- Start the application:
pnpm run start:dev
- Open http://localhost:3000/api in your browser
- Explore the Users API endpoints
- Click "Authorize" to test protected endpoints
- Try the example requests with provided data
For detailed documentation, examples, and customization guide, see docs/SWAGGER.md.
# Format code with Prettier
$ pnpm run format
# Check formatting without fixing
$ pnpm run format:check
# Lint and fix code with ESLint
$ pnpm run lint
# Check linting without fixing
$ pnpm run lint:check
# Type checking
$ pnpm run type-check
This project includes several automated git hooks:
- commit-msg: Validates commit messages using commitlint
- pre-commit: Runs lint-staged (formatting and linting on staged files)
- pre-push: Runs type checking, linting, and tests before pushing
- post-merge: Automatically installs dependencies if package files changed
This project follows the Conventional Commits specification:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Types:
feat
: A new featurefix
: A bug fixdocs
: Documentation only changesstyle
: Changes that do not affect the meaning of the coderefactor
: A code change that neither fixes a bug nor adds a featuretest
: Adding missing tests or correcting existing testschore
: Changes to the build process or auxiliary toolsperf
: A code change that improves performanceci
: Changes to CI configuration files and scriptsbuild
: Changes that affect the build system or external dependenciesrevert
: Reverts a previous commit
Examples:
feat: add user authentication
fix: resolve memory leak in data processing
docs: update API documentation
This project includes a comprehensive CI/CD pipeline using GitHub Actions:
- Triggers: Push to main branch, Pull requests
- All-in-One: Quality checks, testing, security, build, and deploy in single job
- Quality Checks: Type checking, linting, formatting validation
- Testing: Unit tests, E2E tests, coverage reports
- Security: Dependency audit, CodeQL analysis
- Build: Application build and artifact upload
- Deploy: Staging and production deployments
- Triggers: Git tags (v*)
- Automated Releases: GitHub releases with changelogs
- Docker Images: Container builds for deployment
- Production Deploy: Automatic production deployment
- Weekly Updates: Single PR per week with all updates
- Comprehensive: All dependencies updated together
- Security Updates: Automatic security patches
- CodeQL security scanning
- Dependency vulnerability checks
- Branch protection rules
- Environment-based deployments with approvals
- Test coverage reports (Codecov integration)
- Slack notifications for deployments
- Build status badges
- Performance tracking
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the deployment documentation for more information.
If you are looking for a cloud-based platform to deploy your NestJS application, check out Mau, our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
$ pnpm install -g mau
$ mau deploy
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
Check out a few resources that may come in handy when working with NestJS:
- Visit the NestJS Documentation to learn more about the framework.
- For questions and support, please visit our Discord channel.
- To dive deeper and get more hands-on experience, check out our official video courses.
- Deploy your application to AWS with the help of NestJS Mau in just a few clicks.
- Visualize your application graph and interact with the NestJS application in real-time using NestJS Devtools.
- Need help with your project (part-time to full-time)? Check out our official enterprise support.
- To stay in the loop and get updates, follow us on X and LinkedIn.
- Looking for a job, or have a job to offer? Check out our official Jobs board.
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
We welcome contributions! Please see our Contributing Guide for details on:
- π Reporting bugs
- π‘ Suggesting enhancements
- π Submitting pull requests
- π Improving documentation
Thanks to all the amazing contributors who help make this project better! π
This project is licensed under the MIT License - see the LICENSE file for details.
- Author: Dzikri Syairozi
- Email: dzikrisyairozi@gmail.com
- Issues: GitHub Issues
- Discussions: GitHub Discussions
If this project helped you, please give it a β! It helps others discover this project.
Built with β€οΈ by Dzikri Syairozi