# elifnurkarakoc/nextjs-module-federation-playground architecture

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

- Interactive diagram: https://gitdiagram.com/elifnurkarakoc/nextjs-module-federation-playground
- Repository: https://github.com/elifnurkarakoc/nextjs-module-federation-playground

## Overview

##### Project type and purpose
- This is a Next.js “Module Federation” playground consisting of two standalone Next.js applications (app1 and app2) configured to explore Webpack’s Module Federation for micro-frontends. Both apps live at the root level and follow identical folder structures with React/TypeScript, TailwindCSS, and Next.js.

##### File structure
- Top-level:
- .gitignore, README.md
- app1/… (Next.js project)
- app2/… (Next.js project)
- Each app contains:
- Configuration files (.eslintrc.json, next.config.js, tailwind.config.js, tsconfig.json)
- package.json + package-lock.json
- public/ for static assets
- src/components for UI widgets
- src/pages for Next.js routing (including pages/api for serverless endpoints)
- src/styles for global CSS
- No additional “shared” or “common” directory is present—sharing is achieved at runtime via Module Federation.

##### README for additional insights
- Confirms: “NEXTJS MODULE FEDERATION PLAYGROUND.”

a. Main components
- App1 – Next.js server (Node.js SSR), React app, exposed remote modules
- App2 – Next.js server (Node.js SSR), React app, consumes remote modules (and/or vice versa)
- Shared libraries – React, ReactDOM, Next.js runtime, TailwindCSS utilities
- Browser/Client – initiates requests to each app and dynamically loads federated modules
b. Relationships & interactions
- Client → App1 Node server: initial page request, SSR rendered HTML + federated module manifest
- Client → App2 Node server: same flow, but App2’s pages import components exposed by App1 at runtime (or vice versa)
- Webpack ModuleFederation runtime in the browser resolves and fetches remoteEntry.js files from the other app’s public URL
- Shared chunk negotiation: React and other common libs are deduped/shared between apps
c. Architectural patterns/design principles
- Micro-frontends via Webpack Module Federation
- Next.js SSR + client-side hydration
- Shared dependency deduplication
- Clean separation: each app is independently deployable
d. Key technologies/frameworks
- Next.js with custom next.config.js enabling ModuleFederationPlugin
- React + ReactDOM
- TypeScript
- TailwindCSS (via postcss.config.js)
- ESLint for code quality

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Browser/Client"]:::client

    %% Shared Libraries
    SharedLibs["Shared Libraries\nReact, ReactDOM,\nNext.js Runtime,\nTailwindCSS"]:::shared

    %% App1 Subgraph
    subgraph "App1"
        Next1["Next.js Server\n(Node.js SSR)"]:::server
        Runtime1["Module Federation Runtime"]:::runtime
        Pages1["React Pages\n(_app.tsx, _document.tsx,\nindex.tsx, about.tsx)"]:::pages
        API1["API Routes\n(hello.ts)"]:::api
        Components1["UI Components\n(Nav.tsx, Footer.tsx)"]:::component
        Styles1["Global Styles & Tailwind\n(globals.css, postcss.config.js,\ntailwind.config.js)"]:::styles
        TS1["TypeScript Config\n(tsconfig.json)"]:::ts
    end

    %% App2 Subgraph
    subgraph "App2"
        Next2["Next.js Server\n(Node.js SSR)"]:::server
        Runtime2["Module Federation Runtime"]:::runtime
        Pages2["React Pages\n(_app.tsx, _document.tsx,\nindex.tsx, about.tsx)"]:::pages
        API2["API Routes\n(hello.ts)"]:::api
        Components2["UI Components\n(Content.tsx)"]:::component
        Styles2["Global Styles & Tailwind\n(globals.css, postcss.config.js,\ntailwind.config.js)"]:::styles
        TS2["TypeScript Config\n(tsconfig.json)"]:::ts
    end

    %% Connections
    Client -->|Initial HTTP Request| Next1
    Client -->|Initial HTTP Request| Next2
    Next1 -->|SSR Response + remoteEntry.js| Client
    Next2 -->|SSR Response + remoteEntry.js| Client
    Client -->|Loads federated modules| Runtime1
    Client -->|Loads federated modules| Runtime2
    Runtime1 -.->|Fetch remoteEntry.js| Runtime2
    Runtime2 -.->|Fetch remoteEntry.js| Runtime1
    SharedLibs -->|Shared at runtime| Runtime1
    SharedLibs -->|Shared at runtime| Runtime2

    %% Click Events App1
    click Next1 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app1/next.config.js"
    click Pages1 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app1/src/pages/_app.tsx"
    click Pages1 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app1/src/pages/_document.tsx"
    click Pages1 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app1/src/pages/index.tsx"
    click Pages1 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app1/src/pages/about.tsx"
    click API1 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app1/src/pages/api/hello.ts"
    click Components1 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app1/src/components/Nav.tsx"
    click Components1 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app1/src/components/Footer.tsx"
    click Styles1 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app1/src/styles/globals.css"
    click Styles1 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app1/postcss.config.js"
    click Styles1 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app1/tailwind.config.js"
    click TS1 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app1/tsconfig.json"

    %% Click Events App2
    click Next2 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app2/next.config.js"
    click Pages2 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app2/src/pages/_app.tsx"
    click Pages2 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app2/src/pages/_document.tsx"
    click Pages2 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app2/src/pages/index.tsx"
    click Pages2 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app2/src/pages/about.tsx"
    click API2 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app2/src/pages/api/hello.ts"
    click Components2 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app2/src/components/Content.tsx"
    click Styles2 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app2/src/styles/globals.css"
    click Styles2 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app2/postcss.config.js"
    click Styles2 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app2/tailwind.config.js"
    click TS2 "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/app2/tsconfig.json"

    %% Click Event Shared
    click SharedLibs "https://github.com/elifnurkarakoc/nextjs-module-federation-playground/blob/main/README.md"

    %% Styles
    classDef client fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef server fill:#E3F2FD,stroke:#2196F3,stroke-dasharray:5 5;
    classDef runtime fill:#FFF3E0,stroke:#FB8C00;
    classDef component fill:#E8F5E9,stroke:#4CAF50;
    classDef shared fill:#F3E5F5,stroke:#9C27B0,stroke-width:2px;
    classDef pages fill:#F0F4C3,stroke:#CDDC39;
    classDef api fill:#FFEBEE,stroke:#F44336;
    classDef styles fill:#E1F5FE,stroke:#03A9F4;
    classDef ts fill:#ECEFF1,stroke:#607D8B;
```
