# manuelgil/vscode-json-flow architecture

> Architecture diagram of the GitHub repository manuelgil/vscode-json-flow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/manuelgil/vscode-json-flow
- Repository: https://github.com/manuelgil/vscode-json-flow

## Overview

##### Project Type and Purpose
- This is a Visual Studio Code extension (“JSON Flow”) that transforms JSON (and related file types) into interactive node-based graphs. It consists of two main parts:
a. A VS Code extension host (backend) written in TypeScript under `src/`.
b. A React-based webview frontend under `webview/` that renders the graph UI.

##### File Structure Analysis
- Top-level config files (`package.json`, `.vscode`, `tsconfig.json`, Husky hooks, build scripts).
- `src/` – extension code:
- `extension.ts`: activation entry point, command registrations, message passing.
- `app/controllers/`: exposed commands for file operations, graph transformations, feedback.
- `app/providers/`: VS Code API wrappers (file I/O, JSON parsing).
- `app/helpers/`: utilities (tree structure generation, security).
- `app/models` & `interfaces`: type definitions for nodes and trees.
- `test/`: unit tests for extension logic.
- `webview/` – React app:
- `main.tsx` & `App.tsx`: bootstrap the UI.
- `components/`: graph node components, layout elements.
- `common.ts`: message protocol between extension and webview.
- `types/`: TypeScript declarations for messages.
- `images/` & `assets/`: static assets for README and exports.
- `schemas/`: JSON schema for settings validation.

##### Insights from README
- Activation triggers: opening JSON/related files in VS Code, invoking commands via context menu or command palette.
- Features: file conversion, graph rendering, clipboard operations, code generation (uses quicktype under the hood).
- Development & build: `npm run dev` for webview, `npm run build` and `npm run compile` for extension.

a. Main Components
1. VS Code Extension Host (Node process)
- Activation & lifecycle managed by VS Code.
- Registers commands and watches FS events.
2. Extension Backend Modules
- Controllers: handle commands (convert, show graph, copy).
- Providers: interface with VS Code APIs (FileSystem, Workspace).
- Helpers & Models: build internal tree representation of JSON.
- Schema validation (`schemas/config.schema.json`).
3. React Webview Frontend
- UI Container: HTML (`index.html`) served through VS Code Webview API.
- React Components: render nodes, handle zoom/navigation.
- Message Bridge: uses `postMessage` to communicate with backend.
4. External Services & Libraries
- quicktype for code generation.
- D3/vis.js or internal layout logic for graph rendering.
5. File System & VS Code API
- Watches file changes, reads/writes files.
6. Developer Tooling
- Build scripts (Vite, TypeScript), linting (biome, ESLint), Husky hooks, tests.

b. Relationships and Interactions
- User opens a JSON file → VS Code activates extension → backend parses file via providers → builds node-tree model → sends node data via message bridge to webview.
- Webview receives data → React renders node graph → user interactions (zoom, click) send messages back to backend if needed (e.g., “copy selection as JSON”).
- Commands like “Convert to Type or Structure” invoke quicktype in backend → response sent back to editor.

c. Architectural Patterns & Principles
- MVC‐like separation: controllers (C) orchestrate providers (M) and update UI (V via webview).
- Message‐based decoupling between backend and frontend.
- Modular design: each file format support is isolated in controllers and providers.
- Configuration‐driven: schemas validate extension settings.

