# ionorg/ion-sdk-js architecture

> Architecture diagram of the GitHub repository ionorg/ion-sdk-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ionorg/ion-sdk-js
- Repository: https://github.com/ionorg/ion-sdk-js

## Overview

##### Main Components

a) Client-Side Components:
- Ion SDK Client (Core)
- Signal Layer (with two implementations)
- Stream Management
- Connector Layer
- Protocol Buffers Integration

b) External Components:
- Ion Backend (SFU Server)
- WebRTC Infrastructure
- Client Applications

**┌─────────────────────────────────────┐**
- Client Applications          │
- (Examples: ion-echo, ion-pubsub)│
- ┘

**┌─────────────────────────────────────┐**
- Ion SDK Core             │
- ┬──────────┬───────────┤
- Signaling  │  Stream  │ Connector │
- Layer     │ Manager  │   Layer   │
- ┴──────────┴───────────┘

**┌─────────────────────────────────────┐**
- Ion Backend (SFU)            │
- WebRTC Infrastructure        │
- ┘

##### Component Details

- Client Class (src/client.ts)
- LocalStream/RemoteStream (src/stream.ts)
- Connector implementations (src/connector/*)

b) Protocol Interfaces (Hexagons):
- gRPC-Web Implementation
- JSON-RPC Implementation
- Protocol Buffers (from _library/proto/*)

- → for data flow direction
- ⟷ for bidirectional communication

##### Important Relationships to Highlight

- How the Client class interfaces with both signal implementations
- Relationship between LocalStream/RemoteStream and WebRTC
- Demonstrate how Protocol Buffers are used for communication
- Connection between Connectors and the Ion Backend

##### Additional Elements

- Component relationships

##### Technical Details

- WebSocket connections (wss://)
- Supported features (audio, video, datachannel)
- Simulcast capabilities
- Stream control functions (mute/unmute)
- Session management (join/leave)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef signal fill:#4CAF50,stroke:#2E7D32,color:white
    classDef stream fill:#FFC107,stroke:#FFA000,color:black
    classDef external fill:#9E9E9E,stroke:#616161,color:white
    classDef proto fill:#FF5722,stroke:#E64A19,color:white
    classDef apps fill:#673AB7,stroke:#512DA8,color:white

    %% Client Applications Layer
    subgraph Applications
        ClientApps["Client Applications"]
        IonEcho["Ion Echo Example"]
        IonPubSub["Ion PubSub Example"]
    end
    click IonEcho "https://github.com/ionorg/ion-sdk-js/tree/master/examples/ion-echo/"
    click IonPubSub "https://github.com/ionorg/ion-sdk-js/tree/master/examples/ion-pubsub/"

    %% SDK Core Layer
    subgraph CoreSDK
        Client["Ion SDK Client"]
        StreamManager["Stream Manager"]
        ConnectorLayer["Connector Layer"]
    end
    click Client "https://github.com/ionorg/ion-sdk-js/blob/master/src/client.ts"
    click StreamManager "https://github.com/ionorg/ion-sdk-js/blob/master/src/stream.ts"
    click ConnectorLayer "https://github.com/ionorg/ion-sdk-js/blob/master/src/connector/index.ts"

    %% Signal Layer
    subgraph SignalLayer
        SignalCore["Signal Core"]
        GRPCImpl["gRPC-Web Implementation"]
        JSONRPCImpl["JSON-RPC Implementation"]
    end
    click SignalCore "https://github.com/ionorg/ion-sdk-js/blob/master/src/signal/index.ts"
    click GRPCImpl "https://github.com/ionorg/ion-sdk-js/blob/master/src/signal/grpc-web-impl.ts"
    click JSONRPCImpl "https://github.com/ionorg/ion-sdk-js/blob/master/src/signal/json-rpc-impl.ts"

    %% Protocol Buffers
    subgraph Protocols
        IonProto["Ion Protocol"]
        RTCProto["RTC Protocol"]
        SFUProto["SFU Protocol"]
        RoomProto["Room Protocol"]
    end
    click IonProto "https://github.com/ionorg/ion-sdk-js/blob/master/src/_library/proto/ion/ion_pb.js"
    click RTCProto "https://github.com/ionorg/ion-sdk-js/blob/master/src/_library/proto/rtc/rtc_pb.js"
    click SFUProto "https://github.com/ionorg/ion-sdk-js/blob/master/src/_library/proto/sfu/sfu_pb.js"
    click RoomProto "https://github.com/ionorg/ion-sdk-js/blob/master/src/_library/proto/room/proto/room_pb.js"

    %% Connector Components
    subgraph Connectors
        IonConnector["Ion Connector"]
        RoomConnector["Room Connector"]
        RTCConnector["RTC Connector"]
    end
    click IonConnector "https://github.com/ionorg/ion-sdk-js/blob/master/src/connector/ion.ts"
    click RoomConnector "https://github.com/ionorg/ion-sdk-js/blob/master/src/connector/room.ts"
    click RTCConnector "https://github.com/ionorg/ion-sdk-js/blob/master/src/connector/rtc.ts"

    %% External Services
    subgraph Backend
        IonSFU["Ion SFU Server"]
        WebRTCInfra["WebRTC Infrastructure"]
    end

    %% Relationships
    ClientApps --> Client
    IonEcho --> Client
    IonPubSub --> Client
    
    Client --> SignalCore
    SignalCore --> GRPCImpl & JSONRPCImpl
    
    Client --> StreamManager
    Client --> ConnectorLayer
    
    ConnectorLayer --> IonConnector & RoomConnector & RTCConnector
    
    GRPCImpl & JSONRPCImpl --> Protocols
    
    IonConnector & RoomConnector & RTCConnector --> Backend
    
    %% Styling
    class Client,StreamManager,ConnectorLayer core
    class SignalCore,GRPCImpl,JSONRPCImpl signal
    class StreamManager stream
    class IonSFU,WebRTCInfra external
    class IonProto,RTCProto,SFUProto,RoomProto proto
    class ClientApps,IonEcho,IonPubSub apps
```
