Skip to content

A modern monorepo boilerplate for building scalable, high-performance microfrontend applications using Rspack, Module Federation, PNPM Workspaces, and Lerna. Includes [NGINX] web server to securely handle remote module requests by validating request origins or referers against an allowed list.

License

Notifications You must be signed in to change notification settings

en-atul/ts-microfrontend-monorepo-kit-rspack-v3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

๐Ÿš€ TypeScript Microfrontend Monorepo Kit - RSpack

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.

Table of Contents

๐ŸŽฏ Overview

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

โœจ Key Features

๐ŸŽจ Core Features

  • โšก๏ธ 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

๐Ÿ› ๏ธ Custom Build Configuration

  • ๐ŸŽฏ 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

๐Ÿ‘จโ€๐Ÿ’ป Developer Experience

  • ๐Ÿ›  Custom dev-cli tool for workflow automation
  • ๐Ÿ“ Comprehensive TypeScript support
  • ๐Ÿงน Unified code formatting and linting
  • โš™๏ธ Shared configurations for all tools
  • ๐Ÿ“š Component library setup

โš™๏ธ Technology Stack

  • ๐Ÿ”ง 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

๐ŸŽ›๏ธ Rspack Configuration Highlights

// 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
		],
	},
};

๐Ÿ“ Project Structure

โ”œโ”€โ”€ 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

๐Ÿ”ง Build Configuration Structure

โ”œโ”€โ”€ 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

๐Ÿš€ Getting Started

๐Ÿ“‹ Prerequisites

  • Node.js >= 18
  • pnpm >= 9.0.0
  • Docker Desktop (for production-like environment)

โšก๏ธ Installation

# 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:setup

๐Ÿ”ง Development Commands

  • pnpm dev: Start all applications in development mode
  • pnpm start:host: Start host application
  • pnpm start:remote: Start remote application
  • pnpm build: Build all applications
  • pnpm lint: Run linting
  • pnpm format: Format code

๐Ÿณ Docker Commands (Production-like Environment)

  • pnpm docker:setup: Complete Docker setup (build + start + health check)
  • pnpm docker:build: Build Docker images
  • pnpm docker:up: Start services in background
  • pnpm docker:down: Stop and remove containers
  • pnpm docker:logs: View logs from all services
  • pnpm docker:health: Check service health
  • pnpm docker:clean: Clean up containers, volumes, and images

๐Ÿ›  Development Tools

๐Ÿค– Dev CLI (@repo/dev-cli)

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

โš™๏ธ Shared Configurations

  • ๐Ÿ“ TypeScript configurations
  • ๐Ÿงน ESLint rules
  • ๐Ÿ”ง Rspack configurations
  • ๐Ÿ›  Babel presets
  • ๐Ÿงช Jest setup

๐Ÿ— Architecture

๐Ÿข Microfrontend Implementation

  1. Host Application: Main application shell

    • ๐Ÿงญ Manages routing
    • ๐Ÿ” Handles authentication
    • ๐ŸŽฎ Orchestrates remote modules
  2. Remote Applications: Independent features

    • ๐Ÿ“ฆ Expose components via Module Federation
    • ๐Ÿš€ Can be deployed independently
    • ๐Ÿ’พ Maintain their own state and routing

๐Ÿ”„ Module Federation

  • ๐Ÿ“ฅ Dynamic loading of remote modules
  • ๐Ÿ”„ Shared dependencies management
  • โšก๏ธ Runtime integration of components
  • ๐Ÿ“ˆ Version control of shared modules

๐Ÿ”’ Security

๐Ÿ›ก๏ธ Remote Module Protection

  • โœ… 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

๐Ÿ“‹ Best Practices

  • ๐Ÿ” Secure module loading with Nginx access control
  • ๐Ÿ›ก๏ธ Protected production endpoints
  • โš™๏ธ Environment-based configurations
  • ๐Ÿ”„ Error boundary implementation
  • ๐Ÿณ Containerized deployment with health checks

๐Ÿ“ฆ Deployment

๐Ÿš€ Development vs Production

Development Mode

# Start with hot reload
pnpm dev
# or individually
pnpm start:host
pnpm start:remote

Production Mode (Docker)

# Complete production setup
pnpm docker:setup

# Access applications
# Host App: http://localhost:3000
# Remote App: http://localhost:3001

๐Ÿณ Docker Deployment

  • 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

๐Ÿ“ค Build Output

  • ๐Ÿ“ฆ Optimized bundles
  • ๐Ÿ—บ๏ธ Source maps
  • ๐ŸŽจ Asset optimization
  • โšก๏ธ Cache management
  • ๐Ÿณ Containerized applications

๐Ÿค Contributing

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE.md file for details.


๐Ÿ’ฌ Support

For questions and support, please open an issue in the GitHub repository.

โญ๏ธ If you find this project helpful, please give it a star!

About

A modern monorepo boilerplate for building scalable, high-performance microfrontend applications using Rspack, Module Federation, PNPM Workspaces, and Lerna. Includes [NGINX] web server to securely handle remote module requests by validating request origins or referers against an allowed list.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published