# marionlxy/rtvs architecture

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

- Interactive diagram: https://gitdiagram.com/marionlxy/rtvs
- Repository: https://github.com/marionlxy/rtvs

## Overview

##### Project Type and Purpose
- RTVS is a commercial-grade, real-time video platform that handles live and historical video streaming using multiple protocols, including 1078 and 28181.
- Its purpose is to deliver low-latency (≈200ms) video transmission across various platforms (desktop browsers, mobile, WeChat, native apps) and provide a complete end‐to‐end video solution with integrated control, monitoring, and gateways for protocol conversion.
- The README and file tree indicate that besides the core streaming server, there are supporting projects (e.g., JT808GW, gbSip) and related services (attachment services, simulators).

##### Analyzing the File Structure
- The top-level layout includes multiple directories:
- .github: Contains CI/CD workflows (automation and deployment pipelines).
- script: This is a key directory that includes subdirectories/scripts related to:
- Cluster and deployment configurations (clusterMyData, run_all.sh, run_cluster.sh).
- Protocol-specific gateway configuration (gw808 for the 808 gateway; gb28181 for national standard GB28181 interfaces; rtvsMyData for configuration and logs).
- Support for media streaming via WebRTC (webrtc folder, including mediasoup installation script and server scripts).
- Monitoring & logging components (grafana, influxdb, mysql, nginx) which illustrate that the project uses InfluxDB/Grafana for metrics, MySQL for storage, and Nginx for reverse proxy.
- test: Contains test assets including HTML pages and images to verify streaming performance.
- wx: Contains components for the WeChat mini-program integration.
- Configuration files, docker-related scripts, and deployment scripts indicate that the system is containerized and built for easy deployment across various environments.

a. Main Components:
- Frontend Clients:
- Web clients (JavaScript UI controls, test pages),
- Mobile/WeChat mini-program (wx folder),
- Possibly native apps (Android demo).
- API/Signal Processing Server:
- The core RTVS backend that handles video processing, signal management, and API endpoints.
- Protocol Gateways:
- JT808 or 808 gateway (script/gw808),
- GB28181 gateway (script/gb28181),
- These components convert or handle signaling for devices using the respective protocols.
- Media Streaming Engine:
- WebRTC and potentially other streaming mechanisms (e.g., FMP4, RTMP, HLS) with an emphasis on hardware decoding and adaptive streaming; see script/webrtc.
- Data Storage & Logging:
- MySQL (script/mysql) for system records and historical video metadata.
- InfluxDB (script/influxdb) for performance metrics and monitoring.
- Monitoring & Visualization:
- Grafana dashboards (script/grafana) to monitor system performance and logs.
- Reverse Proxy & Deployment:
- Nginx (script/nginx) for routing, load balancing, or HTTPS termination.
- Docker automation scripts for running the entire system (e.g., run_all.sh, run_attachment.sh).
- CI/CD Pipeline:
- GitHub workflows (.github/workflows) for automated testing/deployment.

b. Relationships and Interactions:
- Clients make API/service requests to the Backend server.
- The Backend interfaces with protocol gateways (808, GB28181) to connect with external devices.
- Media streaming components handle real-time video data selection (from hardware decoders) and interact with the Backend for session control.
- The database systems (MySQL) persist metadata and logs, while InfluxDB collects real-time metrics.
- Nginx acts as the entry point, routing requests from clients to the appropriate backend services.
- Docker scripts coordinate deployments and cluster management for scaling.

c. Architectural Patterns and Design Principles:
- Modular Separation: The design distinguishes between UI clients, API logic, protocol gateways, and media processing.
- Containerization and Orchestration: Deployment scripts and docker images imply container-based deployment, simplifying scalability.
- Loose Coupling: Use of standard API endpoints and protocols makes it easier to plug in external modules (e.g., attach additional protocols or data sources).
- Monitoring and Logging: Dedicated services for InfluxDB and Grafana indicate a focus on observability.
- Horizontal Scalability: Cluster and run_all scripts are geared toward scaling the system to handle many concurrent video streams.

