A production-ready monorepo boilerplate for building scalable microfrontend applications, powered by modern web technologies and best practices. Built entirely from scratch without using any cli tools, providing complete control over the build configuration and development workflow.
- ๐ฏ Overview
- โจ Key Features
- โ๏ธ Technology Stack
- ๐ Project Structure
- ๐ Getting Started
- ๐ Development Tools
- ๐ Architecture
- ๐ Security
- ๐ฆ Deployment
- ๐ค Contributing
- ๐ License
This monorepo provides a complete foundation for building scalable microfrontend applications. It solves several key challenges in modern web development:
- ๐ข Microfrontend Architecture: Implement independent, deployable frontend applications that work together seamlessly
- ๐ Code Sharing: Share components and logic between applications efficiently using Rspack Module Federation
- ๐ Type Safety: Full TypeScript support across all applications and packages
- โก๏ธ Development Workflow: Streamlined development experience with hot reloading and custom CLI tools
- ๐ก๏ธ Security: Built-in protection for remote module access using Nginx web server with referer-based validation
- ๐ Scalability: Monorepo structure that scales with your team and application needs
- ๐๏ธ Full Configuration Control: Custom Rspack configuration built from ground up, offering maximum flexibility
- โก๏ธ Rspack Module Federation for component sharing
- ๐ Secure Nginx web server with referer-based access control for remote module protection
- ๐ Hot Module Replacement (HMR) support
- ๐ฆ Optimized production builds
- ๐จ CSS/SCSS Modules support
- ๐งช Testing setup with Jest
- ๐ฏ Built From Scratch: No black-box configurations from Create React App or Vite
- โ๏ธ Custom Rspack Setup: Full control over build process and optimizations
- ๐ง Extensible Configuration: Easy to add new features and customize build behavior
- ๐ฆ Optimized Bundling: Fine-tuned Rspack configuration for optimal performance
- ๐ Hot Reload: Rspack's built-in development server with HMR
- ๐จ Asset Handling: Built-in support for various file types
- ๐ Performance Optimizations:
- Code splitting
- Tree shaking
- Chunk optimization
- Dynamic imports
- Module federation
- Cache optimization
- ๐ Custom dev-cli tool for workflow automation
- ๐ Comprehensive TypeScript support
- ๐งน Unified code formatting and linting
- โ๏ธ Shared configurations for all tools
- ๐ Component library setup
- ๐ง Core: React 18, TypeScript, Rspack
- ๐จ Styling: CSS Modules, SCSS
- ๐ฆ Monorepo: pnpm Workspaces, Lerna
- โจ Quality: ESLint, Prettier, Jest
- ๐ Development: Custom CLI, Rspack Dev Server with HMR, Docker with Nginx for production
- ๐ Build: Rspack optimizations
// Example of the flexible Rspack configuration
module.exports = {
// Core build optimization
optimization: {
splitChunks: {
chunks: 'all',
// Customizable chunking strategy
},
runtimeChunk: 'single',
},
// Module Federation for micro-frontends
builtins: {
federation: {
// Customizable sharing strategy
shared: {
react: { singleton: true },
'react-dom': { singleton: true },
},
},
},
// Nginx web server with security configuration
// Production deployment uses Nginx for access control
// See nginx.conf for referer-based validation
// Extensible module configuration
module: {
rules: [
// TypeScript/JavaScript processing
// CSS/SCSS handling
// Asset optimization
// Custom rule configurations
],
},
};โโโ apps/ # Microfrontend applications
โ โโโ host/ # Host application
โ โโโ remote/ # Remote application
โโโ packages/ # Shared packages
โ โโโ dev-cli/ # Development workflow tools
โ โโโ ui/ # Shared UI components
โ โโโ utils/ # Common utilities
โ โโโ configs/ # Shared configurations
โโโ scripts/ # Build and utility scripts
โโโ package.json # Root package file
โโโ rspack/
โ โโโ common.js # Shared Rspack configuration
โ โโโ development.js # Development-specific settings
โ โโโ production.js # Production optimizations
โ โโโ module-fed.js # Module Federation setup
โโโ apps/
โ โโโ host/
โ โ โโโ nginx.conf # Nginx configuration for host app
โ โ โโโ Dockerfile # Docker configuration for host app
โ โโโ remote/
โ โโโ nginx.conf # Nginx configuration for remote app
โ โโโ Dockerfile # Docker configuration for remote app
โโโ docker-compose.yml # Docker orchestration
โโโ DOCKER.md # Docker setup documentation
- Node.js >= 18
- pnpm >= 9.0.0
- Docker Desktop (for production-like environment)
# Clone the repository
git clone https://github.com/your-username/ts-microfrontend-monorepo-kit.git
# Install dependencies
pnpm install
# Start development
pnpm dev
# For production-like environment with Docker
pnpm docker:setuppnpm dev: Start all applications in development modepnpm start:host: Start host applicationpnpm start:remote: Start remote applicationpnpm build: Build all applicationspnpm lint: Run lintingpnpm format: Format code
pnpm docker:setup: Complete Docker setup (build + start + health check)pnpm docker:build: Build Docker imagespnpm docker:up: Start services in backgroundpnpm docker:down: Stop and remove containerspnpm docker:logs: View logs from all servicespnpm docker:health: Check service healthpnpm docker:clean: Clean up containers, volumes, and images
Custom CLI tool that provides:
- ๐ Workflow automation
- ๐ฅ๏ธ Development server management
- โก๏ธ Build process optimization
- ๐ Project scaffolding
Usage:
# Create a new component
dev-cli generate component
# Run development servers
dev-cli serve- ๐ TypeScript configurations
- ๐งน ESLint rules
- ๐ง Rspack configurations
- ๐ Babel presets
- ๐งช Jest setup
-
Host Application: Main application shell
- ๐งญ Manages routing
- ๐ Handles authentication
- ๐ฎ Orchestrates remote modules
-
Remote Applications: Independent features
- ๐ฆ Expose components via Module Federation
- ๐ Can be deployed independently
- ๐พ Maintain their own state and routing
- ๐ฅ Dynamic loading of remote modules
- ๐ Shared dependencies management
- โก๏ธ Runtime integration of components
- ๐ Version control of shared modules
- โ Referer-based validation using Nginx web server
- ๐ Configurable access controls for remoteEntry.js files
- ๐ CORS protection with proper headers
- โก๏ธ Production-ready security with Nginx reverse proxy
- ๐ Secure module loading with Nginx access control
- ๐ก๏ธ Protected production endpoints
- โ๏ธ Environment-based configurations
- ๐ Error boundary implementation
- ๐ณ Containerized deployment with health checks
# Start with hot reload
pnpm dev
# or individually
pnpm start:host
pnpm start:remote# Complete production setup
pnpm docker:setup
# Access applications
# Host App: http://localhost:3000
# Remote App: http://localhost:3001- Multi-stage builds for optimized images
- Nginx reverse proxy with security headers
- Health checks for container monitoring
- CORS configuration for microfrontend federation
- Access control via referer validation
- ๐ฆ Optimized bundles
- ๐บ๏ธ Source maps
- ๐จ Asset optimization
- โก๏ธ Cache management
- ๐ณ Containerized applications
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE.md file for details.
For questions and support, please open an issue in the GitHub repository.
โญ๏ธ If you find this project helpful, please give it a star!