# jimm98y/sharprtsptowebrtc architecture

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

- Interactive diagram: https://gitdiagram.com/jimm98y/sharprtsptowebrtc
- Repository: https://github.com/jimm98y/sharprtsptowebrtc

## Overview

##### Main Components
- Frontend Client (React App)
- Located in the “ClientApp” directory inside src/RTSPtoWebRTCGateway.
- Contains key elements like index.html and components (CameraViewer.js, NavMenu.js, etc.) that are responsible for rendering the WebRTC video stream and handling user interactions.
- Backend API / Gateway (ASP.NET Core App)
- Found in src/RTSPtoWebRTCGateway with Controllers, Pages, Program.cs, and configuration (appsettings.json).
- Contains the WebRTCController that exposes REST endpoints (e.g., get offer, set answer, add ICE candidate) for signaling between clients and the WebRTC proxy service.
- RTSP to WebRTC Proxy Service
- This part of the system actually bridges the RTSP stream with WebRTC functionality and is implemented by the code in the SharpRTSPtoWebRTC project (e.g., RTSPtoWebRTCProxyService, RTSPtoWebRTCProxy.cs).
- External RTSP Streams
- These are not part of the repository but are external sources that the system connects to (e.g., cameras streaming H264/H265 content).
- Supporting Libraries/Frameworks
- sipsorcery for the WebRTC implementation.
- SharpRTSP for RTSP client functionality.
- Concentus and SharpJaad for handling audio transcoding.

##### Relationships and Interactions
- Client Browser → Frontend (React App)
- The browser loads the static files and uses the client-side JavaScript to render the camera view (using the CameraViewer component) and initiate WebRTC signaling.
- React App → Backend API (WebRTC Signaling)
- API calls made from the client (using endpoints exposed by WebRTCController) to begin a session – these include obtaining the offer, sending the answer back, and exchanging ICE candidates.
- Backend API → RTSP to WebRTC Proxy Service
- The controller leverages the RTSPtoWebRTCProxyService (registered in Startup/Program) to manage the RTSP session and conversion.
- RTSP to WebRTC Proxy Service → External RTSP Stream
- Handles the inbound RTSP stream from a camera and manages the session (without video transcoding, but with AAC to Opus audio transcoding when needed).

##### Architectural Patterns and Design Principles
- Layered Architecture:
- The system is clearly separated between the Frontend (client) and the Backend (API and service layers).
- API-Driven Communication:
- The RESTful endpoints in WebRTCController indicate a service that acts as a mediator between the browser and the WebRTC proxy service.
- Modular Microservice-like Segmentation:
- Although the code is encapsulated in one solution (with different projects and directories) it logically separates concerns (UI vs server-side processing vs proxy logic).

##### Relevant Technologies
- ASP.NET Core (for backend service and API endpoints)
- C# and .NET (for the core logic, including the RTSPtoWebRTC gateway)
- React (for the client-side application in the ClientApp folder)
- WebRTC (for real-time communication)
- Additional libraries: sipsorcery, SharpRTSP, concentus, and SharpJaad.

##### Specific Elements
- Client Browser: label it “React WebRTC Viewer” and include components such as CameraViewer.
- Backend API: label it “ASP.NET Core Gateway” that includes the WebRTCController and related components.
- RTSPtoWebRTC Proxy Service: encapsulated as a separate service/module within the backend.
- Data flows from the browser to the API (e.g., signaling messages, API calls).
- API to the RTSP proxy service to demonstrate control flow (e.g., obtaining offers, transmitting the media stream).
- Inversely, show the return path from the RTSP stream/Proxy Service back to the browser.
- Components with the primary libraries they use (e.g., “Uses sipsorcery for WebRTC”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        FE1("React WebRTC Viewer"):::frontend
        FE2("React Components"):::frontend
    end

    subgraph "Backend"
        BE1("ASP.NET Core Gateway"):::backend
        BE2("WebRTC Controller"):::backend
        BE3("Configuration (Program & appsettings)"):::backend
    end

    subgraph "RTSP Proxy"
        RP1("RTSP to WebRTC Proxy Service"):::proxy
        RP2("RTSP Proxy Implementation"):::proxy
    end

    EX("External RTSP Streams"):::external

    FE1 -->|"signaling"| BE1
    BE1 -->|"calls"| BE2
    BE1 -->|"initializes"| BE3
    BE1 -->|"invokes"| RP1
    RP1 -->|"uses"| RP2
    RP1 -->|"fetches_stream"| EX
    EX -->|"streams_data"| RP1
    RP1 -->|"delivers_stream"| BE1
    BE1 -->|"renders_stream"| FE1

    click FE1 "https://github.com/jimm98y/sharprtsptowebrtc/tree/main/src/RTSPtoWebRTCGateway/ClientApp"
    click FE2 "https://github.com/jimm98y/sharprtsptowebrtc/tree/main/src/RTSPtoWebRTCGateway/ClientApp/src/components"
    click BE1 "https://github.com/jimm98y/sharprtsptowebrtc/tree/main/src/RTSPtoWebRTCGateway"
    click BE2 "https://github.com/jimm98y/sharprtsptowebrtc/blob/main/src/RTSPtoWebRTCGateway/Controllers/WebRTCController.cs"
    click BE3 "https://github.com/jimm98y/sharprtsptowebrtc/blob/main/src/RTSPtoWebRTCGateway/Program.cs"
    click RP1 "https://github.com/jimm98y/sharprtsptowebrtc/blob/main/src/SharpRTSPtoWebRTC/WebRTCProxy/RTSPtoWebRTCProxyService.cs"
    click RP2 "https://github.com/jimm98y/sharprtsptowebrtc/blob/main/src/SharpRTSPtoWebRTC/WebRTCProxy/RTSPtoWebRTCProxy.cs"

    classDef frontend fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef backend fill:#aed6f1,stroke:#2980b9,stroke-width:2px;
    classDef proxy fill:#a9dfbf,stroke:#27ae60,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
```
