# nerfstudio-project/viser architecture

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

- Interactive diagram: https://gitdiagram.com/nerfstudio-project/viser
- Repository: https://github.com/nerfstudio-project/viser

## Overview

##### Core Components

a. Server-Side (Python)
- Core API Layer (/src/viser/)
- Scene API (_scene_api.py)
- GUI API (_gui_api.py)
- Message handling (_messages.py)
- Transform utilities (transforms/)
- Infrastructure Layer (/src/viser/infra/)
- Websocket communication
- Message buffering
- TypeScript interface generation
- Extras Module (/src/viser/extras/)
- Specialized visualizers (COLMAP, Record3D, URDF)

b. Client-Side (TypeScript/React)
- Web Application (/src/viser/client/)
- React Components
- Three.js Integration
- WebSocket Communication
- Scene Management
- GUI Controls

##### Communication Layer
- WebSocket Protocol
- Message Serialization (msgpack)
- Bi-directional data flow

##### Component Representation
- Rounded rectangles for sub-components
- Hexagons for external dependencies
- Diamonds for data stores or state management

##### Specific Elements

Server Side:
**[Python Core API]**
- ↓
**[Scene API] ← → [GUI API]**
- ↓
**[Transform Utils] → [Message Handling]**
- ↓
**[Infrastructure Layer]**
- ↓
**[WebSocket Server]**

Client Side:
**[React App]**
- ↓
**[Components] ← → [Three.js Integration]**
- ↓
**[Scene Management] ← → [GUI Controls]**
- ↓
**[WebSocket Client]**

Communication:
**[WebSocket Server] ↔ [msgpack serialization] ↔ [WebSocket Client]**

Important Implementation Details to Note:
- Asynchronous nature of the communication
- Message flow for scene updates and GUI interactions
- State management with zustand
- Integration points with Three.js
- How the extras module extends the core functionality

- High-level architecture (showing major components and their interactions)
- Implementation details (showing key classes and protocols)
- Data flow (indicating how information moves through the system)

- Different types of connections
- Component groupings
- Key external dependencies

This will create a comprehensive visualization of viser's architecture while maintaining clarity and usefulness for the principal software engineer.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        ReactApp["React Application"]
        Components["React Components"]:::components
        ThreeJS["Three.js Integration"]:::threejs
        SceneManage["Scene Management"]:::scenemanage
        GUIControls["GUI Controls"]:::guicontrols
        ClientState["Client State Management"]:::clientstate
        WSClient["WebSocket Client"]:::wsclient
        MessageHandler["Message Handler"]:::msghandler

        ReactApp --> Components
        ReactApp --> ThreeJS
        Components <--> SceneManage
        Components <--> GUIControls
        SceneManage <--> ClientState
        SceneManage --> WSClient
        WSClient <--> MessageHandler
    end

    subgraph Communication
        WSProtocol{"WebSocket Protocol"}
        MsgPack{"msgpack serialization"}:::msgpack
    end

    subgraph Server
        CoreAPI["Core API Layer"]
        SceneAPI["Scene API"]:::sceneapi
        GUIAPI["GUI API"]:::guiapi
        MsgHandle["Message Handling"]:::msghandle
        TransformUtils["Transform Utilities"]:::transformutils
        InfraLayer["Infrastructure Layer"]:::infralayer
        WSServer["WebSocket Server"]:::wsserver
        
        subgraph Extras
            COLMAP["COLMAP Visualizer"]:::extras
            Record3D["Record3D Visualizer"]:::extras
            URDF["URDF Visualizer"]:::extras
        end

        CoreAPI --> SceneAPI
        CoreAPI --> GUIAPI
        SceneAPI <--> GUIAPI
        SceneAPI --> MsgHandle
        GUIAPI --> MsgHandle
        SceneAPI --> TransformUtils
        MsgHandle --> InfraLayer
        InfraLayer --> WSServer
        
        SceneAPI --> Extras
        GUIAPI --> Extras
    end

    WSServer <--> WSProtocol
    WSProtocol <--> MsgPack
    MsgPack <--> WSClient

    %% Click events for component mapping
    click SceneAPI "https://github.com/nerfstudio-project/viser/blob/main/src/viser/_scene_api.py"
    click GUIAPI "https://github.com/nerfstudio-project/viser/blob/main/src/viser/_gui_api.py"
    click MsgHandle "https://github.com/nerfstudio-project/viser/blob/main/src/viser/_messages.py"
    click TransformUtils "https://github.com/nerfstudio-project/viser/tree/main/src/viser/transforms/"
    click InfraLayer "https://github.com/nerfstudio-project/viser/tree/main/src/viser/infra/"
    click WSClient "https://github.com/nerfstudio-project/viser/blob/main/src/viser/client/src/WebsocketInterface.tsx"
    click MsgPack "https://github.com/nerfstudio-project/viser/blob/main/src/viser/infra/_messages.py"
    click Components "https://github.com/nerfstudio-project/viser/tree/main/src/viser/client/src/components/"
    click SceneManage "https://github.com/nerfstudio-project/viser/blob/main/src/viser/client/src/SceneTree.tsx"
    click GUIControls "https://github.com/nerfstudio-project/viser/tree/main/src/viser/client/src/ControlPanel/"
    click ThreeJS "https://github.com/nerfstudio-project/viser/blob/main/src/viser/client/src/ThreeAssets.tsx"
    click COLMAP "https://github.com/nerfstudio-project/viser/tree/main/src/viser/extras/colmap/"
    click Record3D "https://github.com/nerfstudio-project/viser/blob/main/src/viser/extras/_record3d.py"
    click URDF "https://github.com/nerfstudio-project/viser/blob/main/src/viser/extras/_urdf.py"
    click ClientState "https://github.com/nerfstudio-project/viser/blob/main/src/viser/client/src/SceneTreeState.tsx"
    click MessageHandler "https://github.com/nerfstudio-project/viser/blob/main/src/viser/client/src/MessageHandler.tsx"

    %% Styling
    classDef components fill:#90EE90
    classDef threejs fill:#ADD8E6
    classDef scenemanage fill:#98FB98
    classDef guicontrols fill:#87CEEB
    classDef clientstate fill:#DDA0DD
    classDef wsclient fill:#FFB6C1
    classDef msghandler fill:#F0E68C
    classDef msgpack fill:#FFD700
    classDef sceneapi fill:#4682B4
    classDef guiapi fill:#4169E1
    classDef msghandle fill:#1E90FF
    classDef transformutils fill:#00BFFF
    classDef infralayer fill:#87CEFA
    classDef wsserver fill:#B0C4DE
    classDef extras fill:#9370DB
```
