# andrecrjr/module-federation-explorer architecture

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

- Interactive diagram: https://gitdiagram.com/andrecrjr/module-federation-explorer
- Repository: https://github.com/andrecrjr/module-federation-explorer

## Overview

##### Main Components Identification
- VS Code Extension Host & Activation: At the heart of the extension is the activation process (see src/index.ts). This module bootstraps the extension once a workspace with the appropriate Module Federation configuration is opened.
- Configuration Detection & Extraction: The extension auto-detects configuration files using components such as src/configExtractors.ts. This is where it scans for files like webpack.config.js, vite.config.js, or module-federation.config.js and extracts settings.
- Output & Communication: With src/outputChannel.ts, the project establishes communication with the VS Code UI (for output logging and status indicators).
- Unified Tree Provider & UI Integration: The src/unifiedTreeProvider.ts, along with the media/styles.css, supports the construction of the visual tree view in the VS Code explorer sidebar, ensuring that module remotes and hosts are dynamically rendered.
- Root Configuration Management: Managed via src/rootConfigManager.ts, this component is responsible for persisting configuration data (e.g., in the .vscode/mf-explorer.roots.json file).

##### Architectural Relationships and Interactions
- The VS Code runtime environment triggers the activation (index.ts), which then initializes and coordinates the other components.
- The configuration extractor reads and interprets the workspace’s module federation configuration files and passes that data to both the unified tree provider and dependency graph modules.
- The unified tree provider updates the VS Code explorer view, allowing users to interact with hosts and remotes. In turn, UI actions (via context menus and commands) trigger operations in the configuration manager or output channel.
- The output channel module is used to relay status updates back to the user, ensuring feedback for operations like starting/stopping remotes or hosts.
- The dependencyGraph module interacts with the configuration extractor’s data to build a visual representation of dependencies via a directed graph.

##### Architectural Patterns and Design Principles
- Component Separation: The system is neatly divided into functional areas (configuration extraction, UI update, state management, and dependency visualization).
- Event-Driven / Command Pattern: The extension uses commands (as detailed in the README) to drive user interactions.
- Modularity: Each file in the /src folder represents a distinct functionality, making it easier to maintain or extend parts of the project independently.
- Integration with External VS Code APIs: The extension leverages VS Code’s APIs to embed its functionality (e.g., tree view and command contributions) fully within the editor.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Action
    UA("VS Code User Action"):::user

    %% Core activation
    ACT("VS Code Extension Activation"):::activation

    %% Business Logic Components
    CE("Configuration Detection & Extraction"):::config
    OC("Output & Communication"):::config
    UT("Unified Tree Provider"):::ui
    DG("Dependency Graph Visualization"):::config
    RC("Root Configuration Manager"):::config

    %% UI Styling
    US("UI Styling for Tree View"):::ui

    %% External Files
    EC("Workspace Config Files (Webpack/Vite/ModernJS & .vscode/mf-explorer.roots.json)"):::external

    %% Build/Packaging Files subgraph
    subgraph "Build/Packaging Configuration" 
        PKG("package.json"):::build
        RSP("rspack.config.js"):::build
        TSC("tsconfig.json"):::build
    end

    %% Flow Connections
    UA -->|"triggers"| ACT

    ACT -->|"initializes"| CE
    ACT -->|"logs status"| OC

    %% External inputs to configuration extraction
    EC -->|"provides config data"| CE
    PKG --- RSP
    RSP --- TSC
    %% Merge build config as source for detection
    PKG & RSP & TSC --- CE

    %% Configuration Extraction feeds UI and Graph
    CE -->|"updates"| UT
    CE -->|"populates"| DG

    %% UI interactions flow
    UT -->|"user commands"| RC
    RC -->|"status updates"| OC
    UT -->|"styled by"| US

    %% Click Events
    click ACT "https://github.com/andrecrjr/module-federation-explorer/blob/master/src/index.ts"
    click CE "https://github.com/andrecrjr/module-federation-explorer/blob/master/src/configExtractors.ts"
    click DG "https://github.com/andrecrjr/module-federation-explorer/blob/master/src/dependencyGraph.ts"
    click UT "https://github.com/andrecrjr/module-federation-explorer/blob/master/src/unifiedTreeProvider.ts"
    click RC "https://github.com/andrecrjr/module-federation-explorer/blob/master/src/rootConfigManager.ts"
    click OC "https://github.com/andrecrjr/module-federation-explorer/blob/master/src/outputChannel.ts"
    click US "https://github.com/andrecrjr/module-federation-explorer/blob/master/media/styles.css"
    click PKG "https://github.com/andrecrjr/module-federation-explorer/blob/master/package.json"
    click RSP "https://github.com/andrecrjr/module-federation-explorer/blob/master/rspack.config.js"
    click TSC "https://github.com/andrecrjr/module-federation-explorer/blob/master/tsconfig.json"

    %% Styles
    classDef activation fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef config fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef ui fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef build fill:#d1c4e9,stroke:#6a1b9a,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef user fill:#e2e3e5,stroke:#383d41,stroke-width:2px;
```
