A production-ready monorepo starter with React 19, NestJS 11, and TypeScript. Built for scalability, developer experience, and modern best practices.
This repository is designed to be used as a GitHub template. When creating a new project from this template, you'll need to rename various parts to match your project. See TEMPLATE-SETUP.md for detailed instructions on renaming everything properly.
For AI Agents: If you're an AI assistant helping set up a new project from this template, please refer to the "AI Agent Instructions" section in CLAUDE.md for specific renaming guidelines.
This repository contains a Turborepo setup using pnpm workspaces with:
-
frontend-boilerplate β React 19 app with:
- β‘ Vite for lightning-fast development
- π§ Tanstack Router for type-safe, file-based routing
- π¨ Tailwind CSS v4 with automatic class sorting
- π― shadcn/ui component library (customizable)
- π Storybook for component development
- π§ͺ Vitest + React Testing Library (80% coverage requirement)
- π§ ESLint + Prettier integration
- π Authentication with JWT token management
- π‘ Axios-based API client with interceptors
- π£ React Query for server state management
- π± Responsive design with mobile-first approach
-
backend-boilerplate β NestJS 11 API with:
- ποΈ Modular architecture with feature-based modules
- ποΈ PostgreSQL + MikroORM with migrations
- π JWT authentication with refresh tokens
- β‘ Redis caching with Keyv
- π Swagger/OpenAPI documentation
- π§ͺ Jest for testing (80% coverage requirement)
- π‘οΈ Rate limiting & security (Helmet, CORS)
- π OpenTelemetry integration for observability
- π Structured logging with Pino
- π Health checks with Terminus
- π― Request validation with class-validator
- π·οΈ Environment variables validation with Joi
- types β Shared TypeScript types between frontend and backend
- shared-lib-boilerplate β Template for creating shared libraries
- Monorepo: TurboRepo 2.5.3 + pnpm workspaces
- Frontend: React 19.1.0, Vite 7.0.0, TypeScript 5.8.3, Tanstack Router 1.122.0, Tailwind CSS v4.1.11
- Backend: NestJS 11.1.2, TypeScript 5.8.3, MikroORM 6.4.15, PostgreSQL 17, Redis 7
- Testing: Vitest 3.2.4, Jest 29.7.0, React Testing Library 16.3.0, Storybook 9.0.14
- Code Quality: ESLint 9.27.0, Prettier 3.5.3, Husky 9.1.7, lint-staged 16.1.0
- Type Safety: End-to-end type safety with shared types package
- Authentication: Complete auth flow with JWT tokens, refresh tokens, and protected routes
- API Client: Centralized API client with automatic token refresh and error handling
- Testing: Comprehensive testing setup with coverage requirements
- Developer Experience: Hot reload, automatic formatting, pre-commit hooks
- Production Ready: Environment validation, logging, monitoring, error handling
- Scalable: Modular architecture, code splitting, lazy loading
- Node.js v22 LTS or higher
- pnpm v10.5.2 (specified via packageManager in package.json)
- PostgreSQL 17 (for backend) - or use Docker Compose
- Redis 7 (for backend caching) - or use Docker Compose
# Clone the repository
git clone https://github.com/your-repo/react-nestjs-monorepo-boilerplate.git
cd react-nestjs-monorepo-boilerplate
# Install dependencies
pnpm install
# Option 1: Use Docker for databases (recommended)
docker-compose -f docker-compose.local.yml up -d
# Option 2: Use your own PostgreSQL and Redis instances
# Set up environment variables for backend
cp apps/backend-boilerplate/.env.example apps/backend-boilerplate/.env
# Edit .env with your database credentials
# Run database migrations
cd apps/backend-boilerplate && pnpm migration:run && cd ../..
# Run development servers
pnpm devThe apps will be available at:
- Frontend: http://localhost:5173
- Backend: http://localhost:3001
- Backend Swagger: http://localhost:3001/api
pnpm devβ Run all apps in development modepnpm buildβ Build all apps for productionpnpm testβ Run tests in all appspnpm lintβ Run ESLint across all appspnpm formatβ Format code with Prettierpnpm type-checkβ TypeScript type checkingpnpm build-typeβ Build shared types packagepnpm build-libsβ Build all shared libraries
pnpm devβ Start React dev serverpnpm buildβ Build for productionpnpm testβ Run Vitest testspnpm test:coverageβ Run tests with coveragepnpm storybookβ Start Storybookpnpm lintβ Run ESLintpnpm formatβ Format code with Prettier
pnpm devβ Start NestJS with hot reloadpnpm testβ Run unit testspnpm test:e2eβ Run e2e testspnpm test:coverageβ Run tests with coverage
βββ apps/
β βββ frontend-boilerplate/ # React 19 + Vite app
β β βββ src/
β β β βββ apiClient/ # API client setup
β β β βββ components/ # UI components
β β β β βββ layout/ # Layout components
β β β β βββ pages/ # Page components
β β β β βββ ui/ # Reusable UI components
β β β βββ contexts/ # React contexts
β β β βββ hooks/ # Custom React hooks
β β β βββ routes/ # Tanstack Router pages
β β β βββ lib/ # Utilities
β β β βββ test/ # Test setup
β β βββ .storybook/ # Storybook configuration
β βββ backend-boilerplate/ # NestJS 11 API
β βββ src/
β β βββ modules/ # Feature modules
β β β βββ auth/ # Authentication module
β β β βββ users/ # Users module
β β β βββ health/ # Health checks
β β βββ entities/ # Database entities
β β βββ configs/ # Configuration
β β βββ shared/ # Shared utilities
β β βββ migrations/ # Database migrations
β βββ test/ # E2E tests
βββ packages/
β βββ types/ # Shared TypeScript types
β βββ shared-lib-boilerplate/ # Template for shared libraries
βββ docs/ # Documentation
βββ CLAUDE.md # AI assistant guidelines
βββ AI-CONTEXT.md # Technical context
βββ TEMPLATE-SETUP.md # Template usage guide
βββ turbo.json # TurboRepo configuration
- Entities: Must have "Entity" suffix (e.g.,
UserEntity) - DTOs: Shared as TypeScript interfaces in
packages/types - Database: PostgreSQL uses snake_case, TypeScript uses camelCase
- Components: PascalCase for components, camelCase for utilities
- Frontend: Feature-based with separation of concerns (components, hooks, contexts)
- Backend: Module-based architecture following NestJS best practices
- Shared Types: Centralized in
packages/typesfor consistency
- Minimum 80% code coverage for all new code
- Every component must have tests and Storybook stories
- Backend services must have comprehensive unit tests
Every new component MUST have:
- Component file - The React component
- Test file - Unit tests using Vitest and React Testing Library
- Story file - Storybook stories for all component states
Example structure:
src/components/ui/
βββ Button.tsx
βββ Button.stories.tsx
βββ __tests__/
βββ Button.test.tsx
Every new service/controller MUST have:
- Service/Controller - Business logic with proper decorators
- DTOs - Data Transfer Objects with validation
- Tests - Unit tests with minimum 80% coverage
- Swagger docs - API documentation decorators
This project uses Husky and lint-staged to ensure code quality. On every commit:
- ESLint checks are run on affected files
- TypeScript type checking is performed
- Prettier formats all staged files
See docs/HUSKY_LINT_STAGED.md for details.
The project includes a comprehensive GitHub Actions workflow that runs on every push and PR:
- Build & Type Check: Ensures all packages build successfully
- Linting & Formatting: Enforces code style consistency
- Testing: Runs all tests with coverage requirements
- Services: Spins up PostgreSQL and Redis for integration tests
- Caching: Optimized with pnpm and Turbo caching
For local development, use the included Docker Compose setup:
# Start PostgreSQL (with pgvector) and Redis
docker-compose -f docker-compose.local.yml up -d
# Stop services
docker-compose -f docker-compose.local.yml down
# Stop and remove volumes (fresh start)
docker-compose -f docker-compose.local.yml down -vServices:
- PostgreSQL 17 with pgvector extension (port 5432)
- Redis 7 (port 6379)
The frontend includes a comprehensive Storybook setup:
# Run Storybook (from frontend directory or root)
pnpm storybook
# Build Storybook
pnpm build-storybookFeatures:
- Component documentation and playground
- Accessibility testing with a11y addon
- Interaction testing with play functions
- Mock router for Tanstack Router components
- Global decorators for providers (Auth, Query Client)
This project uses TurboRepo for efficient monorepo management:
- Parallel Execution: Tasks run in parallel when possible
- Smart Caching: Only rebuilds what changed
- Pipeline Optimization: Dependency-aware task scheduling
Key pipelines in turbo.json:
build: Builds all packages in dependency ordertest: Runs tests with cachinglint/format: Code quality checkstype-check: TypeScript validation
- CLAUDE.md - AI assistant guidelines and template instructions
- TEMPLATE-SETUP.md - Guide for using this as a template
- AI-CONTEXT.md - Technical context for AI tools
- Frontend README - Frontend-specific docs
- Backend README - Backend-specific docs
- Husky & Lint-staged - Pre-commit hooks setup
- Create a feature branch
- Make your changes following the guidelines
- Ensure all tests pass (
pnpm test:coverage) - Run formatting (
pnpm format) - Create a pull request
MIT