# analyticalgraphicsinc/gltf-vscode architecture

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

- Interactive diagram: https://gitdiagram.com/analyticalgraphicsinc/gltf-vscode
- Repository: https://github.com/analyticalgraphicsinc/gltf-vscode

## Overview

##### Project type and purpose
- This is a Visual Studio Code Extension (“glTF Tools”) that provides:
- Preview and debug of glTF 1.0/2.0 models in multiple 3D engines (Babylon, Three, Cesium, Filament).
- Commands to import/export between .gltf/.glb, inspect data, validate against schemas and the Khronos Validator.
- A tree‐view outline, quick‐fixes, hover/tooltips, autocomplete, and an animation editor.

##### File structure
- Top‐level:
- package.json, tsconfig.json – extension manifest and build config
- src/ – TypeScript code for the VSCode extension host (commands, providers, validators, tree view)
- server/ – A small Node.js HTTP server (server.ts) that hosts the Webview UI assets (HTML/CSS/JS)
- pages/ – Static HTML, CSS, JS for each preview engine’s Webview (threeView, babylonView, etc.)
- engines/ – JavaScript/WASM decoder bundles for each 3D engine (Draco, Basis, Babylon)
- schemas/ – JSON Schema definitions for glTF 1.0/2.0 and extensions used for validation/autocomplete
- util/ – Helper scripts to import/generate schema files and mappings
- test/ – Unit tests for extension code
- resources/, environments/, images/ – UI assets and default environment maps for preview windows

##### README for additional insights
- Extension uses VSCode APIs (commands, content providers, diagnostics, webviews).
- Leverages external libraries: Babylon.js, Three.js, Cesium, Filament, Draco, Basis Universal, Knockout.js.
- Runs Khronos glTF Validator automatically or on demand.
- Supports quick‐fix code actions for specific validation codes.

a. Main components
1. VSCode Editor Host
– Extension Host Process (src/*.ts)
– Registers Commands, Language Features, Diagnostics
2. HTTP Server (server/server.ts)
– Serves Webview assets on localhost
3. Webview Frontend (pages/*.html, .js, .css)
– UI for 3D preview, debug tools, menus (uses Knockout for bindings)
4. 3D Engines & Decoders (engines/)
– BabylonJS, ThreeJS, Cesium, Filament, Draco, Basis (JS + WASM)
5. File System & Schemas
– glTF JSON Schemas (schemas/…), util scripts to manage them
– Read/write .gltf/.glb/.bin files, data‐URIs
6. External Validator
– Khronos glTF Validator (CLI/WASM)
7. Utility Scripts (util/)
– Schema imports, extension mappings, test harness

b. Relationships & data flow
- User triggers a command (Preview, Import, Export, Inspect) via Command Palette → routed to Extension Host
- Extension Host reads/writes files on disk (glTF, bin, images), updates text documents
- For Preview: Extension Host launches/ensures HTTP Server is running → opens Webview pointing to http://localhost:<port>/*
- Webview fetches HTML/CSS/JS + engine scripts from the HTTP Server → renders 3D scene using the selected engine
- For Validation: Extension Host invokes the Khronos Validator (spawn process or WASM), collects diagnostics → pushes to VSCode’s Problems panel
- Quick‐Fix actions are implemented in the Extension Host, editing JSON or binary URIs, and saving new files

c. Architectural patterns & design principles
– Extension Host / Webview separation (backend vs. frontend in VSCode extension model)
– Micro‐frontend style: separate web apps per engine under pages/
– Modular decoders (engines/) loaded dynamically in Webview
– JSON Schema‐driven validation & autocomplete
– Code‐actions (quick fixes) as discrete providers mapping validator codes to edits

d. Key technologies / libraries
– TypeScript, Node.js, VSCode Extension API
– Webview API → HTML/CSS/JS frontends
– JavaScript/WASM modules: Draco, Basis, zstd, meshopt
– 3D Engines: Babylon.js, Three.js, Cesium, Filament
– JSON Schema (Khronos glTF schemas)
– CLI/WASM glTF Validator
– Testing: Mocha/Jest via test/*.ts

## Diagram (Mermaid)

```mermaid
graph TB
    user["User"]:::external
    user -->|triggers command| VSCodeUI["VSCode Editor UI"]:::external
    VSCodeUI -->|"Command API"| ExtensionHost["Extension Host"]:::backend
    ExtensionHost -->|"read/write files"| FileSystem["File System"]:::storage
    FileSystem -->|"JSON Schemas"| Schemas["Schemas"]:::storage
    ExtensionHost -->|"launch"| HTTPServer["HTTP Server"]:::backend
    HTTPServer -->|"serves assets"| Webview["Webview Frontends"]:::frontend
    Webview -->|"loads runtime modules"| Engines["Engines & Decoders"]:::frontend
    ExtensionHost -->|"invoke validation"| Validator["Khronos Validator"]:::tools
    Validator -->|"reports diagnostics"| VSCodeUI
    ExtensionHost -->|"provides quick-fixes"| QuickFix["Quick-Fix Actions"]:::tools

    subgraph "Utility Scripts"
      Util["Utility Scripts"]:::tools
    end
    subgraph "Test Harness"
      Tests["Unit Tests"]:::tools
    end

    click ExtensionHost "https://github.com/analyticalgraphicsinc/gltf-vscode/tree/master/src/"
    click HTTPServer "https://github.com/analyticalgraphicsinc/gltf-vscode/blob/master/server/src/server.ts"
    click HTTPServer "https://github.com/analyticalgraphicsinc/gltf-vscode/blob/master/server/package.json"
    click HTTPServer "https://github.com/analyticalgraphicsinc/gltf-vscode/blob/master/server/tsconfig.json"
    click Webview "https://github.com/analyticalgraphicsinc/gltf-vscode/tree/master/pages/"
    click Engines "https://github.com/analyticalgraphicsinc/gltf-vscode/tree/master/engines/"
    click Schemas "https://github.com/analyticalgraphicsinc/gltf-vscode/tree/master/schemas/"
    click Util "https://github.com/analyticalgraphicsinc/gltf-vscode/tree/master/util/"
    click Tests "https://github.com/analyticalgraphicsinc/gltf-vscode/tree/master/test/"

    classDef backend fill:#f9f,stroke:#333,stroke-width:1px
    classDef frontend fill:#9f9,stroke:#333,stroke-width:1px
    classDef storage fill:#ff9,stroke:#333,stroke-width:1px
    classDef tools fill:#9ff,stroke:#333,stroke-width:1px
    classDef external fill:#ccc,stroke:#333,stroke-width:1px
```
