Fullstack > Architecture > π Micro Frontends
Micro Frontends is an architectural style where a frontend app is decomposed into individual, semi-independent βmicro-appsβ that are owned by different teams and developed, tested, and deployed independently.
This approach extends the principles of microservices to the frontend, helping to scale frontend development across multiple teams and codebases.
β Why Micro Frontends?
Micro Frontends solve key challenges in large frontend applications:
- π οΈ Scalability: Teams can work independently on different parts of the frontend.
- π¨ Flexibility: Different frameworks or versions can coexist across different micro-apps.
- π Independent Deployment: Each micro-frontend can be deployed without redeploying the entire frontend.
- π₯ Code Ownership: Teams have full ownership over their UI features.
- π§Ή Maintainability: Smaller, isolated codebases are easier to manage and test.
π§© Micro Frontend Components
1οΈβ£ Micro App
Each micro app is a self-contained frontend module responsible for a distinct feature or domain of the application. Examples include:
- π€ User Profile
- π Shopping Cart
- π Admin Dashboard
Each micro app can be:
- Built with a specific frontend framework (Angular, React, Vue, etc.)
- Developed and deployed independently
- Loaded dynamically at runtime or during the build phase
2οΈβ£ Shell (Container Application)
The Shell (also called Host or Container) is the main application responsible for:
- ποΈ Bootstrapping the overall frontend
- ποΈ Orchestrating which micro apps are loaded and when
- π Handling shared concerns like authentication, routing, layout, and state management
The shell can use integration strategies like:
- π§© Module Federation (Webpack 5)
- π Single-SPA
- πΌοΈ Iframe-based embedding (legacy)
3οΈβ£ Routing and Composition
Routing in a micro frontend setup can be handled:
- π Centrally in the Shell (e.g., using Angular Router)
- πΊοΈ Decentralized, where each micro app handles its own routing
Apps are composed into the shell:
- π οΈ Statically during build time (e.g., monorepo)
- β‘ Dynamically during runtime (e.g., remote modules with Webpack Module Federation)
4οΈβ£ Shared Libraries and Dependencies
To avoid duplication and reduce bundle size, micro apps can share:
- π¨ UI libraries (e.g., Angular Material, Tailwind)
- ποΈ State management libraries
- π οΈ Utility functions
These shared dependencies are typically declared as singletons when using Module Federation.
π Micro Frontends in Fullstack Applications
With Angular
- Each micro app is an Angular project (or module) with its own
main.ts,AppModule, routes, and components. - The shell application integrates all micro apps and handles root-level concerns.
- Shared services (like authentication, config, etc.) are injected via the shell or imported as shared libraries.
π Integration Strategies
- π§© Module Federation (Webpack 5) β Recommended for modern Angular setups
- π Single-SPA β Framework-agnostic and highly flexible
- βοΈ Custom Integration β Using dynamic script injection or iframes
π Folder Structure Example
microfrontends-app/
βββ shell-app/
β βββ src/
β βββ webpack.config.js
β βββ angular.json
βββ user-profile-app/
β βββ src/
β βββ webpack.config.js
β βββ angular.json
βββ orders-app/
β βββ src/
β βββ webpack.config.js
β βββ angular.json
βββ shared-lib/
βββ src/