# meshcat-dev/meshcat architecture

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

- Interactive diagram: https://gitdiagram.com/meshcat-dev/meshcat
- Repository: https://github.com/meshcat-dev/meshcat

## Overview

##### Main Components Identification

The system consists of these primary components:
- WebSocket Server Interface
- Viewer Core
- Scene Graph Manager
- Command Handler
- Animation System
- Camera Controller
- Rendering Pipeline

##### Component Relationships

**[External Clients] → [WebSocket] → [Command Handler] → [Scene Graph] → [Renderer]**
- ↘ [Animation System]
- ↘ [Camera Controller]

##### Specific Elements

a) Scene Graph Structure:
- Default paths (/Lights, /Grid, /Axes, /Cameras)
- Demonstrate transform hierarchy

b) Command Flow:
- Command types (set_object, set_transform, delete, set_property)
- MsgPack serialization/deserialization process
- Property handling system

c) Camera System:
- Camera coordinate system transformation
- Orbit controls integration
- Demonstrate target and position relationships

##### Technical Details

Annotations for:
- WebSocket protocol details
- MsgPack encoding/decoding
- Three.js integration points
- File format support (OBJ, DAE, STL, GLTF)
- Animation system capabilities

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        EL["External Languages"]
        WB["Web Browser"]
        WC["WebSocket Client"]
    end

    subgraph Communication
        WS["WebSocket Server"]
        MP["MsgPack Encoder/Decoder"]
        CP["Command Protocol"]
    end

    subgraph Core
        VC["Viewer Core"]:::core
        click VC "https://github.com/meshcat-dev/meshcat/blob/master/src/index.js"
        SG["Scene Graph Manager"]:::core
        click SG "https://github.com/meshcat-dev/meshcat/blob/master/test/chained_properties.html"
        TJ["Three.js Integration"]
        CMD["Command Processor"]
    end

    subgraph Rendering
        CS["Camera System"]:::render
        click CS "https://github.com/meshcat-dev/meshcat/blob/master/test/camera_control.html"
        LS["Lighting System"]
        AM["Animation Manager"]:::render
        click AM "https://github.com/meshcat-dev/meshcat/blob/master/test/animation.html"
        RP["Rendering Pipeline"]:::render
        click RP "https://github.com/meshcat-dev/meshcat/blob/master/test/render_callback.html"
    end

    subgraph "Scene Graph"
        direction TB
        PP["Property Handler"]:::scene
        click PP "https://github.com/meshcat-dev/meshcat/blob/master/test/set_color.html"
        FS["File Format Support"]:::scene
        click FS "https://github.com/meshcat-dev/meshcat/blob/master/test/meshfile_geometry_obj.html"
        Paths["Default Paths<br>/Lights<br>/Grid<br>/Axes<br>/Cameras"]:::scene
    end

    EL --> WC
    WB --> WC
    WC --> WS
    WS --> MP
    MP --> CP
    CP --> CMD
    CMD --> SG
    CMD --> AM
    CMD --> CS
    SG --> PP
    SG --> FS
    SG --> Paths
    SG --> RP
    RP --> TJ
    CS --> TJ
    LS --> TJ
    AM --> TJ

    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef comm fill:#2ecc71,stroke:#27ae60,color:white
    classDef scene fill:#e67e22,stroke:#d35400,color:white
    classDef render fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    subgraph Legend
        L1["Core Components"]:::core
        L2["Communication"]:::comm
        L3["Scene Management"]:::scene
        L4["Rendering"]:::render
        L5["External"]:::external
    end
```
