Modern Full-Stack Application with TypeScript, Clean Architecture & Real-time Features
A production-ready MERN stack monorepo featuring modern development practices, clean architecture, and comprehensive tooling. Built with TypeScript throughout, this project demonstrates best practices for full-stack development in 2025.
π Authentication & Security
- JWT-based authentication with refresh tokens
- Password recovery and email verification
- Profile management with avatar uploads
- Rate limiting and security middleware
π Todo Management
- Full CRUD operations with real-time updates
- Advanced filtering and sorting
- Status management (initial, in-progress, completed, cancelled)
- Optimistic UI updates
π¬ Real-time Chat
- WebSocket-based messaging with Socket.io
- Multiple chat rooms support
- Emoji support and file sharing
- Message history and real-time notifications
ποΈ Architecture & Development
- Clean Architecture principles
- Monorepo structure with shared tooling
- Comprehensive testing suite
- Docker containerization
- Cross-platform development scripts
Frontend (Client)
- React 19 with TypeScript
- TanStack Router for type-safe routing
- TanStack Query for server state management
- Zustand for client state management
- Tailwind CSS + shadcn/ui for styling
- Vite for fast development and building
Backend (Server)
- Node.js + Express with TypeScript
- Clean Architecture with dependency injection
- Multiple Database Support (SQLite, PostgreSQL, Supabase, MongoDB)
- Socket.io for real-time communication
- Swagger/OpenAPI for API documentation
- Jest for comprehensive testing
DevOps & Tooling
- Docker & Docker Compose for containerization
- Cross-platform JavaScript scripts for development
- ESLint + Prettier for code quality
- GitHub Actions ready CI/CD setup
- Node.js >= 18.0.0
- Package Manager: Bun (recommended), npm, or yarn
- Git for version control
- Docker (optional, for containerized development)
# Clone the repository
git clone <repository-url>
cd example-react
# Install all dependencies
npm run setup
# or with bun
bun run setup
# Create unified environment configuration
cp .env.example .env
# Edit .env with your configuration
# The file contains comprehensive documentation for all variables
Key Environment Variables:
# Application
NODE_ENV=development
PORT=3000
IS_SSR=true
# Client Configuration (VITE_ prefix for browser access)
VITE_SERVER_PORT=3000
VITE_CLIENT_PORT=5173
VITE_API_BASE_URL=http://localhost:3000/api
VITE_APP_NAME=React Todo & Chat App 2025
# Authentication (CHANGE IN PRODUCTION!)
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production-2025
JWT_REFRESH_SECRET=your-super-secret-refresh-key-change-this-in-production-2025
# Database
DATABASE_TYPE=sqlite
SQLITE_DATABASE_PATH=./server-ts/data/database.sqlite
# CORS
CORS_ALLOW_ORIGINS=http://localhost:5173,http://localhost:3000
# Start both client and server
npm run dev
# or with bun
bun run dev
Access Points:
- π Client: http://localhost:5173
- π§ Server: http://localhost:3000
- π API Docs: http://localhost:3000/api-docs
- π₯ Health Check: http://localhost:3000/health
example-react/
βββ π± client/ # React Frontend Application
β βββ src/
β β βββ components/ # Reusable UI components
β β β βββ ui/ # shadcn/ui components
β β β βββ Navigation.tsx # Main navigation
β β β βββ AuthRequired.tsx # Auth guard component
β β βββ routes/ # Page components & routing
β β β βββ index.tsx # Home page
β β β βββ login.tsx # Authentication pages
β β β βββ todo.tsx # Todo management
β β β βββ chat.tsx # Real-time chat
β β β βββ profile.tsx # User profile
β β βββ hooks/ # Custom React hooks
β β βββ services/ # API service layer
β β βββ stores/ # Zustand state stores
β β βββ lib/ # Utility libraries
β β βββ types/ # TypeScript definitions
β βββ public/ # Static assets
β βββ tests/ # Frontend tests
β βββ package.json
βββ π§ server-ts/ # Express Backend (Clean Architecture)
β βββ src/
β β βββ domain/ # Business Logic & Entities
β β β βββ entities/ # Domain entities
β β β βββ repositories/ # Repository interfaces
β β β βββ services/ # Domain services
β β βββ application/ # Application Business Rules
β β β βββ use-cases/ # Application use cases
β β β βββ dtos/ # Data transfer objects
β β β βββ interfaces/ # Application interfaces
β β βββ infrastructure/ # External Concerns
β β β βββ database/ # Database implementations
β β β βββ repositories/ # Repository implementations
β β β βββ external-services/ # External services
β β β βββ config/ # Configuration
β β βββ presentation/ # Controllers & Routes
β β β βββ controllers/ # HTTP controllers
β β β βββ routes/ # Route definitions
β β β βββ middleware/ # Presentation middleware
β β β βββ validators/ # Request validators
β β βββ shared/ # Shared utilities
β βββ tests/ # Backend tests
β β βββ unit/ # Unit tests
β β βββ integration/ # Integration tests
β β βββ e2e/ # End-to-end tests
β βββ data/ # Database files (SQLite)
β βββ uploads/ # File uploads
β βββ package.json
βββ π οΈ scripts/ # Cross-platform build scripts
β βββ install.js # Dependency installation
β βββ dev.js # Development server
β βββ test.js # Test runner
β βββ build.js # Production build
β βββ deploy.js # Deployment pipeline
β βββ clean.js # Cleanup utilities
β βββ package-manager.js # Package manager switching
βββ π³ Docker files # Containerization
β βββ Dockerfile # Multi-stage Docker build
β βββ docker-compose.dev.yml # Development environment
β βββ docker-compose.prod.yml # Production environment
β βββ docker-compose.test.yml # Testing environment
βββ π Configuration files
βββ package.json # Root workspace configuration
βββ nginx.conf # Nginx configuration
βββ Makefile # Make commands
# π§ Setup & Installation
npm run setup # Install all dependencies
npm run pm:switch bun # Switch to Bun package manager
# π Development
npm run dev # Start both client & server
npm run test # Run all tests
npm run test:watch # Run tests in watch mode
# ποΈ Production
npm run build # Build for production
npm run start # Start production server
npm run deploy # Full deployment pipeline
# π§Ή Maintenance
npm run clean # Clean build artifacts
npm run seed # Seed demo data
npm run seed:force # Force seed with fresh data
Script | Command | Description |
---|---|---|
π§ Setup | npm run setup |
Install dependencies for all packages |
π Development | npm run dev |
Start development servers concurrently |
π§ͺ Testing | npm run test |
Run comprehensive test suite |
ποΈ Build | npm run build |
Build all packages for production |
npm run start |
Start production server | |
π Deploy | npm run deploy |
Complete deployment pipeline |
π§Ή Clean | npm run clean |
Remove build artifacts and caches |
π¦ Package Manager | npm run pm:switch <manager> |
Switch between npm/yarn/bun |
π± Seed Data | npm run seed |
Create demo data for development |
When the server is running, access comprehensive API documentation:
- π Swagger UI: http://localhost:3000/api-docs
- π OpenAPI Spec: http://localhost:3000/api-docs/swagger.json
- π₯ Health Check: http://localhost:3000/health
- βΉοΈ API Info: http://localhost:3000/api
Authentication & User Management
POST /api/auth/register # User registration
POST /api/auth/login # User login
POST /api/auth/logout # User logout
GET /api/auth/me # Get current user profile
PUT /api/auth/profile # Update user profile
POST /api/auth/upload # Upload profile avatar
Todo Management
GET /api/todos # Get todos (with filtering & pagination)
POST /api/todos # Create new todo
GET /api/todos/:id # Get specific todo
PUT /api/todos/:id # Update todo
DELETE /api/todos/:id # Delete todo
Real-time Chat
GET /api/chat/rooms # Get available chat rooms
POST /api/chat/rooms # Create new chat room
GET /api/chat/rooms/:id # Get room details
WebSocket /socket.io # Real-time messaging
# Run all tests across the monorepo
npm run test
# Individual package testing
cd client && npm run test # Frontend tests
cd server-ts && npm run test # Backend tests
# Watch mode for development
cd client && npm run test:watch
cd server-ts && npm run test:watch
# Coverage reports
cd client && npm run test:coverage
cd server-ts && npm run test:coverage
- Unit Tests: Individual component/function testing
- Integration Tests: API endpoint and database testing
- E2E Tests: Full user workflow testing
- Component Tests: React component testing with Testing Library
All environment variables are now managed from a single root .env
file for simplified deployment and consistency:
example-react/
βββ .env # β
Unified configuration (ALL variables)
βββ .env.example # β
Template with documentation
βββ client/.env.example # β οΈ Deprecated (points to root)
βββ server-ts/.env.example # β οΈ Deprecated (points to root)
Client Variables (VITE_ prefix)
VITE_SERVER_PORT=3000 # Server port for API calls
VITE_CLIENT_PORT=5173 # Client development port
VITE_API_BASE_URL=http://localhost:3000/api
VITE_WS_URL=http://localhost:3000 # WebSocket URL
VITE_APP_NAME=React Todo & Chat App 2025
VITE_ENABLE_CHAT=true # Feature flags
Server Variables
NODE_ENV=development # Environment mode
PORT=3000 # Server port
JWT_SECRET=your-secret # Authentication secrets
DATABASE_TYPE=sqlite # Database configuration
CORS_ALLOW_ORIGINS=http://localhost:5173
If you have existing .env
files in subdirectories:
# Analyze existing environment files
npm run env:cleanup
# Migrate to unified configuration (with backup)
npm run env:cleanup:force
- Single Configuration: One file to manage for all environments
- Consistency: Same variables available to both client and server
- Simplified CI/CD: Single environment configuration in deployment platforms
- Version Control: Easier to track environment changes
- Documentation: Comprehensive inline documentation
The system automatically validates environment configuration:
# Development scripts validate required variables
npm run dev # Validates and shows environment summary
# Manual validation
node scripts/env-loader.js
Development Environment
# Start development environment with hot reload
docker-compose -f docker-compose.dev.yml up --build
Production Environment
# Build and deploy production environment
docker-compose -f docker-compose.prod.yml up --build -d
# View logs
docker-compose -f docker-compose.prod.yml logs -f
Testing Environment
# Run tests in containerized environment
docker-compose -f docker-compose.test.yml up --build
# Build for production
npm run build
# Start production server
npm run start
# Or use PM2 for process management
pm2 start ecosystem.config.js
Frontend (Vercel/Netlify)
- Build command:
npm run build
- Output directory:
client/dist
- Environment variables: Copy all
VITE_*
variables from root.env
Backend (Railway/Render/Heroku)
- Build command:
npm run build
- Start command:
npm run start
- Environment variables: Copy all non-
VITE_*
variables from root.env
Full-Stack (Single Platform)
- Build command:
npm run build
- Start command:
npm run start
- Environment variables: Copy entire root
.env
configuration
Vercel
# Set environment variables in Vercel dashboard or via CLI
vercel env add VITE_API_BASE_URL production
vercel env add NODE_ENV production
vercel env add JWT_SECRET production
# ... copy all variables from .env
Netlify
# Set in Netlify dashboard or netlify.toml
[build.environment]
VITE_API_BASE_URL = "https://your-api.netlify.app/api"
NODE_ENV = "production"
Heroku
# Set via Heroku CLI
heroku config:set NODE_ENV=production
heroku config:set JWT_SECRET=your-production-secret
heroku config:set DATABASE_TYPE=postgres
# ... copy all variables from .env
Railway
# Set in Railway dashboard or railway.json
{
"deploy": {
"startCommand": "npm run start",
"healthcheckPath": "/health"
}
}
This project serves as a comprehensive learning resource for modern full-stack development:
- React 19: Latest features including concurrent rendering and server components
- TypeScript: Advanced type safety and modern JavaScript features
- TanStack Router: Type-safe routing with search params and loaders
- TanStack Query: Server state management with caching and synchronization
- Zustand: Lightweight state management for client-side state
- Tailwind CSS: Utility-first CSS framework for rapid UI development
- shadcn/ui: Modern, accessible component library
- Clean Architecture: Separation of concerns and dependency inversion
- Domain-Driven Design: Business logic organization and modeling
- Repository Pattern: Data access abstraction
- Use Cases: Application business rules implementation
- Dependency Injection: Loose coupling and testability
- Monorepo Management: Shared tooling and cross-package dependencies
- Testing Strategies: Unit, integration, and E2E testing approaches
- Docker Containerization: Development and production environments
- CI/CD Pipelines: Automated testing and deployment workflows
We welcome contributions! Please follow these guidelines:
- Fork the repository
- Clone your fork:
git clone <your-fork-url>
- Install dependencies:
npm run setup
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes following the existing code style
- Add tests for new functionality
- Run tests:
npm run test
- Build the project:
npm run build
- Commit with conventional commits:
git commit -m 'feat: add amazing feature'
- Push to your branch:
git push origin feature/amazing-feature
- Open a Pull Request with a clear description
- Ensure all CI checks pass
- Respond to review feedback
- Follow TypeScript strict mode
- Use ESLint and Prettier configurations
- Write meaningful commit messages
- Add JSDoc comments for public APIs
- Maintain test coverage above 80%
This project is licensed under the MIT License - see the LICENSE file for details.
- β Commercial use - Use in commercial projects
- β Modification - Modify and adapt the code
- β Distribution - Share and distribute
- β Private use - Use in private projects
- β Liability - No warranty or liability
- β Attribution - Include original license
- π Documentation: Check the README files in each package
- π Issues: Open an issue for bugs
- π‘ Discussions: Start a discussion for questions
- π§ Email: Contact the maintainers directly
If you find this project helpful:
- β Star the repository on GitHub
- π΄ Fork it for your own projects
- π’ Share it with the community
- π€ Contribute improvements and features
- π¨βπ» Author: truongdq.dev
- π Portfolio: portfolio-peanut.netlify.app
- π¦ Twitter: @truong20013
- π± Telegram: @peanut201
Built with β€οΈ for the developer community in 2025