A comprehensive, production-ready template for modern web applications with strong type safety, scalable configuration, and best practices.
- Features
- Quick Start
- Environment Setup
- Development
- Testing
- Deployment
- Project Structure
- Configuration
- Contributing
- TypeScript with strict configuration
- Zod for runtime environment validation
- ESLint with comprehensive rules
- Prettier for consistent formatting
- Husky for git hooks
- Modular configuration for different environments
- Path aliases for clean imports
- Feature flags system
- Error boundaries and proper error handling
- Jest for unit testing
- React Testing Library for component testing
- Playwright for E2E testing
- Coverage reporting with thresholds
- Docker support with multi-stage builds
- GitHub Actions CI/CD pipeline
- Environment-specific configurations
- Security scanning and vulnerability checks
- Hot reload in development
- Bundle analyzer for optimization
- Pre-commit hooks for code quality
- Comprehensive logging
- Node.js 18+
- pnpm 8+ (recommended) or npm 8+
- Git
-
Clone and setup
git clone <repository-url> cd template pnpm install
-
Environment configuration
cp .env.example .env.local # Edit .env.local with your configuration -
Validate environment
pnpm run env:validate
-
Start development
pnpm run dev
| File | Purpose | When to use |
|---|---|---|
.env.example |
Template with all variables | Reference for required variables |
.env.local |
Local development | Development on your machine |
.env.development |
Development environment | Shared development settings |
.env.production |
Production environment | Production deployment |
.env.test |
Testing environment | Running tests |
NODE_ENV=development
NEXT_PUBLIC_APP_URL=http://localhost:3000
NEXT_PUBLIC_API_URL=http://localhost:3000/api# Database
DATABASE_URL=postgresql://user:password@localhost:5432/database
# Authentication
JWT_SECRET=your-super-secret-jwt-key-at-least-32-characters-long
# Analytics
NEXT_PUBLIC_ANALYTICS_ENABLED=false
NEXT_PUBLIC_GA_TRACKING_ID=G-XXXXXXXXXX
# Feature Flags
FEATURE_FLAG_NEW_UI=false
FEATURE_FLAG_BETA_FEATURES=falseThe project includes runtime environment validation using Zod:
# Validate current environment
pnpm run env:validate
# Environment will be validated automatically on:
# - Application start
# - Build process
# - CI/CD pipeline| Script | Description |
|---|---|
pnpm run dev |
Start development server |
pnpm run build |
Build for production |
pnpm run start |
Start production server |
pnpm run lint |
Run ESLint |
pnpm run lint:fix |
Fix ESLint issues |
pnpm run format |
Format code with Prettier |
pnpm run type-check |
Run TypeScript type checking |
pnmp run test |
Run unit tests |
pnpm run test:watch |
Run tests in watch mode |
pnpm run test:coverage |
Run tests with coverage |
pnpm run test:e2e |
Run E2E tests |
The project enforces code quality through:
- Pre-commit hooks that run linting and formatting
- Pre-push hooks that run tests
- CI pipeline that validates everything
Use clean imports with configured path aliases:
// Instead of: import { Button } from '../../../components/ui/Button'
import { Button } from '@/components/ui/Button'
import { config } from '@/config'
import { User } from '@/types'Available aliases:
@/*β./src/*@/components/*β./src/components/*@/lib/*β./src/lib/*@/utils/*β./src/utils/*@/hooks/*β./src/hooks/*@/types/*β./types/*@/config/*β./config/*
# Run all tests
pnpm run test
# Run tests in watch mode
pnpm run test:watch
# Run with coverage
pnpm run test:coverage# Run E2E tests
pnpm run test:e2e
# Run E2E tests with UI
pnpm run test:e2e:ui
# Install Playwright browsers (first time)
pnpm exec playwright installtests/
βββ setup.ts # Test configuration
βββ utils/ # Test utilities
βββ e2e/ # E2E tests
src/
βββ __tests__/ # Unit tests
βββ components/
βββ __tests__/ # Component tests
-
Build Docker image
docker build -t template . -
Run container
docker run -p 3000:3000 template
-
Using Docker Compose
# Production docker-compose up -d # Development docker-compose -f docker-compose.dev.yml up -d
# Development build
NODE_ENV=development pnpm run build
# Production build
NODE_ENV=production pnpm run build
# Test build
NODE_ENV=test pnpm run buildThe GitHub Actions workflow automatically:
- Validates environment and code quality
- Tests unit and E2E tests
- Builds the application
- Scans for security vulnerabilities
- Deploys to staging/production
project-root/
βββ .github/ # GitHub workflows and templates
β βββ workflows/ # CI/CD pipelines
βββ .husky/ # Git hooks
βββ config/ # Environment configurations
β βββ development/ # Development config
β βββ production/ # Production config
β βββ testing/ # Test config
β βββ env.ts # Environment validation
β βββ index.ts # Main config
βββ scripts/ # Build and utility scripts
βββ src/ # Source code
β βββ app/ # Next.js app directory
β βββ components/ # React components
β βββ lib/ # Utility libraries
β βββ hooks/ # Custom React hooks
β βββ utils/ # Helper functions
βββ tests/ # Test files
β βββ utils/ # Test utilities
β βββ e2e/ # E2E tests
βββ types/ # Global type definitions
βββ .env.example # Environment template
βββ .eslintrc.js # ESLint configuration
βββ .prettierrc # Prettier configuration
βββ jest.config.ts # Jest configuration
βββ playwright.config.ts # Playwright configuration
βββ tsconfig.json # TypeScript configuration
βββ Dockerfile # Production Docker image
βββ Dockerfile.dev # Development Docker image
βββ docker-compose.yml # Production compose
βββ docker-compose.dev.yml # Development compose
The project uses strict TypeScript settings:
- Strict mode enabled
- No implicit any
- Unused locals/parameters detection
- Exact optional properties
- No unchecked indexed access
Comprehensive linting with:
- TypeScript-specific rules
- React hooks rules
- Import ordering
- Accessibility checks
- Code complexity limits
Each environment has its own configuration:
- Development: Debug mode, hot reload, verbose logging
- Production: Optimized, analytics enabled, security headers
- Testing: Mock data, no analytics, fast timeouts
-
Fork the repository
-
Create a feature branch
git checkout -b feature/amazing-feature
-
Make your changes
-
Run tests and linting
pnpm run test:ci
-
Commit your changes
git commit -m "feat: add amazing feature" -
Push to the branch
git push origin feature/amazing-feature
-
Open a Pull Request
We use Conventional Commits:
feat:New featuresfix:Bug fixesdocs:Documentation changesstyle:Code style changesrefactor:Code refactoringtest:Adding or updating testschore:Maintenance tasks
- Next.js Documentation
- TypeScript Handbook
- Testing Library Docs
- Playwright Documentation
- Docker Best Practices
This project is licensed under the MIT License - see the LICENSE file for details.
Made by DuckingGo with β€οΈ for robust, scalable, and maintainable applications.