Micro Frontend (MFE) Architecture with Angular & Nx

posted 2 min read

To fully understand Micro Frontends (MFEs), especially with Angular + Nx + Module Federation, it's helpful to look at a layered architecture diagram and explanation of each piece.


Here’s a high-level conceptual architecture:

                           ┌────────────────────────┐
                           │       Shell App        │
                           │ (App Host/Container)   │
                           └────────────┬───────────┘
                                        │
       ┌────────────────────────────────┼─────────────────────────────────┐
       ▼                                ▼                                 ▼
┌────────────┐                ┌────────────────┐               ┌────────────────┐
│ Product MFE│                │ Checkout MFE   │               │ Profile MFE    │
│ (Remote)   │                │ (Remote)       │               │ (Remote)       │
└────────────┘                └────────────────┘               └────────────────┘

  │                                  │                                  │
  ▼                                  ▼                                  ▼
┌──────────────────┐     ┌────────────────────┐         ┌────────────────────┐
│ Feature Module(s)│     │ Feature Module(s)  │         │ Feature Module(s)  │
│ - Routing        │     │ - Routing          │         │ - Routing          │
│ - UI Components  │     │ - UI Components    │         │ - UI Components    │
└──────────────────┘     └────────────────────┘         └────────────────────┘

                   Shared Libraries (e.g., libs/ui, libs/auth, libs/api)
                   └─────────────────────────────────────────────────────┘

Key Building Blocks

1. Shell App (Host)

  • Acts as the entry point to the entire system.
  • Loads remote MFEs via Webpack Module Federation.
  • Defines global routing and layout (e.g. header, nav).

Example:

{
  path: 'product',
  loadChildren: () =>
    loadRemoteModule('product', './Module').then((m) => m.ProductModule),
}

2. Remote Apps (MFEs)

Each MFE:

  • Is a standalone Angular app.
  • Exposes one or more modules (via exposes in module-federation.config.ts).
  • Has its own routing, logic, and optionally independent deployment.

Example:

exposes: {
  './Module': './src/app/product/product.module.ts',
}

3. Feature Modules

  • Encapsulated functionality for that domain (e.g. ProductModule, CheckoutModule).
  • Follows Angular's modular architecture.
  • Supports lazy loading.

4. Shared Libraries (libs/)

  • Cross-cutting concerns like UI components, auth services, or API clients.

  • You can create domain-specific libraries like:

    libs/ui
    libs/data-access/orders
    libs/shared/auth
    
  • Helps enforce Domain-Driven Design (DDD) and code boundaries.


Deployment Models

Option A: Unified Deployment

  • All MFEs deployed together.
  • Shell and remotes served from the same domain (monorepo).
  • Simpler CI/CD.

Option B: Independent Deployment

  • Each MFE has its own CI/CD and hosting.
  • Shell loads them from remote URLs (e.g. S3, Vercel).
  • True autonomy and scalability.
remotes: [
  ['product', 'https://product.domain.com/remoteEntry.js'],
]

Advantages of This Architecture

Benefit Explanation
Independent Teams Teams can work and deploy separately.
Faster Builds Smaller builds due to separation.
Reusable Modules Use shared libraries without duplication.
Lazy Loading Improves initial load time.
Clear Domain Boundaries Encourages DDD and maintainability.

Recommended Nx Workspace Folder Structure

apps/
  shell/           ← host application
  product/         ← remote MFE
  checkout/        ← remote MFE
libs/
  ui/              ← shared UI components
  auth/            ← authentication logic
  data-access/     ← shared API calls
  shared/utils/    ← utility functions

If you read this far, tweet to the author to show them you care. Tweet a Thanks

More Posts

Main approaches to work with dynamic strings in Angular templates.

Sunny - May 14

Datadog implementation in an Angular project.

Sunny - Jun 21

Frontend Development: React vs Angular - Getting Started

Deekshith Raj Basa - Mar 25

How to Maintain Fast Load Time in Angular Apps

Sunny - Jun 18

Concise list of Angular essentials

Sunny - Jun 6
chevron_left