# lvidgen/webrtc architecture

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

- Interactive diagram: https://gitdiagram.com/lvidgen/webrtc
- Repository: https://github.com/lvidgen/webrtc

## Overview

##### Project Type and Purpose
- This project is a client-side WebRTC application that supports chat, file and screen sharing, video calls, and an interactive whiteboard.
- It primarily operates in the browser, with peer-to-peer communications facilitated by WebRTC. A fallback TURN server option is provided (via the FOSS_TURN_Server folder) along with instructions on how to self-host one if needed.

##### Main Components
- Browser/Web Client:
– Indicate UI components for chat, video calls, shared whiteboard and file sharing.
- Signaling and Connection Broker:
– Highlight that the application uses the PeerJS cloud server for the initial handshake and connection setup. This component is vital for establishing peer connections.
– Optionally, note the possibility to replace the cloud server with a self-hosted TURN server.
- Peer-to-Peer Connections:
– Illustrate direct WebRTC data and media channels between clients once the connection is established.
- FOSS TURN Server (Optional):
– Represent the TURN server as an optional component that can be self-hosted (pointing to instructions in FOSS_TURN_Server/howto.md).
– Connect this component to the browser clients to indicate its use for NAT traversal or when direct peer-to-peer connections cannot be established.

##### Relationships and Interactions
- Direct peer-to-peer links between multiple Web Clients to show media and data exchanges.
- That the WebRTC communication occurs directly between peers, with the signaling server (and optionally the TURN server) acting only as the connection facilitator.

##### Architectural Patterns and Technologies
- Use of HTML5/WebRTC for real-time communication.
- Mention WebSockets (implicit in the use of the PeerJS cloud server) for the initial signaling.
- Distinguish between media flows (video calls, screen sharing) and data flows (chat, file sharing, whiteboard data).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Side (Browser)"
        client_html["index.htm"]:::client
        client_css["style.css"]:::client
        client_webrtc["webrtc.js"]:::client
        client_draw["draw.js"]:::client
        client_draggable["draggable.js"]:::client
    end

    peerjs["PeerJS Cloud Server (Signaling)"]:::server
    turn["TURN Server (Optional)"]:::server
    p2p["Direct Peer-to-Peer Connection"]:::p2p

    client_webrtc -->|"initial-handshake"| peerjs
    client_webrtc -->|"fallback"| turn
    client_webrtc <-->|"media+data"| p2p

    click client_html "https://github.com/lvidgen/webrtc/blob/master/index.htm"
    click client_css "https://github.com/lvidgen/webrtc/blob/master/style.css"
    click client_webrtc "https://github.com/lvidgen/webrtc/blob/master/webrtc.js"
    click client_draw "https://github.com/lvidgen/webrtc/blob/master/draw.js"
    click client_draggable "https://github.com/lvidgen/webrtc/blob/master/draggable.js"
    click turn "https://github.com/lvidgen/webrtc/blob/master/FOSS_TURN_Server/howto.md"

    classDef client fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef server fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef p2p fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
```
