# gopring/pdn-webrtc architecture

> Architecture diagram of the GitHub repository gopring/pdn-webrtc, 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/gopring/pdn-webrtc
- Repository: https://github.com/gopring/pdn-webrtc

## Overview

##### Main Components Identification

a) Core Components:
- Signal Server (signal/)
- Media Server (media/)
- PDN (Peer-Assisted Delivery Network) Server (pdn/)
- Broker System (broker/)
- Coordinator (coordinator/)
- Database Layer (database/)
- Metrics System (metric/)

##### Technical Details

Annotations for:
- WebRTC protocols (ICE, STUN, TURN)
- Socket.IO implementation
- Prometheus metrics flow
- Channel key authentication

##### Component Details

Signal Server:
- Controller and handler components
- Socket handling

Media Server:
- Stream management
- Connection handling

PDN Server:
- Peer management
- Super peer selection
- Fault recovery mechanisms

Broker:
- Channel management
- Subscription handling

Database:
- Different info types (channel, client, connection)
- Index structure

Metrics:
- Prometheus data collection
- Grafana visualization

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Clients
        B[Broadcaster]
        V[Viewers]
    end

    subgraph "Server Components"
        subgraph "Signal Server"
            SS["Signal Server"]:::signal
            SC["Controller"]:::signal
            SH["Socket Handler"]:::signal
        end

        subgraph "Media Server"
            MS["Media Server"]:::media
            SM["Stream Management"]:::media
            CH["Connection Handler"]:::media
        end

        subgraph "PDN Server"
            PDN["PDN Server"]:::pdn
            PM["Peer Management"]:::pdn
            SP["Super Peer Selection"]:::pdn
        end

        subgraph "Core Services"
            BR["Broker"]:::broker
            CO["Coordinator"]:::coordinator
            MSG["Message System"]:::core
        end

        subgraph "Data Layer"
            subgraph "Database"
                DB["Memory Database"]:::database
                CI["Channel Info"]:::database
                CLI["Client Info"]:::database
                CONI["Connection Info"]:::database
                IDX["Index Structure"]:::database
            end
        end

        subgraph "Monitoring"
            MT["Metrics"]:::monitoring
            PR["Prometheus"]:::monitoring
            GF["Grafana"]:::monitoring
        end
    end

    B --> |WebSocket| SS
    V --> |WebSocket| SS
    B <--> |WebRTC| MS
    V <--> |WebRTC| PDN

    SS --> SC
    SS --> SH
    SC <--> MSG
    SH <--> MSG

    MS --> SM
    MS --> CH
    
    PDN --> PM
    PDN --> SP

    BR <--> CO
    CO <--> MSG
    BR <--> DB
    
    DB --> CI
    DB --> CLI
    DB --> CONI
    DB --> IDX

    MT --> PR
    PR --> GF

    classDef signal fill:#3498db
    classDef media fill:#2ecc71
    classDef pdn fill:#e67e22
    classDef broker fill:#95a5a6
    classDef coordinator fill:#9b59b6
    classDef core fill:#34495e
    classDef database fill:#f1c40f
    classDef monitoring fill:#8e44ad

    click SS "https://github.com/Gopring/PDN-WebRTC/tree/main/signal"
    click SC "https://github.com/Gopring/PDN-WebRTC/blob/main/signal/controller/controller.go"
    click SH "https://github.com/Gopring/PDN-WebRTC/blob/main/signal/handler/socket.go"
    click MS "https://github.com/Gopring/PDN-WebRTC/blob/main/media/media.go"
    click SM "https://github.com/Gopring/PDN-WebRTC/blob/main/media/stream/stream.go"
    click CH "https://github.com/Gopring/PDN-WebRTC/blob/main/media/connection.go"
    click PDN "https://github.com/Gopring/PDN-WebRTC/blob/main/pdn/pdn.go"
    click BR "https://github.com/Gopring/PDN-WebRTC/blob/main/broker/broker.go"
    click CO "https://github.com/Gopring/PDN-WebRTC/blob/main/coordinator/coordinator.go"
    click DB "https://github.com/Gopring/PDN-WebRTC/blob/main/database/memory/database.go"
    click CI "https://github.com/Gopring/PDN-WebRTC/blob/main/database/channel_info.go"
    click CLI "https://github.com/Gopring/PDN-WebRTC/blob/main/database/client_info.go"
    click CONI "https://github.com/Gopring/PDN-WebRTC/blob/main/database/connection_info.go"
    click IDX "https://github.com/Gopring/PDN-WebRTC/blob/main/database/memory/index.go"
    click MT "https://github.com/Gopring/PDN-WebRTC/blob/main/metric/metric.go"
    click MSG "https://github.com/Gopring/PDN-WebRTC/blob/main/types/message/messages.go"
```
