# gmurtaza786/module-federation-plugin-example architecture

> Architecture diagram of the GitHub repository gmurtaza786/module-federation-plugin-example, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gmurtaza786/module-federation-plugin-example
- Repository: https://github.com/gmurtaza786/module-federation-plugin-example

## Overview

##### What this project is (type + purpose)

This repo is an **Angular workspace (monorepo) demonstrating Micro Frontends using Webpack 5 Module Federation via `@angular-architects/module-federation`**.

Purpose (from README + structure):
- A **Shell/Host SPA** (`projects/shell`) runs as the main Angular app.
- A **Remote Microfrontend** (`projects/mfe1`) is built/served separately and **lazy-loaded at runtime** into the shell through Module Federation.
- There are also **Angular libraries** (`projects/shared-lib`, `projects/auth-lib`) intended to be consumed by one or more apps (shell/mfe1), representing shared UI/services/auth concerns.

So the “system” is primarily a **front-end runtime composition architecture** (no backend in this repo), where the shell dynamically loads code from a separately deployed microfrontend.

##### Top-level workspace
- `angular.json`, `tsconfig.json`, `package.json`: Angular workspace configuration and dependency graph.

##### Applications (deployable units)
- `projects/shell/`
Host application, includes:
- `src/app/app.routes.ts`: key for **lazy route to remote**
- `src/assets/mf.manifest.json`: indicates **manifest-based remote URL mapping** (important runtime discovery)
- `webpack.config.js` / `webpack.prod.config.js`: **Module Federation host configuration**
- `src/decl.d.ts`: typing for mapped remote modules

- `projects/mfe1/`
Remote application, includes:
- `src/bootstrap.ts`: typical MF setup where bootstrap is separated for federation
- `src/app/.../flights/*`: a feature domain exposed/used by shell (the README mentions “flights” link)
- `webpack.config.js` / `webpack.prod.config.js`: **Module Federation remote configuration**

##### Libraries (build artifacts; not deployed standalone)
- `projects/shared-lib/`: shared components/services module
- `projects/auth-lib/`: authentication-related module/service/component
These are likely **statically bundled dependencies** of shell/mfe1 at build time (unless configured to be shared as federated singletons; that detail lives in webpack configs).

##### Runtime / Container view (most important here)
What runs in the browser and what it fetches over the network at runtime.

**Nodes to include:**
- End User Browser
- Shell (Host) Angular SPA (served from its own origin)
- MFE1 (Remote) Angular build artifacts (served from its own origin)
- `mf.manifest.json` (as runtime config lookup, typically fetched by shell)

##### Remote code executes inside shell page (in-browser integration)

This view answers: “How does the shell load and render the microfrontend?”

##### Build-time / Dependency view (module federation + libs)
How code is produced and what depends on what during build.

**Nodes to include:**
- Angular CLI build (workspace)
- Webpack 5 Module Federation configuration:
- `projects/shell/webpack*.config.js` (host)
- `projects/mfe1/webpack*.config.js` (remote)
- `shared-lib` and `auth-lib` (as workspace libraries)

**Key relationships:**
- Shell build depends on: shell source + libs + MF host config
- MFE1 build depends on: mfe1 source + libs + MF remote config
- Both produce separate deployable artifacts
- Federation contract: shell expects remote exposes (e.g., a module/route) and remote provides them

This view answers: “What are the deployables and how are they wired?”

##### Deployment / Environment view (CI/CD + hosting)

**Nodes to include:**
- GitHub repo → GitHub Actions workflow
- Azure Static Web Apps (likely 2 apps or 2 deployments/paths):
- Shell static site (host)
- MFE1 static site (remote)
- Optional: CDN/front door (if applicable; can be shown as “Static hosting/CDN”)

**Key relationships:**
- CI builds shell and mfe1 separately
- Publishes artifacts to their hosting endpoints
- Shell runtime points to remote endpoint (direct URL or via manifest)

This view answers: “Where do these artifacts live and how are they updated?”

##### Browser Runtime Lane
- Browser
- Shell SPA (router + MF loader)
- Remote MFE1 module executing in shell DOM

##### Static Hosting Lane
- Shell hosting endpoint (serves shell bundles)
- MFE1 hosting endpoint (serves remoteEntry + chunks)
- Manifest location (often on shell host)

##### Build/CI Lane
- GitHub Actions
- `ng build shell` + `ng build mfe1`
- Outputs published to hosting

This captures the essential architecture without overthinking, while still separating the system into many components (host, remote, manifest, router, federation runtime, shared libs, CI/CD, hosting).

