# contentstack/micro-frontend-example architecture

> Architecture diagram of the GitHub repository contentstack/micro-frontend-example, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/contentstack/micro-frontend-example
- Repository: https://github.com/contentstack/micro-frontend-example

## Overview

##### Project type and purpose
- This is a micro-frontend example showcasing a container (“restaurant”) app that dynamically loads a “pizza-app” micro-frontend.
- The container hosts two menu sections (“sandwich” directly and “pizza” via micro-frontend).
- Uses React, webpack, Docker+Nginx, and Docker Compose to orchestrate both apps side by side.

##### File structure
- Top-level:
· .github/workflows files for CI (CodeQL, policy, SCA, secrets)
· docker-compose.yaml to spin up both services
- “restaurant” directory (container app)
· Dockerfile + nginx.conf to serve built assets
· src/app: container’s React entry, micro-frontend loader, portal target for breadcrumbs
· microfrontends.ts: maps micro-frontend names to remote URLs
- “pizza-app” directory (micro-frontend)
· Dockerfile + nginx.conf, bundle served on port 8081
· src/app: React components for pizza menu, uses React Portal to render breadcrumbs in container
· src/lib: Redux store configuration, micro-frontend metadata context
- Common patterns
· Both use webpack.config.js to produce vendor.js and app bundles
· SCSS for styling, index.html templates

