A modern, production-ready full-stack application built with the PERN stack (PostgreSQL, Express.js, React, Node.js) featuring complete separation of client and server components.
- Express.js - Fast, unopinionated web framework
- TypeScript - Full type safety and better developer experience
- PostgreSQL - Robust relational database
- JWT Authentication - Secure token-based authentication
- Role-Based Access Control - Granular permission system
- Database Migrations - Version-controlled schema management
- API Documentation - Comprehensive endpoint documentation
- Security Middleware - Helmet, CORS, rate limiting
- Logging System - Winston-based structured logging
- Email Service - Nodemailer integration for notifications
- React 18 - Latest React with concurrent features
- TypeScript - Full type safety and better developer experience
- Vite - Lightning fast build tool and dev server
- Tailwind CSS - Utility-first CSS framework with design system
- React Router - Client-side routing with protected routes
- Zustand - Lightweight state management
- React Query - Server state management and caching
- React Hook Form - Performant forms with validation
- React Hot Toast - Beautiful toast notifications
- Responsive Design - Mobile-first approach
template/
βββ client/ # React frontend application
β βββ src/
β β βββ components/ # Reusable UI components
β β βββ pages/ # Page components
β β βββ hooks/ # Custom React hooks
β β βββ services/ # API service functions
β β βββ stores/ # Zustand state stores
β β βββ types/ # TypeScript type definitions
β β βββ utils/ # Utility functions
β β βββ styles/ # Global styles and design system
β βββ public/ # Static assets
β βββ package.json # Frontend dependencies
βββ server/ # Express.js backend application
β βββ src/
β β βββ config/ # Configuration management
β β βββ controllers/ # Request handlers
β β βββ middlewares/ # Express middleware
β β βββ routes/ # API route definitions
β β βββ services/ # Business logic
β β βββ models/ # Data models
β β βββ database/ # SQL files and migrations
β β βββ scripts/ # Database and deployment scripts
β β βββ utils/ # Utility functions
β βββ package.json # Backend dependencies
βββ scripts/ # Deployment and setup scripts
βββ .cursor/ # Cursor IDE rules and guidelines
βββ README.md # This file
- Node.js - JavaScript runtime
- Express.js - Web application framework
- TypeScript - Type-safe JavaScript
- PostgreSQL - Relational database
- JWT - JSON Web Tokens for authentication
- bcryptjs - Password hashing
- Winston - Logging library
- Nodemailer - Email service
- Helmet - Security middleware
- CORS - Cross-origin resource sharing
- express-rate-limit - Rate limiting
- express-validator - Input validation
- React 18 - UI library
- TypeScript - Type-safe JavaScript
- Vite - Build tool and dev server
- Tailwind CSS - CSS framework
- React Router - Client-side routing
- Zustand - State management
- React Query - Server state management
- React Hook Form - Form handling
- React Hot Toast - Notifications
- Lucide React - Icon library
- Axios - HTTP client
- ESLint - Code linting
- Prettier - Code formatting
- TypeScript - Type checking
- Nodemon - Development server
- PostCSS - CSS processing
- Autoprefixer - CSS vendor prefixes
# Clone the repository
git clone <repository-url>
cd template
# Run the automated setup script
chmod +x scripts/setup.sh
./scripts/setup.sh
The setup script will:
- Check prerequisites (Node.js, npm)
- Install all dependencies
- Create environment files from templates
- Set up the database (if PostgreSQL is available)
- Configure Git hooks
- Build the projects
- Run tests
- Node.js 18+
- PostgreSQL 12+
- npm or yarn
- Clone the repository
git clone <repository-url>
cd template
- Install dependencies
# Install server dependencies
cd server && npm install
# Install client dependencies
cd ../client && npm install
- Environment Setup
# Copy environment files
cp server/.env.example server/.env
cp client/.env.example client/.env
-
Configure Environment Variables
Server (.env):
PG_USER=your_db_user PG_HOST=localhost PG_DATABASE=template_db PG_PASSWORD=your_db_password PG_PORT=5432 JWT_SECRET=your_jwt_secret PORT=5000 CORS_ORIGIN=http://localhost:3000
Client (.env):
VITE_API_URL=http://localhost:5000/api VITE_APP_NAME=Template App VITE_APP_VERSION=1.0.0
-
Database Setup
cd server
npm run setup # Installs deps, migrates, seeds, and optimizes
- Start Development Servers
# Terminal 1 - Start server
cd server && npm run dev
# Terminal 2 - Start client
cd client && npm run dev
- Access the Application
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000/api
- API Health: http://localhost:5000/api/health
- File Size Limit: Maximum 500 lines per file
- Code Duplication: Always check existing implementations
- No Hardcoding: Use environment variables for configuration
- Type Safety: Use TypeScript throughout
- Error Handling: Implement proper error handling and logging
- Unified Design: Single source of truth for all design values
- Component Consistency: Standardized API across all components
- Centralized Styling: All styles defined in configuration files
- Responsive Design: Mobile-first approach
- Accessibility: WCAG compliance built-in
- Use meaningful commit messages
- Create feature branches for new development
- Test changes before committing
- Follow the established code style and patterns
The application includes a comprehensive user management system:
- users - User accounts and authentication
- user_profiles - Extended user information
- roles - System and custom roles
- user_roles - Many-to-many user-role relationships
- user_metadata - Dynamic user attributes
- user_preferences - Application settings
- user_sessions - Active user sessions
- user_audit_log - Change tracking
- UUID Primary Keys - Globally unique identifiers
- Soft Deletes - Preserve data integrity
- Audit Logging - Track all changes
- Role-Based Access - Granular permissions
- Metadata System - Flexible user attributes
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run migrate # Run database migrations
npm run seed # Seed database with sample data
npm run optimize # Optimize database performance
npm run setup # Complete setup (install, migrate, seed, optimize)
npm run lint # Run ESLint
npm run lint:fix # Fix ESLint issues
npm run dev # Start development server
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLint
npm run lint:fix # Fix ESLint issues
npm run type-check # Run TypeScript type checking
POST /api/auth/register
- User registrationPOST /api/auth/login
- User loginPOST /api/auth/logout
- User logoutPOST /api/auth/refresh
- Refresh tokenPOST /api/auth/verify-email
- Email verificationPOST /api/auth/forgot-password
- Password reset requestPOST /api/auth/reset-password
- Password reset
GET /api/users/profile
- Get current user profilePUT /api/users/profile
- Update user profileGET /api/users
- Get all users (admin)GET /api/users/:id
- Get user by ID (admin)PATCH /api/users/:id/status
- Update user status (admin)DELETE /api/users/:id
- Delete user (admin)
GET /api/health
- Health checkGET /api/health/ready
- Readiness check
- JWT tokens with configurable expiration
- Role-based access control (RBAC)
- Secure password hashing with bcrypt
- Session management
- Email verification
- Express-validator for input validation
- SQL injection prevention
- XSS protection
- CSRF protection
- Rate limiting
- Helmet.js for security headers
- CORS configuration
- Content Security Policy
- X-Frame-Options
- X-Content-Type-Options
The application is built with a mobile-first approach:
- Mobile: < 640px
- Tablet: 640px - 1024px
- Desktop: > 1024px
- Unit Tests: Individual component and function testing
- Integration Tests: API endpoint and service testing
- E2E Tests: End-to-end user flow testing
- Coverage Reports: Detailed test coverage analysis
- Jest testing framework with TypeScript support
- Supertest for API endpoint testing
- Database testing with test fixtures
- Mock services and external dependencies
- Vitest for fast unit testing
- React Testing Library for component testing
- User event simulation and interaction testing
- Accessibility testing with jest-dom matchers
# Client tests
npm run test # Run tests in watch mode
npm run test:run # Run tests once
npm run test:coverage # Generate coverage report
npm run test:ui # Run tests with UI
# Server tests
npm run test # Run all tests
npm run test:watch # Run tests in watch mode
npm run test:coverage # Generate coverage report
# Production deployment
npm run docker:up
# Development deployment
npm run docker:dev
# With monitoring
npm run docker:monitoring
# Or manually from deployment folder
cd deployment
docker-compose up -d
# Build both client and server
cd client && npm run build
cd ../server && npm run build
- Configure production environment variables
- Set up PostgreSQL database
- Configure email service
- Set up logging and monitoring
- Docker: Complete containerized deployment with multi-stage builds
- PM2: Process management for Node.js applications
- Nginx: Reverse proxy with optimized configuration
- Cloud Platforms: AWS, GCP, Azure, Vercel, Netlify
- Kubernetes: Container orchestration ready
- Prometheus: Metrics collection and storage
- Grafana: Visualization and dashboards
- Node Exporter: System metrics
- cAdvisor: Container metrics
- Redis/PostgreSQL Exporters: Database metrics
- AlertManager: Alert management
- HTTP request metrics (count, duration, status codes)
- Database connection metrics
- Cache hit/miss ratios
- Memory and CPU usage
- Custom business metrics
/api/metrics
- Prometheus metrics/api/health/detailed
- Detailed health information/api/system/info
- System information
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3001 (admin/admin)
- AlertManager: http://localhost:9093
- Code Quality: ESLint, Prettier, TypeScript checks
- Testing: Unit, integration, and coverage tests
- Security: Dependency scanning with Trivy
- Build: Automated builds for client and server
- Deployment: Staging and production deployments
- Multi-stage builds: Separate client and server testing
- Database testing: PostgreSQL service for integration tests
- Dependency management: Automated dependency updates with Dependabot
- Security scanning: Vulnerability detection and reporting
- Coverage reporting: Code coverage tracking with Codecov
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Follow the coding standards and guidelines
- Ensure all files are under 500 lines
- Check for code duplication
- Write meaningful commit messages
- Run tests locally (
npm test
) - Ensure all CI checks pass
- Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
# Frontend (React + Vite)
cd client
npm install
npm run dev # Development server
npm run build # Production build
npm run test # Run tests
# Backend (Express + TypeScript)
cd server
npm install
npm run dev # Development server with nodemon
npm run start # Production server
npm run test # Run tests
# From root directory
npm run docker:up # Production deployment
npm run docker:dev # Development deployment
npm run docker:monitoring # With full monitoring stack
npm test # Run all tests
npm run test:coverage # Run with coverage
npm run test:client # Frontend tests only
npm run test:server # Backend tests only
npm run lint # Lint all code
npm run lint:fix # Fix linting issues
npm run format # Format code
npm run type-check # TypeScript checking
For detailed information, see:
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the Issues page
- Review the documentation in each directory
- Follow the development guidelines
- Ensure all environment variables are configured correctly
- Docker containerization
- CI/CD pipeline setup
- Comprehensive testing suite
- API documentation with Swagger
- Real-time features with WebSockets
- File upload and management
- Advanced user management features
- Performance monitoring and analytics
- Internationalization (i18n)
- Dark mode support
Built with β€οΈ using the PERN stack