A scalable Micro Frontend architecture built with React, TypeScript, Vite, Module Federation, and pnpm Workspaces.
This project demonstrates how to split a frontend application into independently developed and built applications while maintaining a unified development environment through a Monorepo.
The project consists of four independent applications:
| Application | Role | Development Port | Preview Port |
|---|---|---|---|
| Shell | Host application | 3000 | 4000 |
| Products | Products remote | 3001 | 4001 |
| Cart | Shopping cart remote | 3002 | 4002 |
| Auth | Authentication remote | 3003 | 4003 |
flowchart TB
Shell["Shell (Host)<br/>:3000 / :4000"]
Products["Products (Remote)<br/>:3001 / :4001"]
Cart["Cart (Remote)<br/>:3002 / :4002"]
Auth["Auth (Remote)<br/>:3003 / :4003"]
Shell --> Products
Shell --> Cart
Shell --> Auth
The Shell application acts as the host and consumes exposed modules from the remote applications using Module Federation.
- React
- TypeScript
- Vite
- Module Federation (
@module-federation/vite) - pnpm Workspaces
- ESLint
micro-frontend-monorepo/
│
├── apps/
│ ├── shell/
│ ├── products/
│ ├── cart/
│ └── auth/
│
├── package.json
├── pnpm-workspace.yaml
└── README.md
- Micro Frontend architecture using Module Federation.
- Monorepo management with pnpm Workspaces.
- Independent applications with separate development servers.
- Remote module integration through a host application.
- Shared React and React DOM dependencies.
- Environment-based remote configuration.
- Independent production builds.
- Production build preview for all applications.
- Centralized development, build, preview, and lint commands.
- Node.js
- pnpm
git clone https://github.com/YOUR_USERNAME/micro-frontend-monorepo.git
cd micro-frontend-monorepo
pnpm installRun all applications simultaneously:
pnpm devOr run an individual application:
pnpm dev:shell
pnpm dev:products
pnpm dev:cart
pnpm dev:authBuild all applications:
pnpm buildBuild an individual application:
pnpm build:shell
pnpm build:products
pnpm build:cart
pnpm build:authStart all preview servers:
pnpm previewpnpm lintRemote entry URLs are configured through a centralized .env file in the Shell application.
Development remotes:
VITE_PRODUCTS_DEV=http://localhost:3001/remoteEntry.js
VITE_CART_DEV=http://localhost:3002/remoteEntry.js
VITE_AUTH_DEV=http://localhost:3003/remoteEntry.jsProduction preview remotes:
VITE_PRODUCTS_PREVIEW=http://localhost:4001/remoteEntry.js
VITE_CART_PREVIEW=http://localhost:4002/remoteEntry.js
VITE_AUTH_PREVIEW=http://localhost:4003/remoteEntry.jsVite's mode-based configuration selects the appropriate remote URLs during development and production builds.
These two concepts solve different architectural problems:
Monorepo is a codebase management strategy that allows multiple applications and packages to live in a single repository.
Micro Frontend is an architectural approach that divides a frontend application into smaller, independently developed and deployable parts.
This project combines both approaches:
- pnpm Workspaces manages the applications within one repository.
- Module Federation enables runtime integration between independently built frontend applications.
This project explores:
- Micro Frontend architecture and its trade-offs.
- Module Federation and remote module loading.
- Host and remote application responsibilities.
- Monorepo management using pnpm Workspaces.
- Shared dependencies between federated applications.
- Environment-based configuration.
- Independent builds and production preview workflows.
- CI/CD integration.
- Automated testing.
- Independent deployment pipelines.
- Runtime remote configuration.
- Error boundaries and remote loading fallbacks.
- Shared design system and component library.
- Docker-based deployment.
- Production hosting with Nginx.
MIT