joshajh/nest-prisma-vue-turborepo
Fullstack Typescript-first starter template using NestJS, Prisma, Vue 3, and Turborepo; comprehensive testing with Jest; rapid codegen with Plop; git hooks and branching rules with Husky; and more.
Fullstack Starter Template
A production-ready fullstack starter template featuring NestJS, Prisma, Vue 3, and Turborepo with comprehensive testing, code generation, and quality tools.
โจ Highlights
- ๐ฏ Production-Ready: 86.66% test coverage on critical paths, all builds passing
- ๐ Rapid Development: Plop generators for instant scaffolding
- ๐ API Documentation: Auto-generated Swagger/OpenAPI docs
- ๐งช Comprehensive Testing: 30+ unit tests with Jest
- ๐จ Code Quality: ESLint, Prettier, Husky git hooks
- ๐ Type-Safe: Shared TypeScript types across frontend and backend
- โก Fast Builds: Turborepo caching for lightning-fast builds
Stack
- Monorepo: Turborepo
- Backend: NestJS + Prisma
- Frontend: Vue 3 + Vite
- Testing: Jest (Backend)
- Code Generation: Plop
- API Docs: Swagger/OpenAPI
- Code Quality: ESLint + Prettier + Husky
- Shared: TypeScript types package
- Language: TypeScript throughout
Project Structure
โโโ apps/
โ โโโ backend/ # NestJS API server
โ โ โโโ src/
โ โ โโโ prisma/ # Prisma schema & migrations
โ โ โโโ test/
โ โโโ frontend/ # Vue 3 application
โ โโโ src/
โ โ โโโ router/ # Vue Router
โ โ โโโ stores/ # Pinia stores
โ โ โโโ services/ # API services
โ โ โโโ views/ # Page components
โ โ โโโ components/
โโโ packages/
โ โโโ types/ # Shared TypeScript types
โโโ turbo.json # Turborepo config
Prerequisites
- Node.js >= 18.0.0
- npm >= 9.0.0
- PostgreSQL database
Getting Started
1. Install Dependencies
npm install2. Set Up Environment Variables
Backend (apps/backend/.env):
cp apps/backend/.env.example apps/backend/.envEdit apps/backend/.env and set your database URL:
DATABASE_URL="postgresql://user:password@localhost:5432/mydb?schema=public"
PORT=3000
NODE_ENV=development
Frontend (apps/frontend/.env):
cp apps/frontend/.env.example apps/frontend/.env3. Initialize Database
cd apps/backend
npm run prisma:migrate
npm run prisma:seed # Optional: seed sample data4. Build Shared Packages
# From root
npm run build5. Start Development Servers
# From root - starts all apps in parallel
npm run devOr start individually:
# Backend (http://localhost:3000)
cd apps/backend
npm run dev
# Frontend (http://localhost:5173)
cd apps/frontend
npm run devAvailable Scripts
Root Commands
npm run dev- Start all apps in development modenpm run build- Build all apps for productionnpm run lint- Lint all appsnpm run format- Format code with Prettiernpm run clean- Clean all build outputsnpm run generate- Run Plop code generators (see Code Generation)npm run test- Run all tests
Backend Commands
npm run dev- Start in watch modenpm run build- Build for productionnpm run start- Start production servernpm run prisma:migrate- Run database migrationsnpm run prisma:generate- Generate Prisma Clientnpm run prisma:studio- Open Prisma Studionpm run prisma:seed- Seed databasenpm run lint- Lint codenpm run test- Run tests
Frontend Commands
npm run dev- Start dev servernpm run build- Build for productionnpm run clean- Clean build output
Project Features
Backend Features
- โ Clean Architecture: Controllers, services, and DTOs pattern
- โ Prisma ORM: Type-safe database access with migrations
- โ Validation: Global validation pipe with class-validator
- โ
API Documentation: Auto-generated Swagger/OpenAPI docs at
/api/docs - โ Testing: Comprehensive unit tests with Jest (86.66% coverage)
- โ CORS: Configured and ready
- โ Error Handling: Proper error responses with HTTP status codes
- โ Sample CRUD: Complete User entity example
- โ Database Seeding: Sample data generator
Frontend Features
- โ
Vue 3: Composition API with
<script setup> - โ TypeScript: Full type safety
- โ Vue Router: File-based routing setup
- โ Pinia: State management with stores
- โ Axios: HTTP client with interceptors
- โ Vite: Lightning-fast HMR and builds
- โ Sample UI: Complete User CRUD interface
Code Quality & DX
- โ Shared TypeScript Types: Type-safe contracts between frontend and backend
- โ Turborepo: Smart caching for faster builds
- โ ESLint: Code linting with TypeScript and Vue support
- โ Prettier: Consistent code formatting
- โ Husky: Git hooks for pre-commit linting and pre-push builds
- โ Plop Generators: Instant code scaffolding (see Code Generation)
- โ Comprehensive Tests: 30+ unit tests covering critical paths
Development Workflow
Code Generation
This template includes Plop generators for rapid scaffolding:
# Run the interactive generator
npm run generateAvailable Generators:
-
NestJS Module - Generates complete CRUD module:
- Controller with all REST endpoints
- Service with business logic
- Create/Update DTOs
- Swagger decorators
- Imports Prisma service
-
Vue Component - Generates Vue 3 component:
- TypeScript with
<script setup> - Template and style sections
- Proper naming conventions
- TypeScript with
Example: Generate a NestJS module
npm run generate
? What do you want to generate? nest-module
? Module name: productsThis creates:
apps/backend/src/products/products.module.tsapps/backend/src/products/products.controller.tsapps/backend/src/products/products.service.tsapps/backend/src/products/dto/create-product.dto.tsapps/backend/src/products/dto/update-product.dto.ts
Adding a New API Endpoint
Option 1: Use Plop Generator (Recommended)
npm run generate
# Select "nest-module" and follow promptsOption 2: Manual Setup
- Define types in
packages/types/src/ - Create Prisma model in
apps/backend/prisma/schema.prisma - Generate Prisma Client:
npm run prisma:generate - Create NestJS module/controller/service in
apps/backend/src/ - Use types from
@repo/types
Adding a New Frontend Page
Option 1: Use Plop Generator (Recommended)
npm run generate
# Select "vue-component" and follow promptsOption 2: Manual Setup
- Create view in
apps/frontend/src/views/ - Add route in
apps/frontend/src/router/index.ts - Create service in
apps/frontend/src/services/if needed - Use types from
@repo/types
API Documentation
This template includes Swagger/OpenAPI documentation for the backend API.
Access Swagger UI:
http://localhost:3000/api/docs
All endpoints are automatically documented with:
- Request/response schemas
- Validation rules
- HTTP status codes
- Example payloads
Adding Swagger Docs to New Endpoints:
The Plop generator automatically adds Swagger decorators. For manual endpoints, use:
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
@ApiTags('products')
@Controller('products')
export class ProductsController {
@Get()
@ApiOperation({ summary: 'Get all products' })
@ApiResponse({ status: 200, description: 'Returns all products' })
findAll() {
// ...
}
}Testing
This template includes comprehensive testing setup with Jest.
Running Tests
# Run all tests
npm run test
# Run tests with coverage
cd apps/backend
npm run test -- --coverage
# Run tests in watch mode
npm run test -- --watchTest Coverage
Current coverage (see TEST_REPORT.md for details):
- Overall: 64.76% statements, 75% branches
- Users Module: 86.66% statements (critical paths)
- 30 unit tests covering:
- Service layer (CRUD operations, error handling)
- Controller layer (HTTP responses, validation)
- Edge cases and error scenarios
Writing Tests
Tests are located alongside source files:
*.spec.ts- Unit tests*.e2e-spec.ts- E2E tests (intest/directory)
Example test structure:
describe('UsersService', () => {
describe('findAll', () => {
it('should return an array of users', async () => {
// Test implementation
});
});
});Database Migrations
# Create a new migration
cd apps/backend
npm run prisma:migrate
# View database in Prisma Studio
npm run prisma:studio
# Reset database (WARNING: deletes all data)
npx prisma migrate resetBuilding for Production
# Build all packages
npm run build
# Backend will be in apps/backend/dist
# Frontend will be in apps/frontend/distTroubleshooting
Port Already in Use
Change the port in apps/backend/.env:
PORT=3001
Database Connection Failed
Ensure PostgreSQL is running and the DATABASE_URL in .env is correct.
Types Not Found
Build the types package:
cd packages/types
npm run buildGit Hooks
This template uses Husky for git hooks:
- Pre-commit: Runs Prettier on staged files (via lint-staged)
- Pre-push: Runs full build to ensure everything compiles
To skip hooks (not recommended):
git commit --no-verify
git push --no-verifyProject Quality
See TEST_REPORT.md for comprehensive quality assessment:
- โ All builds passing
- โ Linting configured
- โ 30/30 tests passing
- โ Quality Score: 8.35/10 (Excellent)
Example: Complete User CRUD
This template includes a complete User CRUD example demonstrating:
Backend (apps/backend/src/users/):
- User entity with Prisma schema
- Full REST API (GET, POST, PUT, DELETE)
- Input validation with class-validator
- Error handling (404, validation errors)
- Swagger documentation
- Unit tests (service + controller)
Frontend (apps/frontend/src/):
- Users list view with table
- Create/Edit user modals
- Delete confirmation
- Pinia store for state management
- API service layer
- Error handling and loading states
API Endpoints:
GET /api/users- List all usersGET /api/users/:id- Get single userPOST /api/users- Create userPUT /api/users/:id- Update userDELETE /api/users/:id- Delete user
Recommended Next Steps
Short-term (1-2 weeks):
- Add JWT authentication
- Add role-based authorization
- Configure CORS for production domains
- Add Docker Compose setup
- Add frontend component tests (Vitest)
- Add E2E tests with real database
Long-term (Production):
- Set up CI/CD pipeline (GitHub Actions)
- Add rate limiting (NestJS throttler)
- Add logging (Winston/Pino)
- Add monitoring (Sentry/DataDog)
- Add security headers (Helmet)
- Add request/response logging
- Add database backups
- Add performance monitoring
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Generated with โค๏ธ using Claude Code