# hubs-foundation/hubs architecture

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

- Interactive diagram: https://gitdiagram.com/hubs-foundation/hubs
- Repository: https://github.com/hubs-foundation/hubs

## Overview

##### Main Components

a. Client-Side Core Components:
- React UI Layer (/src/react-components)
- A-Frame/Three.js 3D Engine Integration
- WebXR System (/src/systems/userinput)
- Networking Layer (/src/network-schemas.ts)
- Media Systems (/src/systems)
- Authentication System (/src/react-components/auth)

b. External Services Integration:
- Reticulum Backend Connection
- Media Storage/CDN
- Authentication Services
- WebRTC Services

##### Key Architectural Patterns to Highlight

a. Component Architecture:
- Relationship between React components and A-Frame entities
- ECS (Entity Component System) pattern used with bit-components and bit-systems
- Event system architecture

b. Network Architecture:
- WebRTC peer connections
- Phoenix Channels integration
- Network schema synchronization

**┌─────────────────────────────────────────────┐**
- User Interface                 │
- ┌─────────┐ ┌─────────┐ ┌─────────┐      │
- React  │ │  HUD    │ │ Menus   │      │
- ┘ └─────────┘ └─────────┘      │
- ┤
- 3D Engine Layer                │
- ┌─────────┐ ┌─────────┐ ┌─────────┐      │
- A-Frame │ │Three.js │ │ Physics │      │
- ┘ └─────────┘ └─────────┘      │
- ┤
- Systems Layer                  │
- ┌─────────┐ ┌─────────┐ ┌─────────┐      │
- Input   │ │ Network │ │ Media   │      │
- ┘ └─────────┘ └─────────┘      │
- ┤
- Service Integration            │
- ┌─────────┐ ┌─────────┐ ┌─────────┐      │
- Reticulum│ │ WebRTC  │ │  Auth   │      │
- ┘ └─────────┘ └─────────┘      │
- ┘

##### Important Relationships

- Data flow between React UI and A-Frame components
- WebRTC peer connections between clients
- Media loading and streaming pathways
- Authentication flow
- Scene graph hierarchy
- Network state synchronization

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        React["React UI Components"]
        HUD["HUD Components"]
        Menus["Menu System"]
        UIRoot["UI Root"]
    end

    subgraph Engine["3D Engine Layer"]
        AFrame["A-Frame Core"]
        ThreeJS["Three.js Engine"]
        Physics["Physics System"]
    end

    subgraph Systems["Systems Layer"]
        InputSys["Input System"]
        NetworkSys["Network System"]
        MediaSys["Media System"]
        CharController["Character Controller"]
        CameraSys["Camera System"]
        AudioSys["Audio System"]
    end

    subgraph Services["Service Integration"]
        Reticulum["Reticulum Backend"]
        WebRTC["WebRTC Services"]
        Auth["Authentication"]
        CDN["Media CDN"]
    end

    subgraph AssetMgmt["Asset Management"]
        AssetLoad["Asset Loaders"]
        TextureMgmt["Texture Management"]
        MediaLoad["Media Loading"]
    end

    %% Relationships
    React --> UIRoot
    UIRoot --> HUD
    UIRoot --> Menus
    
    AFrame --> ThreeJS
    ThreeJS --> Physics
    
    InputSys --> CharController
    NetworkSys --> WebRTC
    MediaSys --> CDN
    
    Systems --> Engine
    Engine --> UI
    
    Auth --> Reticulum
    NetworkSys --> Reticulum
    
    MediaSys --> AssetMgmt
    AssetLoad --> CDN
    
    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef service fill:#90EE90,stroke:#333
    classDef core fill:#ADD8E6,stroke:#333
    classDef media fill:#DDA0DD,stroke:#333
    classDef system fill:#FFE4B5,stroke:#333
    
    class Reticulum,WebRTC,Auth,CDN service
    class React,AFrame,ThreeJS core
    class MediaSys,AssetLoad,MediaLoad media
    class InputSys,NetworkSys,CharController,CameraSys,AudioSys system

    %% Click Events
    click React "https://github.com/Hubs-Foundation/hubs/tree/master/src/react-components/"
    click UIRoot "https://github.com/Hubs-Foundation/hubs/blob/master/src/react-components/ui-root.js"
    click Auth "https://github.com/Hubs-Foundation/hubs/tree/master/src/react-components/auth/"
    click InputSys "https://github.com/Hubs-Foundation/hubs/tree/master/src/systems/userinput/"
    click NetworkSys "https://github.com/Hubs-Foundation/hubs/blob/master/src/network-schemas.js"
    click Physics "https://github.com/Hubs-Foundation/hubs/blob/master/src/bit-systems/physics.ts"
    click AudioSys "https://github.com/Hubs-Foundation/hubs/blob/master/src/systems/audio-system.js"
    click CameraSys "https://github.com/Hubs-Foundation/hubs/blob/master/src/systems/camera-system.js"
    click CharController "https://github.com/Hubs-Foundation/hubs/blob/master/src/systems/character-controller-system.js"
    click AssetLoad "https://github.com/Hubs-Foundation/hubs/tree/master/src/loaders/"
    click TextureMgmt "https://github.com/Hubs-Foundation/hubs/tree/master/src/textures/"
    click MediaLoad "https://github.com/Hubs-Foundation/hubs/blob/master/src/bit-systems/media-loading.ts"
```
