# xeokit/xeokit-sdk architecture

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

- Interactive diagram: https://gitdiagram.com/xeokit/xeokit-sdk
- Repository: https://github.com/xeokit/xeokit-sdk

## Overview

- Viewer Core: At the heart of the system is the Viewer class (located in src/viewer). This component manages the WebGL render loop, handles camera settings (eye, look, up vectors), and coordinates scene updates.
- Plugin System: Surrounding the Viewer core is the plugin architecture. Various loader plugins (such as XKTLoaderPlugin, GLTFLoaderPlugin, LASLoaderPlugin, OBJLoaderPlugin, CityJSONLoaderPlugin, etc.) extend the viewer’s capabilities. Also include other plugins (for annotations, measurements, navigation, section planes, and more). This modular design allows for class-specific responsibilities (e.g., model loading, scene updates or UI interactions).
- Scene Graph & Model Management: This comprises the scene-related modules (present in src/viewer/scene) that include geometry, mesh handling, cameras, lights, materials, and node hierarchies. This layer takes model data supplied by plugins and transforms it into a renderable scene.
- Rendering Pipeline: Within the viewer, the rendering subsystem deals with WebGL resources, shaders, and the frame update loop. It gets its data from the scene graph and issues rendering calls.
- Extras and Utilities: Components like collision detection (src/extras/collision), context menus (src/extras/ContextMenu), plus other UI and helper modules (for example, pointer controls and marquee pickers) help with user interaction and scene manipulation.

##### Relationships and data flows
- Plugins (e.g., the XKTLoaderPlugin) are responsible for loading external data (like XKT models) and passing parsed scene objects to the scene graph layer.
- The Scene Graph then supplies structured geometry, cameras, lights, etc. to the Rendering Pipeline.
- User input and interaction events (handled by interaction/controls plugins) affect the Viewer core (which updates camera positions and scene state).
- Additionally, utility modules and extras such as collision detection and context menu handling are invoked by both plugins and viewers to provide interactive capabilities.

##### Architectural design patterns
- Modular and Extensible Plugin Architecture: Emphasize how each plugin is a self-contained module that registers itself with the Viewer.
- Layered Design: Show the separation between the data loading/parsing layer (plugins), the scene graph (model representation), and the rendering layer (WebGL processing).
- Decoupled Event and UI Handling: Reflect that interactive extras (e.g., context menus, pointer controls) are separated from the core rendering but still integrated via callbacks or event handlers.

##### Technologies and key file groups
- JavaScript (ES Modules) and TypeScript type definitions (in types/) underpin the code.
- Use of build tools (Rollup configurations) and testing frameworks (Playwright, tests/) may be included in a separate “Tooling & DevOps” section.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Main Components
    B["Plugin System"]:::plugin
    A["Viewer Core"]:::viewer
    C["Scene Graph & Model Management"]:::scene
    D["Rendering Pipeline"]:::render
    E["Extras & Utilities"]:::extras

    %% Relationships and Data Flow
    B -->|"PluginInitialization"| A
    B -->|"ModelIngestion"| C
    A -->|"SceneUpdates"| C
    C -->|"SceneData"| D
    E -->|"UserInteractions"| A

    %% DevOps & Build Subgraph
    subgraph "DevOps & Build"
        F1["rollup.config.js"]:::devops
        F2["tsconfig.json"]:::devops
        F3["package.json"]:::devops
        F4["tests/"]:::devops
    end

    %% Link from DevOps to Viewer Core (using F1 as representative)
    F1 -->|"Build&Test"| A

    %% Click Events
    click A "https://github.com/xeokit/xeokit-sdk/blob/master/src/viewer/Viewer.js"
    click B "https://github.com/xeokit/xeokit-sdk/tree/master/src/plugins"
    click C "https://github.com/xeokit/xeokit-sdk/tree/master/src/viewer/scene"
    click D "https://github.com/xeokit/xeokit-sdk/tree/master/src/viewer/scene/webgl"
    click E "https://github.com/xeokit/xeokit-sdk/tree/master/src/extras"
    click F1 "https://github.com/xeokit/xeokit-sdk/blob/master/rollup.config.js"
    click F2 "https://github.com/xeokit/xeokit-sdk/blob/master/tsconfig.json"
    click F3 "https://github.com/xeokit/xeokit-sdk/blob/master/package.json"
    click F4 "https://github.com/xeokit/xeokit-sdk/tree/master/tests/"

    %% Styles
    classDef viewer fill:#f9f,stroke:#333,stroke-width:2px;
    classDef plugin fill:#d7e8f7,stroke:#333,stroke-width:2px;
    classDef scene fill:#cfffcf,stroke:#333,stroke-width:2px;
    classDef render fill:#ffe6cc,stroke:#333,stroke-width:2px;
    classDef extras fill:#fff2cc,stroke:#333,stroke-width:2px;
    classDef devops fill:#f7d6d6,stroke:#333,stroke-width:2px;
```