##### Checklist to ensure you didn’t miss anything important

- [ ] Shell and MFE1 shown as **independently deployed** apps
- [ ] `remoteEntry.js` shown explicitly as the remote “entry point”
- [ ] `mf.manifest.json` shown if used for remote URL mapping
- [ ] Lazy route (`/flights`) shown as the trigger
- [ ] Shared libs (`shared-lib`, `auth-lib`) shown as build-time dependencies
- [ ] Shared Angular dependencies shown (conceptually) as “shared singletons”
- [ ] CI/CD pipeline + hosting endpoints included (Azure Static Web Apps workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =========================
  %% Runtime / Container View
  %% =========================
  subgraph "Browser Runtime (in-page composition)"
    U["EndUserBrowser"]:::external

    subgraph "ShellHostSPA (Angular)"
      SH["ShellApp (Host)"]:::host
      SHR["AngularRouter"]:::runtime
      SHMF["ModuleFederationRuntimeLoader"]:::runtime
      SHT["RemoteModuleTyping (decl.d.ts)"]:::code
      SHB["ShellBootstrap (bootstrap.ts)"]:::code
    end

    subgraph "RemoteMFE1 (executed inside Shell page)"
      MFE["MFE1RemoteApp"]:::remote
      MFEB["MFE1Bootstrap (bootstrap.ts)"]:::code
      MFEF["FlightsFeatureDomain"]:::remote
      MFEM["FlightsModule"]:::code
      MFER["FlightsRoutes"]:::code
    end
  end

  %% =========================
  %% Static Hosting / Artifacts
  %% =========================
  subgraph "Static Hosting (separate origins)"
    subgraph "ShellOrigin (Host endpoint)"
      SHH["ShellStaticSite (index.html + bundles)"]:::host
      MAN["mf.manifest.json"]:::artifact
    end

    subgraph "MFE1Origin (Remote endpoint)"
      MFEH["MFE1StaticSite (remoteEntry.js + chunks)"]:::remote
      RE["remoteEntry.js"]:::artifact
      CH["RemoteChunks (lazy loaded JS)"]:::artifact
    end
  end

  %% =========================
  %% Build-time / Dependency View
  %% =========================
  subgraph "Build Time (Angular CLI + Webpack 5 Module Federation)"
    WS["AngularWorkspace (angular.json + tsconfig.json + package.json)"]:::workspace

    subgraph "ShellBuild"
      SHSRC["ShellSource (projects/shell)"]:::host
      SHWPD["HostMFConfig (webpack.config.js)"]:::code
      SHWPP["HostMFConfig (webpack.prod.config.js)"]:::code
      SHOUT["ShellBuildArtifacts"]:::artifact
    end

    subgraph "MFE1Build"
      MFESRC["MFE1Source (projects/mfe1)"]:::remote
      MFEWPD["RemoteMFConfig (webpack.config.js)"]:::code
      MFEWPP["RemoteMFConfig (webpack.prod.config.js)"]:::code
      MFEOUT["MFE1BuildArtifacts (remoteEntry + chunks)"]:::artifact
    end

    subgraph "WorkspaceLibraries (shared code)"
      SL["shared-lib"]:::lib
      SLAPI["shared-lib public-api.ts"]:::code
      AL["auth-lib"]:::lib
      ALAPI["auth-lib public-api.ts"]:::code
    end

    SD["SharedSingletonDeps (@angular/*,rxjs,etc.)"]:::shared
  end

  %% =========================
  %% CI/CD / Deployment View
  %% =========================
  subgraph "CI/CD + Deployment (Azure Static Web Apps)"
    GH["GitHubRepo"]:::cicd
    GHA["GitHubActions Workflow"]:::cicd
    AZ1["AzureStaticWebApps (Shell)"]:::cicd
    AZ2["AzureStaticWebApps (MFE1)"]:::cicd
  end

  %% =========================
  %% Runtime flows (solid)
  %% =========================
  U -->|"GET index.html+bundles"| SHH
  SHH -->|"loads into"| SH

  SH -->|"GET mf.manifest.json"| MAN
  SHMF -->|"resolveRemoteURL"| MAN

  SHR -->|"lazyRoute:/flights"| SHMF
  SHMF -->|"GET /remoteEntry.js"| RE
  SHMF -->|"GET remoteChunks"| CH
  RE -->|"registerRemoteModules"| MFE
  CH -->|"executeInShellDOM"| MFEF
  MFEF -->|"provides"| MFEM
  MFEM -->|"configures"| MFER

  %% =========================
  %% Build-time dependencies (dashed)
  %% =========================
  WS -.->|"workspaceConfig"| SHSRC
  WS -.->|"workspaceConfig"| MFESRC
  WS -.->|"builds"| SL
  WS -.->|"builds"| AL

  SHSRC -.->|"uses"| SL
  SHSRC -.->|"uses"| AL
  MFESRC -.->|"uses"| SL
  MFESRC -.->|"uses"| AL

  SHSRC -.->|"mfHostConfig"| SHWPD
  SHSRC -.->|"mfHostConfigProd"| SHWPP
  MFESRC -.->|"mfRemoteConfig"| MFEWPD
  MFESRC -.->|"mfRemoteConfigProd"| MFEWPP

  SHWPD -.->|"shareSingletons"| SD
  SHWPP -.->|"shareSingletons"| SD
  MFEWPD -.->|"shareSingletons"| SD
  MFEWPP -.->|"shareSingletons"| SD

  SHSRC -.->|"outputs"| SHOUT
  MFESRC -.->|"outputs"| MFEOUT

  %% Federation contract (conceptual)
  SHMF -.->|"consumesExposes"| MFE
  MFE -.->|"exposesFlights"| MFEF

  %% =========================
  %% Deployment flows
  %% =========================
  GH -->|"triggers"| GHA
  GHA -->|"build+deployShell"| AZ1
  GHA -->|"build+deployMFE1"| AZ2

  AZ1 -->|"serves"| SHH
  AZ1 -->|"hosts"| MAN
  AZ2 -->|"serves"| MFEH
  MFEH -->|"contains"| RE
  MFEH -->|"contains"| CH

  %% =========================
  %% Click Events (from mapping)
  %% =========================
  click WS "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/angular.json"
  click WS "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/tsconfig.json"
  click WS "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/package.json"
  click GHA "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/.github/workflows/azure-static-web-apps-brave-mud-09b32e310.yml"

  click SHSRC "https://github.com/gmurtaza786/module-federation-plugin-example/tree/main/projects/shell/"
  click SHR "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/shell/src/app/app.routes.ts"
  click SHWPD "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/shell/webpack.config.js"
  click SHWPP "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/shell/webpack.prod.config.js"
  click MAN "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/shell/src/assets/mf.manifest.json"
  click SHT "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/shell/src/decl.d.ts"
  click SHB "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/shell/src/bootstrap.ts"

  click MFESRC "https://github.com/gmurtaza786/module-federation-plugin-example/tree/main/projects/mfe1/"
  click MFEWPD "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/mfe1/webpack.config.js"
  click MFEWPP "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/mfe1/webpack.prod.config.js"
  click MFEB "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/mfe1/src/bootstrap.ts"
  click MFEF "https://github.com/gmurtaza786/module-federation-plugin-example/tree/main/projects/mfe1/src/app/flights/"
  click MFEM "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/mfe1/src/app/flights/flights.module.ts"
  click MFER "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/mfe1/src/app/flights/flights.routes.ts"

  click SL "https://github.com/gmurtaza786/module-federation-plugin-example/tree/main/projects/shared-lib/"
  click SLAPI "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/shared-lib/src/public-api.ts"
  click AL "https://github.com/gmurtaza786/module-federation-plugin-example/tree/main/projects/auth-lib/"
  click ALAPI "https://github.com/gmurtaza786/module-federation-plugin-example/blob/main/projects/auth-lib/src/public-api.ts"

  %% =========================
  %% Styles
  %% =========================
  classDef external fill:#ffffff,stroke:#1f2937,stroke-width:1px,color:#111827
  classDef host fill:#dbeafe,stroke:#1d4ed8,stroke-width:1.5px,color:#0f172a
  classDef remote fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#052e16
  classDef lib fill:#e5e7eb,stroke:#6b7280,stroke-width:1.25px,color:#111827
  classDef shared fill:#f3f4f6,stroke:#4b5563,stroke-width:1.25px,color:#111827
  classDef cicd fill:#ffedd5,stroke:#ea580c,stroke-width:1.5px,color:#7c2d12
  classDef artifact fill:#fef3c7,stroke:#d97706,stroke-width:1.25px,color:#78350f
  classDef runtime fill:#e0f2fe,stroke:#0284c7,stroke-dasharray:5 3,stroke-width:1.25px,color:#0c4a6e
  classDef code fill:#ede9fe,stroke:#6d28d9,stroke-width:1.25px,color:#2e1065
  classDef workspace fill:#f1f5f9,stroke:#334155,stroke-width:1.5px,color:#0f172a
```
