# saddysk/videopie architecture

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

- Interactive diagram: https://gitdiagram.com/saddysk/videopie
- Repository: https://github.com/saddysk/videopie

## Overview

##### Project type and purpose
- This is a full-stack, one-on-one video conferencing web application (“VideoPie”) built with WebRTC.
- It provides real-time video/audio calls, file transfer, live chat, screen sharing (Canvas), mute/unmute controls, and a timer.
- The Node.js server (server.js) acts as the WebRTC signaling server, and the client directories (peerA/ and peerB/) host the two endpoints.

##### File structure
Top-level:
- server.js – Node.js signaling (likely using WebSocket or Socket.io)
- index.html & style.css – landing or common client page
- peerA/peerA.html + sender.js – client A’s UI & signaling/client-side logic
- peerB/peerB.html + receiver.js – client B’s UI & logic
- Canvas/ – whiteboard or screen-share module (canvas/index.html, canvas.js, style.css)
- node_modules, package-lock.json – server dependencies
Key patterns:
- Separation of signaling (server.js) vs. media logic (sender.js/receiver.js)
- Modular front-end: main pages vs. Canvas submodule

##### README for additional insights
- Confirms WebRTC usage and features (file transfer, chat, screen share).
- No further architectural notes, so infer default WebRTC flows (offer/answer, ICE candidates, STUN/TURN).

##### Main components & interactions
a. Components:
1. Client A UI (peerA.html + sender.js)
2. Client B UI (peerB.html + receiver.js)
3. Signaling Server (server.js)
4. Canvas Module (Canvas/index.html + canvas.js)
5. STUN/TURN infrastructure (external service)
6. Optional: File-system (for file transfer buffering)
b. Relationships/Data Flow:
- Clients A & B load their HTML/CSS/JS from the Node.js server (static hosting).
- Upon “call” initiation, A sends an SDP offer → Signaling Server → B.
- B responds with SDP answer → Signaling Server → A.
- ICE candidates exchanged via Signaling Server.
- Peer connection established P2P for media (video/audio) streams & data channels (chat, file transfer).
- Screen sharing uses getDisplayMedia → Canvas Module for drawing or annotations.
c. Architectural Patterns/Principles:
- MVC-like separation on the client: UI (HTML/CSS), signaling logic (sender.js/receiver.js), media layer (WebRTC API).
- Single-page submodule (Canvas) detachable from main UI.
- Event-driven messaging via WebSocket/Socket.io.
d. Key technologies:
- Node.js + Express (serving static files + WebSocket signaling)
- WebRTC API (RTCPeerConnection, MediaStream, RTCDataChannel)
- HTML5 Canvas API (for screen share/annotation)
- CSS for styling
- (Possibly) Socket.io or ws library for signaling

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Client A"
        A_UI["Peer A UI (HTML/CSS)"]:::ui
        A_Signaling["Signaling Logic (sender.js)"]:::signaling
        A_MS["MediaStream"]:::media
        A_DC["DataChannel"]:::data
    end

    subgraph "Signaling Server"
        SS_Node["Node.js Server"]:::server
        SS_Static["Static File Host"]:::server
        Landing["Landing Page (index.html)"]:::ui
        LandingCSS["Landing CSS (style.css)"]:::ui
    end

    subgraph "Client B"
        B_UI["Peer B UI (HTML/CSS)"]:::ui
        B_Signaling["Signaling Logic (receiver.js)"]:::signaling
        B_MS["MediaStream"]:::media
        B_DC["DataChannel"]:::data
    end

    STUN("STUN/TURN Servers"):::cloud

    subgraph "Canvas Module"
        C_UI["Canvas UI (index.html)"]:::canvas
        C_Logic["Canvas Logic (canvas.js)"]:::canvas
        C_Style["Canvas CSS (style.css)"]:::canvas
    end

    A_UI --> A_Signaling
    A_Signaling -->|"SDP/ICE"| SS_Node
    SS_Node -->|"SDP/ICE"| B_Signaling
    B_Signaling --> B_UI

    A_MS -->|"P2P MediaStream"| B_MS
    A_DC -.->|"P2P DataChannel"| B_DC

    A_Signaling -->|"serves files"| SS_Static
    B_Signaling -->|"serves files"| SS_Static
    SS_Static --> A_UI
    SS_Static --> B_UI
    SS_Static --> C_UI
    SS_Static --> Landing
    SS_Static --> LandingCSS

    A_MS -->|"screen share"| C_Logic
    B_MS -->|"screen share"| C_Logic
    C_UI --> C_Logic
    C_UI --> C_Style

    SS_Node --> STUN
    A_Signaling --> STUN
    B_Signaling --> STUN

    click A_UI "https://github.com/saddysk/videopie/blob/main/peerA/peerA.html"
    click A_Signaling "https://github.com/saddysk/videopie/blob/main/peerA/sender.js"
    click B_UI "https://github.com/saddysk/videopie/blob/main/peerB/peerB.html"
    click B_Signaling "https://github.com/saddysk/videopie/blob/main/peerB/receiver.js"
    click SS_Node "https://github.com/saddysk/videopie/blob/main/server.js"
    click C_UI "https://github.com/saddysk/videopie/blob/main/Canvas/index.html"
    click C_Logic "https://github.com/saddysk/videopie/blob/main/Canvas/canvas.js"
    click C_Style "https://github.com/saddysk/videopie/blob/main/Canvas/style.css"
    click Landing "https://github.com/saddysk/videopie/blob/main/index.html"
    click LandingCSS "https://github.com/saddysk/videopie/blob/main/style.css"

    classDef ui fill:#f3e5f5,stroke:#9c27b0;
    classDef signaling fill:#bbdefb,stroke:#1976d2;
    classDef media fill:#c8e6c9,stroke:#388e3c;
    classDef data fill:#ffe0b2,stroke:#fb8c00,stroke-dasharray: 2 2;
    classDef server fill:#d7ccc8,stroke:#5d4037;
    classDef canvas fill:#fff9c4,stroke:#fbc02d;
    classDef cloud fill:#b3e5fc,stroke:#0288d1,stroke-dasharray: 5 5;
```
