How manuelgil/vscode-json-flow works
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).