A production-grade starter framework for Micro-Frontends (MFE) powered by pnpm Workspaces, Turborepo, Module Federation 2.0 (@module-federation/vite), React 19, React Router v8, and Tailwind CSS v4.
Splits complex web applications into decoupled, independently deployable micro-frontends with live HMR, zero-touch dynamic routing, runtime URL overrides, type safety, and socket isolation.
- ποΈ Architecture Specification: Deep dive into Module Federation 2.0, Host Shell orchestration, route specificity sorting, and universal adapters.
- π» Development & Workflows Guide: Local development workflows, targeted DX (
pnpm dev:only), safe port guard, remote scaffolding (pnpm mfe:create), and repository garbage collection. - β‘ Runtime Configuration & Event Architecture: Dynamic runtime remote URL injection (
window.__MFE_RUNTIME_CONFIG__), type-safe cross-MFE event bus, and edge caching strategies.
mfe/ (Root Workspace)
βββ .github/workflows/ci.yml # GitHub Actions automated lint, typecheck, & build
βββ turbo.json # Turborepo task pipeline & caching graph
βββ remotes.manifest.json # Single Source of Truth for all active micro-frontends
βββ scripts/ # Orchestration, code generation, and integrity tools
β βββ orchestrate.js # Dev and build concurrency coordinator
β βββ manifest.js # Manifest validator and command builder
β βββ port-guard.js # Safe listener-only socket inspector
β βββ generate-remotes-dts.js # Zero-touch route registry & ambient type generator
β βββ create-remote.js # Interactive / flag-based remote generator
β βββ garbage-collector.js # Monorepo dead code and drift auditor
β βββ reset-demo.js # Reset workspace to clean starter slate
β βββ restore-demo.js # Restore demo services snapshot
β
βββ apps/ # Deployable application containers & micro-frontends
β βββ host/ # Primary Shell Container (Port 5000)
β β βββ src/
β β β βββ components/ # Shell UI (RemoteErrorBoundary, LoadingFallback)
β β β βββ pages/ # LandingPage dashboard and live event feed
β β β βββ plugins/ # runtimeRemoteOverride.js (MF 2.0 runtime plugin)
β β β βββ utils/ # resolveRemoteUrl.js & telemetry.js (APM hooks)
β β β βββ remotesRegistry.jsx# Auto-generated dynamic remote route registry
β β β βββ remotes.d.ts # Auto-generated ambient TypeScript declarations
β β β βββ App.jsx # Dynamic routing & error boundaries
β β β βββ main.jsx # Entry point (sets window.__IS_HOST__)
β β βββ vercel.json # Host-specific edge routing & cache headers
β β βββ vite.config.js # Federation consumer configuration
β β
β βββ marketing-mfe/ # Marketing Micro-Frontend (Port 5002)
β β βββ vercel.json # Independent edge deployment rules
β β βββ vite.config.js # defineRemoteConfig preset
β β
β βββ auth-mfe/ # Authentication Micro-Frontend (Port 5003)
β βββ vercel.json # Independent edge deployment rules
β βββ vite.config.js # defineRemoteConfig preset
β
βββ packages/ # Shared libraries, adapters, and tools
β βββ shared/ # Core Library (@subrataroy100/mfe-shared)
β βββ src/
β β βββ adapters/ # UniversalRemoteMount, Shadow DOM, dual-mode mounts
β β βββ events/ # Scoped Event Bus, pure JS core, React hooks, event replay
β β βββ vite/ # defineRemoteConfig preset + CSS auto-injection
β β βββ components/ # Shared UI primitives (Button)
β β βββ constants/ # Shared ports, origins, and configuration
β β βββ index.js # Barrel export
β βββ package.json # Dual ESM/CJS exports with tracked .d.ts types
β
βββ docs/ # Architectural and operational guides
βββ netlify.toml # Root unified edge headers (preview deployments)
βββ vercel.json # Root unified edge headers (preview deployments)
βββ package.json # Root scripts and workspace devDependencies
βββ pnpm-workspace.yaml # Monorepo package directories (apps/*, packages/*)
- Node.js:
>= 20.0.0 - pnpm:
12.x(enforced viadevEngines&packageManager)
Install all dependencies from the workspace root:
pnpm installpnpm devThis single command:
- Runs Safe Port Guard: Checks and frees orphaned background sockets on configured ports (5000, 5002, 5003...).
- Generates Route Registry & Types: Reads
remotes.manifest.jsonand updatespackages/host/src/remotesRegistry.jsxandremotes.d.ts. - Boots Dev Servers Concurrently: Starts the host shell and each registered remote with live Vite HMR.
Open http://localhost:5000 in your browser to view the Host dashboard.
Micro-frontends run standard Vite dev servers using Module Federation 2.0 (dev: { remoteHmr: true }). Edits to remote components appear instantly inside the running host application without requiring full rebuilds or browser reloads.
Avoid running every remote simultaneously when working on a single feature:
# Boots only the Host Shell (port 5000) and marketingMfe (port 5002)
pnpm dev:only marketingMfeNo manual router editing is needed when adding or removing micro-frontends:
- Manifest entries in
remotes.manifest.jsonare automatically converted into lazy-loaded routes inremotesRegistry.jsx. - Specificity Sorting: Deeper and explicit routes (e.g.,
/marketing/features/*,/auth/*) are automatically mounted before shallow paths (/*), preventing wildcard hijacking. - Isolated Error Boundaries: Every remote route is wrapped in
<RemoteErrorBoundary>and Suspense fallbacks. If a remote fails or throws an unhandled error, the Host navigation and sibling remotes remain completely unaffected.
Deploy remotes independently to staging or CDN environments without rebuilding the host shell container:
<script>
window.__MFE_RUNTIME_CONFIG__ = {
marketingMfe: "https://staging-cdn.example.com/marketing/mf-manifest.json",
authMfe: "https://staging-cdn.example.com/auth/mf-manifest.json"
};
</script>The Host's Module Federation 2.0 runtime plugin intercepts requests dynamically in the browser. Build-time defaults in .env (VITE_MARKETING_MFE_URL) are read automatically via loadEnv().
Micro-frontends communicate asynchronously without shared global stores:
import { createMfeEventBus } from "@subrataroy100/mfe-shared/events";
// Scoped event bus
const bus = createMfeEventBus({ sender: "authMfe", namespace: "auth" });
bus.send("user:login", { userId: "usr_100" });
// React Hook with automatic lifecycle unmount cleanup
bus.useListener("user:logout", (detail) => {
console.log("Logged out:", detail);
});Scaffold a complete, fully connected micro-frontend with auto-allocated ports in one command:
pnpm mfe:create billingService --path /billing --framework react| Command | Description |
|---|---|
pnpm dev |
Runs port guard, generates registry & types, then launches host and remotes with live HMR. |
pnpm dev:only <name> |
Targeted DX: Boots only the Host Shell and a specific Remote (e.g. pnpm dev:only marketingMfe). |
pnpm mfe:create <name> |
Scaffolds a new remote package, auto-allocates port, updates manifest, and mounts routes. |
pnpm clean:ports |
Safely detects and terminates orphaned listeners on configured MFE ports. |
pnpm build |
Production build across all packages using Turborepo with outputs caching. |
pnpm build:remotes |
Builds all remote micro-frontends using Turborepo (turbo run build --filter=!host). |
pnpm build:host |
Builds the host shell container (turbo run build --filter=host). |
pnpm remotes:list |
Prints a summary table of all active remotes configured in remotes.manifest.json. |
pnpm typecheck |
Generates types and validates TypeScript definitions across workspaces and tests. |
pnpm test |
Runs all unit and integration tests via Vitest. |
pnpm test:watch |
Runs Vitest in interactive watch mode. |
pnpm test:coverage |
Generates full test coverage report via @vitest/coverage-v8. |
pnpm lint |
Runs oxlint across all workspace packages via Turborepo. |
pnpm preview |
Serves the production build of the host shell. |
pnpm reset:demo |
Resets workspace to clean starter slate (backs up demo remotes to .demo-backup/). |
pnpm restore:demo |
Restores demo micro-frontends from .demo-backup/. |
pnpm gc |
Runs the monorepo Garbage Collector to audit drift, dead code, and stale artifacts. |
pnpm gc:check |
Non-destructive CI check for repo consistency and orphan configurations. |
pnpm gc:fix |
Automatically remedies detected monorepo drift and cleans stale entries. |
For optimal CDN performance and instant updates:
remoteEntry.js/mf-manifest.json: Must never be cached (Cache-Control: no-cache, no-store, must-revalidate).- Hashed Assets (
/assets/*): Cached permanently with max immutable lifetimes (Cache-Control: public, max-age=31536000, immutable).
Pre-configured headers are included for:
- Netlify:
netlify.toml - Vercel:
vercel.json
MIT Β© Subrata Roy