d. Technologies, Frameworks, and Libraries:
- Docker for containerization.
- Nginx as a reverse proxy.
- MySQL and InfluxDB for data persistence and monitoring.
- Grafana for visualization.
- WebRTC for real-time communication, with mediasoup likely supporting this under script/webrtc.
- Scripting (Bash) plays a crucial role in deployment (various shell scripts).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% System Boundary
    subgraph "RTVS Platform"
    
        %% Client Layer
        subgraph "Client Layer"
            WebClient["Web Client"]:::frontend
            WeChatMP["WeChat Mini-Program"]:::frontend
        end
        
        %% Deployment & Infrastructure Layer
        subgraph "Deployment & Infrastructure"
            Nginx["Nginx Proxy"]:::infra
            CICD["CI/CD Pipeline"]:::infra
        end

        %% API/Backend Layer
        subgraph "API/Backend Layer"
            CoreServer["RTVS Core Server"]:::backend
        end

        %% Gateway Layer
        subgraph "Gateway Layer"
            JT808["JT808 Gateway"]:::gateway
            GB28181["GB28181 Gateway"]:::gateway
        end

        %% Media Processing Layer
        subgraph "Media Processing Layer"
            WebRTC["WebRTC Engine"]:::media
        end

        %% Data & Monitoring Layer
        subgraph "Data & Monitoring Layer"
            MySQL["MySQL Database"]:::data
            Influx["InfluxDB"]:::data
            Grafana["Grafana Monitoring"]:::data
        end

    end

    %% Connections
    %% Clients connect to Nginx
    WebClient -->|"request"| Nginx
    WeChatMP -->|"request"| Nginx

    %% Nginx routes requests to Core Server and receives CI/CD deployments
    Nginx -->|"routes to"| CoreServer
    CICD -->|"deploys to"| Nginx
    CICD -->|"deploys to"| CoreServer

    %% Core Server communicates with Protocol Gateways
    CoreServer -->|"signals"| JT808
    CoreServer -->|"signals"| GB28181

    %% Core Server coordinates with Media Streaming Engine
    CoreServer -->|"controls"| WebRTC

    %% Media Engine streams video to Clients
    WebRTC -->|"streams"| WebClient
    WebRTC -->|"streams"| WeChatMP

    %% Core Server interacts with Data Storage
    CoreServer -->|"writes"| MySQL
    CoreServer -->|"logs metrics"| Influx

    %% InfluxDB feeds metrics to Grafana
    Influx -->|"provides data"| Grafana

    %% Click Events
    click WebClient "https://github.com/marionlxy/rtvs/blob/master/test/tstrtvs.html"
    click WeChatMP "https://github.com/marionlxy/rtvs/blob/master/wx/rtvs.wx.js"
    click CoreServer "https://github.com/marionlxy/rtvs/blob/master/script/run_rtvs.sh"
    click CoreServer "https://github.com/marionlxy/rtvs/tree/master/script/rtvsMyData"
    click JT808 "https://github.com/marionlxy/rtvs/tree/master/script/gw808"
    click GB28181 "https://github.com/marionlxy/rtvs/tree/master/script/gb28181"
    click WebRTC "https://github.com/marionlxy/rtvs/tree/master/script/webrtc"
    click MySQL "https://github.com/marionlxy/rtvs/tree/master/script/mysql"
    click Influx "https://github.com/marionlxy/rtvs/tree/master/script/influxdb"
    click Grafana "https://github.com/marionlxy/rtvs/tree/master/script/grafana"
    click Nginx "https://github.com/marionlxy/rtvs/tree/master/script/nginx"
    click CICD "https://github.com/marionlxy/rtvs/tree/master/.github/workflows"

    %% Styles
    classDef frontend fill:#a3cef1,stroke:#03396c,stroke-width:2px;
    classDef backend fill:#c7e9b4,stroke:#237b3f,stroke-width:2px,stroke-dasharray: 5, 5;
    classDef gateway fill:#fff79a,stroke:#b58900,stroke-width:2px;
    classDef media fill:#a1de93,stroke:#2d572c,stroke-width:2px;
    classDef data fill:#f7a1c4,stroke:#d11149,stroke-width:2px;
    classDef infra fill:#d3d3d3,stroke:#808080,stroke-width:2px,stroke-dasharray: 2, 2;
```
