A comprehensive implementation of Module Federation using React 18 Suspense Streaming, TypeScript, Rspack, and modern web development best practices. Features real-time streaming components with enhanced UX and visual indicators for conference demonstrations.
๐ข Latest Update: Enhanced with React 18 Suspense streaming components and improved flat design with better color contrast for optimal user experience!
This project demonstrates a micro-frontend architecture with React 18 Suspense streaming for enhanced user experience:
- Shell Application (
localhost:3000) - Main orchestrator with streaming indicators - Products Module (
localhost:3001) - Product catalog with streaming delays (Blue theme) - Cart Module (
localhost:3002) - Shopping cart with real-time updates (Green theme) - Dashboard Module (
localhost:3003) - User analytics with streaming data (Violet theme)
- Flat Design: Clean, modern interface with improved color contrast
- Streaming Indicators: Clear visual feedback showing which service is streaming
- Theme Consistency: Color-coded modules for easy identification during demos
- Enhanced UX: Better accessibility and reduced cognitive load
- Conference Ready: Optimized for live demonstrations and presentations
- React 18 Suspense: Advanced streaming with skeleton loading states
- Hooks Optimization:
useCallback,useMemo,memofor performance - Component Architecture: Memoized, reusable components with proper separation
- Error Boundaries: Comprehensive error handling for module federation
- Accessibility: ARIA labels, semantic HTML, proper focus management
- Event Handling: Custom events for inter-module communication
- State Management: Efficient local state with proper TypeScript typing
- Streaming Components: Real-time data loading with visual feedback
- Strict Configuration: Enhanced
tsconfig.jsonwith strict rules - Type Safety: Comprehensive interfaces and readonly properties
- Path Mapping: Clean import paths with alias configuration
- Union Types: Proper enum-like types for better type safety
- Generic Components: Flexible, reusable component typing
- Event Types: Custom event interfaces for type-safe communication
- Development Experience: Hot reloading, source maps, error overlays
- Production Optimization: Code splitting, tree shaking, minification
- Caching Strategy: Filesystem caching for faster rebuilds
- Bundle Analysis: Performance hints and size optimization
- Module Federation: Optimized sharing and loading strategies
- Flat Design: Modern clean interface with improved color contrast
- Responsive Design: Mobile-first approach with Tailwind CSS
- Streaming States: Real-time skeleton screens and loading indicators
- Visual Feedback: Clear service identification and streaming status
- Micro-interactions: Hover effects, transitions, and animations
- Error States: User-friendly error messages and fallbacks
- Progressive Enhancement: Graceful degradation for failed modules
- Conference Demo Ready: Enhanced visibility for live presentations
- Node.js 20+ (required for Tailwind CSS v4)
- npm or yarn
- Modern browser (Safari 16.4+, Chrome 111+, Firefox 128+)
# Install dependencies
npm install
# Start all applications concurrently
npm run dev
# Access the applications
# Shell: http://localhost:3000
# Products: http://localhost:3001
# Cart: http://localhost:3002
# Dashboard: http://localhost:3003# Products module
cd packages/products && npm run dev
# Cart module
cd packages/cart && npm run dev
# Dashboard module
cd packages/dashboard && npm run dev
# Shell application
cd packages/shell && npm run devmodule-federation-demo/
โโโ packages/
โ โโโ shell/ # Main orchestrator app
โ โ โโโ src/
โ โ โ โโโ components/ # Reusable UI components
โ โ โ โ โโโ ErrorBoundary.tsx
โ โ โ โ โโโ LoadingSpinner.tsx
โ โ โ โ โโโ ModuleFallback.tsx
โ โ โ โโโ lib/ # Utility functions
โ โ โ โโโ App.tsx # Main app component
โ โ โ โโโ bootstrap.tsx # Module federation bootstrap
โ โ โโโ rspack.config.js # Enhanced Rspack configuration
โ โ โโโ tsconfig.json # Strict TypeScript config
โ โโโ products/ # Product catalog module (Blue theme)
โ โ โโโ src/
โ โ โ โโโ ProductsCatalog.tsx # Main product component
โ โ โ โโโ StreamingProductsCatalog.tsx # Streaming version with delays
โ โ โ โโโ types.ts # TypeScript definitions
โ โ โ โโโ lib/ # Shared utilities
โ โ โโโ rspack.config.js # Module federation config
โ โโโ cart/ # Shopping cart module (Green theme)
โ โ โโโ src/
โ โ โ โโโ ShoppingCart.tsx # Cart management
โ โ โ โโโ StreamingShoppingCart.tsx # Streaming version with updates
โ โ โ โโโ types.ts # Cart-specific types
โ โ โโโ rspack.config.js
โ โโโ dashboard/ # User dashboard module (Violet theme)
โ โโโ src/
โ โ โโโ UserDashboard.tsx # Analytics dashboard
โ โ โโโ StreamingUserDashboard.tsx # Streaming version with data
โ โ โโโ types.ts # Dashboard types
โ โโโ rspack.config.js
โโโ package.json # Root package with scripts
โโโ README.md # This file
// Adding items to cart (Products โ Cart)
window.dispatchEvent(
new CustomEvent("addToCart", {
detail: cartItem,
bubbles: true,
})
);
// User notifications (Global)
window.dispatchEvent(
new CustomEvent("showNotification", {
detail: {
type: "success",
message: "Item added to cart!",
},
})
);// Custom event interfaces
export interface AddToCartEvent extends CustomEvent {
detail: CartItem;
}
export interface NotificationEvent extends CustomEvent {
detail: {
type: "success" | "error" | "info" | "warning";
message: string;
};
}
declare global {
interface WindowEventMap {
addToCart: AddToCartEvent;
showNotification: NotificationEvent;
}
}| Technology | Version | Purpose |
|---|---|---|
| React | ^18.3.1 | UI library with modern hooks |
| TypeScript | ^5.6.2 | Type-safe development |
| Rspack | ^0.7.5 | Fast bundler with Module Federation |
| Tailwind CSS | ^4.0.0 | Modern utility-first styling |
| PostCSS | ^8.4.0 | CSS processing |
| Module Federation | Enhanced | Micro-frontend architecture |
- โก Code Splitting: Automatic chunk splitting for optimal loading
- ๐ Lazy Loading: Components loaded on demand
- ๐พ Caching: Filesystem caching for faster rebuilds
- ๐ฆ Tree Shaking: Dead code elimination
- ๐๏ธ Bundle Analysis: Size optimization and performance hints
- ๐ฅ Hot Module Replacement: Instant updates during development
- ๐ Source Maps: Enhanced debugging capabilities
- ๐ TypeScript Integration: Full type checking and IntelliSense
- ๐จ Tailwind Integration: v4 with CSS-based configuration and modern features
- ๐ Error Overlays: Clear error messages in development
- ๐ Error Boundaries: Graceful error handling
- ๐ฑ Responsive Design: Mobile-first approach
- โฟ Accessibility: WCAG compliance with ARIA support
- ๐ Cross-Origin: Proper CORS configuration
- ๐ Performance Monitoring: Bundle size tracking
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Generate coverage report
npm run test:coverage- Initial Load: < 100kb gzipped
- Module Load: < 50kb per module
- Hot Reload: < 200ms
- Build Time: < 30s for full rebuild
npm run devnpm run buildnpm run preview- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Functional components with hooks
- Memoization with
React.memo,useMemo,useCallback - Proper dependency arrays in hooks
- Error boundaries for graceful failures
- Accessibility with ARIA labels
- Semantic HTML structure
- Strict mode enabled
- Readonly properties where applicable
- Union types for better type safety
- Generic components and functions
- Proper event typing
- Path mapping for clean imports
- Code splitting and lazy loading
- Tree shaking enabled
- Development optimizations
- Production optimizations
- Proper caching strategy
- Bundle size optimization
- Component memoization
- Bundle size monitoring
- Lazy loading of modules
- Efficient re-rendering
- Optimized asset loading
- Proper caching headers
- Module Federation Documentation
- React 18 Documentation
- TypeScript Handbook
- Rspack Documentation
- Tailwind CSS Guide
This project is licensed under the MIT License - see the LICENSE file for details.
Built with โค๏ธ using modern web technologies and best practices