##### README for additional insights
- Confirms container runs on localhost:8080, micro-frontend on localhost:8081
- Explains React Portal usage for rendering breadcrumbs outside the micro-frontend frame
- Suggests using docker-compose up for quick startup

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Infrastructure Layer
    subgraph "Docker Compose Orchestrator" 
        direction TB
        DockerCompose["docker-compose.yaml"]:::infra
    end

    subgraph "Restaurant Container" 
        direction TB
        RC_Dockerfile["Dockerfile"]:::infra
        RC_Nginx["nginx.conf"]:::infra
        subgraph "Restaurant App Code"
            direction TB
            RC_Index["index.tsx"]:::frontend
            RC_HTML["index.html"]:::frontend
            RC_App["app.tsx"]:::frontend
            RC_MicroContainer["micro-frontend-container.tsx"]:::frontend
            RC_Mapping["microfrontends.ts"]:::frontend
            RC_Styles["main.scss"]:::frontend
            RC_Vendor["vendor.js"]:::frontend
            RC_Webpack["webpack.config.js"]:::infra
        end
    end

    subgraph "Pizza Micro-frontend" 
        direction TB
        PA_Dockerfile["Dockerfile"]:::infra
        PA_Nginx["nginx.conf"]:::infra
        subgraph "Pizza App Code"
            direction TB
            PA_Index["index.tsx"]:::frontend
            PA_HTML["index.html"]:::frontend
            PA_App["app.tsx"]:::frontend
            PA_AllPizzas["all-pizzas.tsx"]:::frontend
            PA_Vegan["vegan-pizza.tsx"]:::frontend
            PA_Menu["pizza-menu.tsx"]:::frontend
            PA_Nav["nav-layout.tsx"]:::frontend
            PA_Store["configureStore.ts"]:::frontend
            PA_Meta["microfrontend-meta-context.ts"]:::frontend
            PA_Reducer["rootReducer.ts"]:::frontend
            PA_Styles["main.scss"]:::frontend
            PA_Vendor["vendor.js"]:::frontend
            PA_Webpack["webpack.config.js"]:::infra
        end
    end

    subgraph "User Browser"
        Browser["Browser"]:::external
    end

    subgraph "CI/CD Pipelines"
        direction TB
        CodeQL["codeql-analysis.yml"]:::cicd
        IssuesJira["issues-jira.yml"]:::cicd
        Policy["policy-scan.yml"]:::cicd
        SCA["sca-scan.yml"]:::cicd
        Secrets["secrets-scan.yml"]:::cicd
    end

    %% Connections
    Browser -->|"HTTP GET / (port 8080)"| RC_Nginx
    RC_Nginx -->|"serves index.html, app & vendor"| Browser
    RC_App -->|"reads mapping"| RC_Mapping
    RC_App -->|"injects <script src>"| PA_Nginx
    Browser -->|"HTTP GET remote bundle"| PA_Nginx
    PA_Nginx -->|"serves pizza-app bundle"| Browser
    PA_App -->|"React Portal render"| RC_MicroContainer
    DockerCompose --> RC_Dockerfile
    DockerCompose --> PA_Dockerfile
    CodeQL --> DockerCompose
    IssuesJira --> DockerCompose
    Policy --> DockerCompose
    SCA --> DockerCompose
    Secrets --> DockerCompose

    %% Click Events
    click RC_Dockerfile "https://github.com/contentstack/micro-frontend-example/tree/main/restaurant/Dockerfile"
    click RC_Nginx "https://github.com/contentstack/micro-frontend-example/blob/main/restaurant/nginx.conf"
    click RC_Index "https://github.com/contentstack/micro-frontend-example/blob/main/restaurant/src/index.tsx"
    click RC_HTML "https://github.com/contentstack/micro-frontend-example/blob/main/restaurant/src/index.html"
    click RC_App "https://github.com/contentstack/micro-frontend-example/blob/main/restaurant/src/app/app.tsx"
    click RC_MicroContainer "https://github.com/contentstack/micro-frontend-example/blob/main/restaurant/src/app/components/micro-frontend-container.tsx"
    click RC_Mapping "https://github.com/contentstack/micro-frontend-example/blob/main/restaurant/src/app/microfrontends.ts"
    click RC_Styles "https://github.com/contentstack/micro-frontend-example/blob/main/restaurant/src/styles/main.scss"
    click RC_Vendor "https://github.com/contentstack/micro-frontend-example/blob/main/restaurant/vendor.js"
    click RC_Webpack "https://github.com/contentstack/micro-frontend-example/blob/main/restaurant/webpack.config.js"
    click PA_Dockerfile "https://github.com/contentstack/micro-frontend-example/tree/main/pizza-app/Dockerfile"
    click PA_Nginx "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/nginx.conf"
    click PA_Index "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/src/index.tsx"
    click PA_HTML "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/src/index.html"
    click PA_App "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/src/app/app.tsx"
    click PA_AllPizzas "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/src/app/all-pizzas.tsx"
    click PA_Vegan "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/src/app/vegan-pizza.tsx"
    click PA_Menu "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/src/app/pizza-menu.tsx"
    click PA_Nav "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/src/app/nav-layout.tsx"
    click PA_Store "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/src/lib/configureStore.ts"
    click PA_Meta "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/src/lib/microfrontend-meta-context.ts"
    click PA_Reducer "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/src/lib/rootReducer.ts"
    click PA_Styles "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/src/styles/main.scss"
    click PA_Vendor "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/vendor.js"
    click PA_Webpack "https://github.com/contentstack/micro-frontend-example/blob/main/pizza-app/webpack.config.js"
    click DockerCompose "https://github.com/contentstack/micro-frontend-example/blob/main/docker-compose.yaml"
    click CodeQL "https://github.com/contentstack/micro-frontend-example/blob/main/.github/workflows/codeql-analysis.yml"
    click IssuesJira "https://github.com/contentstack/micro-frontend-example/blob/main/.github/workflows/issues-jira.yml"
    click Policy "https://github.com/contentstack/micro-frontend-example/blob/main/.github/workflows/policy-scan.yml"
    click SCA "https://github.com/contentstack/micro-frontend-example/blob/main/.github/workflows/sca-scan.yml"
    click Secrets "https://github.com/contentstack/micro-frontend-example/blob/main/.github/workflows/secrets-scan.yml"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0254A5
    classDef infra fill:#DFF7D8,stroke:#2F6627
    classDef cicd fill:#FFF5C2,stroke:#A67C00
    classDef external fill:#F0F0F0,stroke:#333
```
