A modern todo application built using micro-frontend architecture with React, Vite, and Module Federation. This project demonstrates how to build scalable applications by breaking them into independent, deployable micro-frontends.
This application consists of four independent micro-frontends:
- Container App (Port 5000) - Main host application that orchestrates other micro-frontends
- Todo List (Port 5001) - Displays and manages the list of todos
- Todo Form (Port 5002) - Handles adding new todos
- UI Components (Port 5003) - Shared component library with reusable UI elements
- β Add new todos
- β Delete existing todos
- β Authentication system
- β Shared UI component library
- β CORS configuration for security
- β Module Federation for runtime integration
- β Independent deployment capabilities
- Frontend Framework: React 18
- Build Tool: Vite
- Module Federation: @originjs/vite-plugin-federation
- Styling: CSS3
- Authentication: JWT (Mock implementation)
- Node.js (v16 or higher)
- npm or yarn
- Clone the repository:
git clone <repository-url>
cd micro-frontend- Install dependencies for each micro-frontend:
# Install UI Components dependencies
cd ui-components
npm install
cd ..
# Install Todo List dependencies
cd todo-list
npm install
cd ..
# Install Todo Form dependencies
cd todo-form
npm install
cd ..
# Install Container dependencies
cd container
npm install
cd ..Important: Start the applications in the following order:
- Start UI Components (Terminal 1):
cd ui-components
npm run build && npm run preview- Start Todo List (Terminal 2):
cd todo-list
npm run build && npm run preview- Start Todo Form (Terminal 3):
cd todo-form
npm run build && npm run preview- Start Container App (Terminal 4):
cd container
npm run dev- Open your browser and navigate to
http://localhost:5000
The application includes a mock authentication system:
- Username:
admin - Password:
password
- Container App: http://localhost:5000
- Todo List: http://localhost:5001
- Todo Form: http://localhost:5002
- UI Components: http://localhost:5003
Each micro-frontend is configured with CORS to whitelist specific domains:
- Prevents unauthorized cross-origin requests
- Allows credentials for authenticated requests
- Configurable for different environments
- JWT-based authentication (mock implementation)
- Protected routes and components
- Session persistence with localStorage
- Main orchestrator application
- Handles authentication state
- Loads and coordinates other micro-frontends
- Displays list of todos
- Handles todo deletion
- Protected by authentication
- Form for adding new todos
- Input validation
- Protected by authentication
- Button: Reusable button component with variants
- Card: Container component with elevation levels
- Input: Form input with validation support
- Login: Authentication form component
# Start all applications in development mode
cd ui-components && npm run dev &
cd todo-list && npm run dev &
cd todo-form && npm run dev &
cd container && npm run dev# Build all applications
cd ui-components && npm run build
cd todo-list && npm run build
cd todo-form && npm run build
cd container && npm run buildEach micro-frontend can be deployed independently:
- Build the application:
npm run build - Deploy the
distfolder to your hosting service - Update the remote URLs in the container's
vite.config.js
For production deployment, update the remote URLs in container/vite.config.js:
remotes: {
todo_list: "https://your-todo-list-domain.com/assets/remoteEntry.js",
todo_form: "https://your-todo-form-domain.com/assets/remoteEntry.js",
ui_components: "https://your-ui-components-domain.com/assets/remoteEntry.js"
}- Create component in appropriate micro-frontend
- Export in
vite.config.jsexposes section - Import in consuming application
- Each component has its own CSS file
- Consistent design system across components
- Easily customizable themes
-
Module Federation Errors:
- Ensure all remote applications are running
- Check port configurations
- Verify remote URLs in vite.config.js
-
CORS Errors:
- Check CORS configuration in vite.config.js
- Ensure all domains are whitelisted
-
Build Errors:
- Clear node_modules and reinstall dependencies
- Check for missing files or incorrect paths
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.
For questions or support, please open an issue in the repository.
Built with β€οΈ using Micro-Frontend Architecture