# antfu/node-modules-inspector architecture

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

- Interactive diagram: https://gitdiagram.com/antfu/node-modules-inspector
- Repository: https://github.com/antfu/node-modules-inspector

## Overview

Based on an analysis of the file tree and the README content, this project is a tool for visualizing and inspecting the node_modules directory of a JavaScript/Node.js project. In essence, it functions both as a CLI utility and as a static or dynamic Single Page Application (SPA) that displays dependency information in various graphical formats (charts, trees, reports, etc.). It is designed for users running npm or pnpm projects, and it even leverages WebContainer for an online version.

##### Main Components
- CLI/Entry Point: Represent the command-line interface (triggered via “pnpx node-modules-inspector” or “npx node-modules-inspector”). This is the starting point, and it handles different invocations (either running in interactive mode or producing a static build).
- Configuration Manager: Show the configuration module (the user-defined “node‑modules‑inspector.config.ts”) that feeds default filters, settings, and experimental integrations (like publint).
- Analysis Engine (node‑modules‑tools): This set of modules – found under packages/node‑modules‑tools – contains the logic to analyze dependency trees, compute sizes, resolve package types (commonjs/esm), and prepare the dependency metadata for visualization.
- Frontend SPA/UI Layer (node‑modules‑inspector package): The visualizer built with Vue, which is composed of multiple sub-components:
– App Shell (app.vue) that hosts layouts and page routing.
– Components grouping for charts (Framegraph, Sunburst, Treemap, etc.), reports, panels, tree views, UI badges, and other display elements.
– State management and API endpoints that feed data from the analysis engine into the UI.
- Backend Integration/API: Although this is a frontend-heavy project, there is also a backend/server folder that handles API routes, WebSocket connections (as seen in the src/app/backends folder), and integration with the CLI’s runtime (for example, serving the SPA or updating data in real time).
- External Services/Integrations: Include modules for integration with WebContainer (to power the online version) and the optional publint integration. These can be depicted as external services or cloud components that interact with the core system.

##### Relationships and Data Flows
- The CLI/Entry Point invokes the Analysis Engine and passes parsed configuration settings.
- The Analysis Engine processes the node_modules structure and generates parsed metadata that is then transmitted to the SPA.
- Optionally, for the static build process, show that a “build” command collects analysis data and then outputs a deployable SPA (hosted on any static file server).

##### Architectural Patterns and Technologies
- Modular Architecture: The project is split across packages (node‑modules‑inspector and node‑modules‑tools), separating the UI from the analytical logic.
- Component-Based UI: The use of Vue Single File Components (SFCs) to build a responsive and modular UI.
- Separation of Concerns: The analysis engine is isolated from the display layer, and configurations are handled separately.
- API/Backend Interaction: The use of server-side code (including API endpoints and WebSocket support) to mediate communication between commands and UI.
- Integrations with package managers (npm, pnpm) and third-party services (WebContainer and publint).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI & Configuration Layer
    subgraph "CLI & Configuration Layer"
        CLI_Entry["CLI/Entry Point"]:::cli
        Configuration_Manager["Configuration Manager"]:::config
    end

    %% Analysis Engine Layer
    subgraph "Analysis Engine Layer"
        Analysis["Analysis Engine"]:::analysis
    end

    %% Backend Integration/API
    subgraph "Backend Integration/API"
        Backend["Backend Integration/API"]:::backend
    end

    %% Frontend SPA/UI Layer
    subgraph "Frontend SPA/UI"
        AppShell["App Shell (Vue)"]:::frontend
        Components["Components & State Management"]:::frontend
    end

    %% External Services
    External["External Services (WebContainer)"]:::external

    %% Relationships and Data Flows
    CLI_Entry -->|"triggers"| Analysis
    Configuration_Manager -->|"configures"| Analysis
    Configuration_Manager -->|"configures"| AppShell
    Analysis -->|"feedsData"| AppShell
    Analysis -->|"feedsData"| Components
    CLI_Entry -->|"staticBuild"| AppShell
    AppShell <-->|"realTimeAPI"| Backend
    Components <-->|"realTimeAPI"| Backend
    External -->|"integrates"| Backend
    External -->|"integrates"| AppShell

    %% Click Events
    click CLI_Entry "https://github.com/antfu/node-modules-inspector/blob/main/packages/node-modules-inspector/src/node/cli.ts"
    click Configuration_Manager "https://github.com/antfu/node-modules-inspector/blob/main/node-modules-inspector.config.ts"
    click Configuration_Manager "https://github.com/antfu/node-modules-inspector/blob/main/packages/node-modules-inspector/src/node/config.ts"
    click Analysis "https://github.com/antfu/node-modules-inspector/tree/main/packages/node-modules-tools/"
    click AppShell "https://github.com/antfu/node-modules-inspector/blob/main/packages/node-modules-inspector/src/app/app.vue"
    click Components "https://github.com/antfu/node-modules-inspector/tree/main/packages/node-modules-inspector/src/app/components"
    click Components "https://github.com/antfu/node-modules-inspector/tree/main/packages/node-modules-inspector/src/app/state"
    click Backend "https://github.com/antfu/node-modules-inspector/tree/main/packages/node-modules-inspector/src/app/backends"
    click Backend "https://github.com/antfu/node-modules-inspector/blob/main/packages/node-modules-inspector/src/node/server.ts"
    click External "https://github.com/antfu/node-modules-inspector/tree/main/packages/node-modules-inspector/src/app/webcontainer"
    click External "https://github.com/antfu/node-modules-inspector/tree/main/packages/node-modules-inspector/src/node/webcontainer"

    %% Styles
    classDef cli fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef config fill:#FFFACD,stroke:#000,stroke-width:2px;
    classDef analysis fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef backend fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef frontend fill:#F08080,stroke:#000,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:2px;
```
