# meetecho/simple-whip-server architecture

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

- Interactive diagram: https://gitdiagram.com/meetecho/simple-whip-server
- Repository: https://github.com/meetecho/simple-whip-server

## Overview

##### Main Components

a) Client Layer:
- WHIP Clients (e.g., Simple WHIP Client, GStreamer webrtcbin)
- Web Management Interface (Demo UI)

b) Server Layer:
- HTTP/REST API Server (Node.js)
- WHIP Protocol Handler
- Endpoint Management System

c) Backend Layer:
- Janus WebRTC Server
- VideoRoom Plugin
- WebRTC PeerConnections

##### Component Relationships

- Top layer: External clients and web interface
- Middle layer: The WHIP server implementation
- Bottom layer: Janus WebRTC backend

##### Key Interactions to Highlight

a) Control Flow:
- REST API endpoints (/create, /endpoint/<id>, /resource/<id>)
- Endpoint management operations
- WebRTC session establishment
- ICE candidate handling

b) Media Flow:
- WebRTC media streams from clients to Janus
- Room-based media distribution

##### Specific Implementation Details

- Blue rectangles: Core server components
- Green rectangles: External systems (Janus)
- Yellow diamonds: API endpoints
- Red lines: WebRTC media flows
- Black lines: Control flows

##### Critical Processes

a) Endpoint Creation Flow:
**Client -> REST API -> Endpoint Management -> Janus Room Mapping**

b) Publishing Flow:
**WHIP Client -> REST API -> WHIP Handler -> Janus WebRTC -> VideoRoom**

##### Additional Elements

- Notes about configuration aspects (config.js)
- Authentication points (Bearer tokens)
- Optional components (STUN/TURN servers)

##### Technical Details to Emphasize

- HTTP/REST interfaces
- WebRTC signaling paths
- PeerConnection management
- Room-based architecture
- Resource lifecycle management

Remember to include these specific endpoints in the API layer:
- /whip/create
- /endpoint/<id>
- /resource/<id>
- /endpoints (for testing)

This will give other engineers a clear understanding of how the WHIP server acts as a middleware between WebRTC clients and the Janus infrastructure, while maintaining the protocol-specific requirements of the WHIP specification.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef client fill:#a8e6cf,stroke:#3b6978
    classDef server fill:#dcedc1,stroke:#3b6978
    classDef api fill:#ffd3b6,stroke:#3b6978
    classDef backend fill:#ffaaa5,stroke:#3b6978
    classDef endpoint fill:#ff8b94,stroke:#3b6978
    classDef management fill:#98ddca,stroke:#3b6978

    %% Client Layer
    subgraph Clients
        WHIP[WHIP Clients]:::client
        GSTR[GStreamer webrtcbin]:::client
        WebUI[Web Management Interface]:::client
    end

    %% Server Layer
    subgraph "WHIP Server"
        REST[HTTP/REST API Server]:::server
        WHIPH[WHIP Protocol Handler]:::server
        EndpointMgr[Endpoint Management System]:::server
        Config[Configuration System]:::server
    end

    %% API Endpoints
    subgraph "API Layer"
        Create["/whip/create"]:::api
        Endpoint["endpoint/<id>"]:::api
        Resource["resource/<id>"]:::api
        Endpoints["/endpoints"]:::api
    end

    %% Backend Layer
    subgraph "Janus Backend"
        JanusServer[Janus WebRTC Server]:::backend
        VideoRoom[VideoRoom Plugin]:::backend
        PeerConn[WebRTC PeerConnections]:::backend
    end

    %% Relationships
    WHIP --> Create
    GSTR --> Create
    WebUI --> Endpoints
    
    Create --> REST
    Endpoint --> REST
    Resource --> REST
    Endpoints --> REST
    
    REST --> WHIPH
    REST --> EndpointMgr
    WHIPH --> EndpointMgr
    Config --> REST
    
    WHIPH --> JanusServer
    EndpointMgr --> JanusServer
    JanusServer --> VideoRoom
    VideoRoom --> PeerConn

    %% Click Events
    click REST "https://github.com/meetecho/simple-whip-server/blob/main/src/server.js"
    click WHIPH "https://github.com/meetecho/simple-whip-server/blob/main/src/whip-janus.js"
    click Config "https://github.com/meetecho/simple-whip-server/blob/main/src/config.js"
    click WebUI "https://github.com/meetecho/simple-whip-server/blob/main/web/index.html"
    
    %% Legend
    subgraph Legend
        Client1[Client Components]:::client
        Server1[Server Components]:::server
        API1[API Endpoints]:::api
        Backend1[Backend Components]:::backend
    end
```
