# zthxxx/react-dev-inspector architecture

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

- Interactive diagram: https://gitdiagram.com/zthxxx/react-dev-inspector
- Repository: https://github.com/zthxxx/react-dev-inspector

## Overview

##### Main Components
- Compiler Integration (Babel Plugin):
- Found under the “packages/babel-plugin” directory.
- Inspector Component:
- Located in the “packages/inspector” package.
- This React component, when integrated into your app, reads the saved source info.
- Dev Server Middleware:
- Located in “packages/middleware” and in the various integrations provided (e.g., packages/umi3-plugin, packages/umi4-plugin, packages/vite-plugin, etc.).
- These middlewares capture requests from the Inspector component and forward them appropriately.
- Launch Editor Endpoint:
- Under “packages/launch-editor-endpoint”.
- Responsible for receiving API requests and invoking your local IDE to open the specific file.
- Examples & Documentation:
- The “examples” folder shows integrations with various frameworks (CRA, Next.js, rspack, multiple versions of Umi and Vite). This emphasizes that the tool has been tailored for a wide range of React-based ecosystems.
- Build & Dev Tools:
- There are configuration files and scripts at the root (like .github workflows, PNPM configurations, and various project scripts) that manage building, versioning, and testing.

##### Relationships and Interactions
- The user interacts with the React application in the browser. Inside it, the Inspector component detects when a developer clicks on a component.
- The Inspector component uses the source mapping (possibly injected at build/compile time by the Babel plugin) to know the file location.
- It sends this source path via an API call to the dev server middleware.
- The middleware relays the request to the Launch Editor Endpoint, which then triggers the local IDE to open the file.
- The build tools and tooling (different bundlers or frameworks defined in various example integrations) show how this system integrates seamlessly with different environments.

##### Architectural Patterns/Design Principles
- Modular Design: Each feature (plugin, inspector, middleware, launch-editor) is kept in its own package. This separation makes it easy to maintain and extend.
- Middleware-Based Communication: The Inspector component’s API calls are handled by custom middleware in the dev server to bridge browser actions and local system actions.
- Extensibility: With plugins available for different bundlers (Webpack, Vite, rspack, Umi, CRA), the architecture is designed to be framework-agnostic.
- Integration Over Layers: The system clearly differentiates between compile-time (source injection), runtime (Inspector in the browser), and development tooling (middleware to open the IDE).

##### Relevant Technologies/Frameworks
- React: The core library since the tool targets React developers.
- Babel: For the compiler plugin that injects source mapping.
- Various dev server middleware integrations (specific to bundlers like Vite, rspack, etc.).
- Node.js and middleware frameworks on the dev-server side.
- GitHub actions and workflows are used to handle CI/CD.

##### Final Summary
- Follow this with a “React Application” node highlighting the Inspector Component.
- Link it to an “API/Middleware” layer (showing Dev Server Middleware) which communicates with the “Launch Editor Endpoint.”
- On the side, indicate the “Babel Plugin” which runs during build time and injects source info back into the React components.

## Diagram (Mermaid)

```mermaid
graph TD
    A("Developer Action (Browser Click)"):::external
    F("Babel Plugin (Source Mapping Injection)"):::build
    B("Inspector Component (React App)"):::frontend
    C("Dev Server Middleware (API Layer)"):::middleware
    D("Launch Editor Endpoint (Open IDE)"):::backend
    E("Local IDE"):::backend

    %% Main Flow
    F -->|"injects"| B
    A -->|"triggers"| B
    B -->|"sends_API_request"| C
    C -->|"forwards_request"| D
    D -->|"opens_file_in"| E

    %% Additional Components: Integrations and Dev Tools
    subgraph "Integration & Documentation"
        G("Examples"):::integration
        H("Docs"):::integration
    end

    subgraph "Build & Dev Tools"
        I("Build & Dev Tools"):::build
    end

    %% Connections to Additional Components
    D -->|"configuredBy"| I
    D -->|"utilizes"| G
    D -->|"utilizes"| H

    %% Click Events
    click F "https://github.com/zthxxx/react-dev-inspector/tree/dev/packages/babel-plugin"
    click B "https://github.com/zthxxx/react-dev-inspector/tree/dev/packages/inspector"
    click C "https://github.com/zthxxx/react-dev-inspector/tree/dev/packages/middleware"
    click D "https://github.com/zthxxx/react-dev-inspector/tree/dev/packages/launch-editor-endpoint"
    click G "https://github.com/zthxxx/react-dev-inspector/tree/dev/examples"
    click H "https://github.com/zthxxx/react-dev-inspector/tree/dev/docs"
    click I "https://github.com/zthxxx/react-dev-inspector/tree/dev/scripts"

    %% Styles
    classDef external fill:#AED6F1,stroke:#2980B9,stroke-width:2px;
    classDef frontend fill:#F9E79F,stroke:#F39C12,stroke-width:2px;
    classDef middleware fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef backend fill:#D4EFDF,stroke:#1ABC9C,stroke-width:2px;
    classDef build fill:#FADBD8,stroke:#E74C3C,stroke-width:2px;
    classDef integration fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
```