d. Key Technologies & Frameworks
- TypeScript, VS Code Extension API, quicktype, React, Vite, JSON Schema, Husky, biome.json (formatter), Tailwind (for webview styles).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% VS Code UI Entry
    VSCodeUI["VS Code UI"]:::external
    ExtensionActivation["Extension Activation<br/>(src/extension.ts)"]:::backend
    click ExtensionActivation "https://github.com/manuelgil/vscode-json-flow/blob/main/src/extension.ts"

    VSCodeUI -->|"activates"| ExtensionActivation

    subgraph "Extension Backend"
        direction TB
        %% Controllers
        subgraph "Controllers" 
            direction TB
            FeedbackController["Feedback Controller"]:::controller
            click FeedbackController "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/controllers/feedback.controller.ts"
            FilesController["Files Controller"]:::controller
            click FilesController "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/controllers/files.controller.ts"
            JSONController["JSON Controller"]:::controller
            click JSONController "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/controllers/json.controller.ts"
            TransformController["Transform Controller"]:::controller
            click TransformController "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/controllers/transform.controller.ts"
        end

        %% Providers
        subgraph "Providers"
            direction TB
            FeedbackProvider["Feedback Provider"]:::provider
            click FeedbackProvider "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/providers/feedback.provider.ts"
            FilesProvider["Files Provider"]:::provider
            click FilesProvider "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/providers/files.providers.ts"
            JSONProvider["JSON Provider"]:::provider
            click JSONProvider "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/providers/json.provider.ts"
        end

        %% Helpers
        subgraph "Helpers"
            direction TB
            JSONHelper["JSON Helper"]:::helper
            click JSONHelper "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/helpers/json.helper.ts"
            SecurityHelper["Security Helper"]:::helper
            click SecurityHelper "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/helpers/security.helper.ts"
            TreeHelper["Tree Helper"]:::helper
            click TreeHelper "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/helpers/tree.helper.ts"
        end

        %% Models & Interfaces
        subgraph "Models & Interfaces"
            direction TB
            NodeModel["Node Model"]:::model
            click NodeModel "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/models/node.model.ts"
            ModelsIndex["Models Index"]:::model
            click ModelsIndex "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/models/index.ts"
            TreeInterface["Tree Interface"]:::model
            click TreeInterface "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/interfaces/tree.interface.ts"
            InterfacesIndex["Interfaces Index"]:::model
            click InterfacesIndex "https://github.com/manuelgil/vscode-json-flow/blob/main/src/app/interfaces/index.ts"
        end

        %% Configuration Schema
        ConfigSchema["Config Schema<br/>(schemas/config.schema.json)"]:::schema
        click ConfigSchema "https://github.com/manuelgil/vscode-json-flow/blob/main/schemas/config.schema.json"
    end

    %% External Services & FS
    subgraph "External Services / FS"
        direction TB
        VSCodeAPI["VS Code API"]:::external
        FileSystem["File System"]:::external
        QuicktypeLib["quicktype Library"]:::external
    end

    %% Message Bridge
    MessageBridge["Message Bridge<br/>(postMessage)"]:::external

    %% Webview Frontend
    subgraph "Webview Frontend"
        direction TB
        MainEntry["main.tsx"]:::frontend
        click MainEntry "https://github.com/manuelgil/vscode-json-flow/blob/main/webview/main.tsx"
        AppRoot["App.tsx"]:::frontend
        click AppRoot "https://github.com/manuelgil/vscode-json-flow/blob/main/webview/App.tsx"
        CommonProto["common.ts"]:::frontend
        click CommonProto "https://github.com/manuelgil/vscode-json-flow/blob/main/webview/common.ts"

        subgraph "Components"
            direction TB
            ComponentsDir["components/"]:::frontend
            click ComponentsDir "https://github.com/manuelgil/vscode-json-flow/tree/main/webview/components/"
            CustomNode["CustomNode.tsx"]:::frontend
            click CustomNode "https://github.com/manuelgil/vscode-json-flow/blob/main/webview/components/CustomNode.tsx"
            LoadingComp["Loading.tsx"]:::frontend
            click LoadingComp "https://github.com/manuelgil/vscode-json-flow/blob/main/webview/components/Loading.tsx"
            LoadingCSS["Loading.css"]:::frontend
            click LoadingCSS "https://github.com/manuelgil/vscode-json-flow/blob/main/webview/components/Loading.css"
            LayoutEl["layout-elements.ts"]:::frontend
            click LayoutEl "https://github.com/manuelgil/vscode-json-flow/blob/main/webview/components/layout-elements.ts"
        end

        IndexCSS["index.css"]:::frontend
        click IndexCSS "https://github.com/manuelgil/vscode-json-flow/blob/main/webview/index.css"
        GlobalTypes["global.d.ts"]:::frontend
        click GlobalTypes "https://github.com/manuelgil/vscode-json-flow/blob/main/webview/types/global.d.ts"
        ViteEnvTypes["vite-env.d.ts"]:::frontend
        click ViteEnvTypes "https://github.com/manuelgil/vscode-json-flow/blob/main/webview/types/vite-env.d.ts"
    end

    %% Build & Tooling
    subgraph "Build & Tooling"
        direction TB
        ViteConfig["vite.config.ts"]:::tools
        click ViteConfig "https://github.com/manuelgil/vscode-json-flow/blob/main/vite.config.ts"
        TailwindConfig["tailwind.config.js"]:::tools
        click TailwindConfig "https://github.com/manuelgil/vscode-json-flow/blob/main/tailwind.config.js"
        TSConfigRoot["tsconfig.json"]:::tools
        click TSConfigRoot "https://github.com/manuelgil/vscode-json-flow/blob/main/tsconfig.json"
        TSConfigNode["tsconfig.node.json"]:::tools
        click TSConfigNode "https://github.com/manuelgil/vscode-json-flow/blob/main/tsconfig.node.json"
        TSConfigWeb["tsconfig.web.json"]:::tools
        click TSConfigWeb "https://github.com/manuelgil/vscode-json-flow/blob/main/tsconfig.web.json"
        TSConfigDoc["tsconfig.doc.json"]:::tools
        click TSConfigDoc "https://github.com/manuelgil/vscode-json-flow/blob/main/tsconfig.doc.json"
        BiomeConfig["biome.json"]:::tools
        click BiomeConfig "https://github.com/manuelgil/vscode-json-flow/blob/main/biome.json"
        LintStaged[".lintstagedrc"]:::tools
        click LintStaged "https://github.com/manuelgil/vscode-json-flow/blob/main/.lintstagedrc"
        CommitLint["commitlint.config.js"]:::tools
        click CommitLint "https://github.com/manuelgil/vscode-json-flow/blob/main/commitlint.config.js"
        HuskyHooks[".husky/"]:::tools
        click HuskyHooks "https://github.com/manuelgil/vscode-json-flow/tree/main/.husky/"
    end

    %% Flows
    ExtensionActivation -->|registers commands| FeedbackController
    ExtensionActivation -->|registers commands| FilesController
    ExtensionActivation -->|registers commands| JSONController
    ExtensionActivation -->|registers commands| TransformController

    FeedbackController -->|uses| FeedbackProvider
    FilesController -->|uses| FilesProvider
    JSONController -->|uses| JSONProvider
    TransformController -->|uses| JSONProvider

    FeedbackProvider -->|calls| VSCodeAPI
    FilesProvider -->|calls| FileSystem
    JSONProvider -->|calls| JSONHelper

    JSONHelper -->|builds| TreeHelper
    TreeHelper -->|constructs| NodeModel
    NodeModel -->|defines| ModelsIndex
    ModelsIndex -->|exports| TreeInterface
    TreeInterface -->|managed by| InterfacesIndex

    Controllers -->|validate config| ConfigSchema

    TransformController -->|invokes| QuicktypeLib

    %% Message Bridge
    Controllers -->|send data| MessageBridge
    MessageBridge -->|postMessage| MainEntry
    MainEntry -->|renders| AppRoot
    AppRoot -->|uses| CommonProto
    AppRoot -->|loads| ComponentsDir
    AppRoot -->|imports styles| IndexCSS

    %% Components internals
    ComponentsDir --> CustomNode
    ComponentsDir --> LoadingComp
    ComponentsDir --> LayoutEl
    LoadingComp --> LoadingCSS

    %% Types
    AppRoot -->|uses| GlobalTypes
    AppRoot -->|uses| ViteEnvTypes

    %% User interactions back
    CustomNode -->|onClick messages| MessageBridge
    AppRoot -->|user actions| MessageBridge

    %% Toolchain
    MainEntry -->|built by| ViteConfig
    IndexCSS -->|styled by| TailwindConfig
    TSConfigRoot -.-> ViteConfig
    TSConfigWeb -.-> ViteConfig
    TSConfigNode -.-> HuskyHooks
    BiomeConfig -.-> LintStaged

    %% Styles
    classDef backend fill:#f9f,stroke:#333,stroke-width:1px
    classDef controller fill:#fcf,stroke:#333,stroke-width:1px
    classDef provider fill:#cff,stroke:#333,stroke-width:1px
    classDef helper fill:#ffc,stroke:#333,stroke-width:1px
    classDef model fill:#ccf,stroke:#333,stroke-width:1px
    classDef schema fill:#cfc,stroke:#333,stroke-width:1px
    classDef frontend fill:#cff,stroke:#333,stroke-width:1px
    classDef external fill:#eee,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef tools fill:#eee,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2
```
