# diego-rm-dev/vite-plugin-federation architecture

> Architecture diagram of the GitHub repository diego-rm-dev/vite-plugin-federation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/diego-rm-dev/vite-plugin-federation
- Repository: https://github.com/diego-rm-dev/vite-plugin-federation

## Overview

##### Project Type and Purpose
- The project is a front-end micro-frontend architecture built with React and Vite.
- It uses Module Federation to dynamically load remote components into a host application.
- The host consumes remote modules from two separate microservices (acting as remotes), each configured to expose specific components (in this case, the "App" components).

##### Identifying Main Components
- Host Application:
- Resides in the "host" directory.
- Configured on port 3000.
- Uses the federation plugin to declare remotes ("remote1" and "remote2") with their respective endpoints.
- Microservice-1:
- Found in the "microservice-1" directory.
- Configured on port 3001.
- Exposes its App component via Module Federation.
- Microservice-2:
- Found in the "microservice-2" directory.
- Configured on port 3002.
- Similarly exposes its App component.

##### Highlighting Architectural Patterns and Technologies
- That the architecture follows a micro-frontend approach enabled by Module Federation.
- That the Vite build system is used for configuration and bundling in all modules.
- Mention that the use of React (with dynamic imports using lazy and Suspense) is a critical part of rendering remote components.
- That each application has its own Vite configuration file that sets up the Module Federation (noting the usage of the @module-federation/vite plugin).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Shared Dependencies
    SD["Shared: React & React-DOM"]:::shared

    %% Host Application Subgraph
    subgraph "Host Application (Port 3000)"
        HMain["Host Application"]:::host
        HFile1["index.html"]:::file
        HFile2["src/App.tsx"]:::file
        HFile3["vite.config.mts"]:::file
        HNote["Uses Module Federation, Vite, React lazy/Suspense"]:::note
        HMain --> HFile1
        HMain --> HFile2
        HMain --> HFile3
        HMain --> HNote
    end

    %% Microservice-1 Subgraph
    subgraph "Microservice-1 (Remote 1, Port 3001)"
        R1Main["Microservice-1"]:::remote
        R1File1["src/App.tsx"]:::file
        R1File2["vite.config.ts"]:::file
        R1Note["Exposes App component via Module Federation"]:::note
        R1Main --> R1File1
        R1Main --> R1File2
        R1Main --> R1Note
    end

    %% Microservice-2 Subgraph
    subgraph "Microservice-2 (Remote 2, Port 3002)"
        R2Main["Microservice-2"]:::remote
        R2File1["src/App.tsx"]:::file
        R2File2["vite.config.ts"]:::file
        R2Note["Exposes App component via Module Federation"]:::note
        R2Main --> R2File1
        R2Main --> R2File2
        R2Main --> R2Note
    end

    %% Connections between components
    HMain -->|"DynamicImport:remote1/App"| R1Main
    HMain -->|"DynamicImport:remote2/App"| R2Main

    %% Shared dependencies connections
    SD --- HMain
    SD --- R1Main
    SD --- R2Main

    %% Click Events for Host Application
    click HMain "https://github.com/diego-rm-dev/vite-plugin-federation/tree/main/host/"
    click HFile1 "https://github.com/diego-rm-dev/vite-plugin-federation/blob/main/host/index.html"
    click HFile2 "https://github.com/diego-rm-dev/vite-plugin-federation/blob/main/host/src/App.tsx"
    click HFile3 "https://github.com/diego-rm-dev/vite-plugin-federation/blob/main/host/vite.config.mts"

    %% Click Events for Microservice-1
    click R1Main "https://github.com/diego-rm-dev/vite-plugin-federation/tree/main/microservice-1/"
    click R1File1 "https://github.com/diego-rm-dev/vite-plugin-federation/blob/main/microservice-1/src/App.tsx"
    click R1File2 "https://github.com/diego-rm-dev/vite-plugin-federation/blob/main/microservice-1/vite.config.ts"

    %% Click Events for Microservice-2
    click R2Main "https://github.com/diego-rm-dev/vite-plugin-federation/tree/main/microservice-2/"
    click R2File1 "https://github.com/diego-rm-dev/vite-plugin-federation/blob/main/microservice-2/src/App.tsx"
    click R2File2 "https://github.com/diego-rm-dev/vite-plugin-federation/blob/main/microservice-2/vite.config.ts"

    %% Styles
    classDef host fill:#ffebcc,stroke:#333,stroke-width:2px;
    classDef remote fill:#cceeff,stroke:#333,stroke-width:2px;
    classDef shared fill:#e0e0e0,stroke:#333,stroke-dasharray: 5,5;
    classDef file fill:#d4edda,stroke:#155724,stroke-width:1px;
    classDef note fill:#fff3cd,stroke:#856404,stroke-width:1px,stroke-dasharray: 2 2;
```
