# itstaranarora/video-chat-v1 architecture

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

- Interactive diagram: https://gitdiagram.com/itstaranarora/video-chat-v1
- Repository: https://github.com/itstaranarora/video-chat-v1

## Overview

##### Main components
- Client (Browser):
- Web UI delivered from static assets in the public directory (script.js and style.css).
- Dynamic HTML rendered using room.ejs from the views folder.
- Server:
- NodeJS application initiated from server.js.
- Socket.io integration on the server for handling real-time communication/signaling.
- PeerJS integration on the server to help with WebRTC connection management.
- External/Infrastructure:
- The demo is hosted on Heroku, which serves the NodeJS app.
- (Optional) Future front-end upgrade possibility with React, as mentioned in the ToDo list.

##### Relationships and interactions
- The Browser (client) loads the UI (HTML, CSS, and client-side JavaScript) from the public and views directories.
- The client establishes a connection with the NodeJS server over WebSocket using Socket.io.
- Signaling messages for initiating peer-to-peer communication are exchanged via Socket.io.
- Once the signaling is complete, PeerJS facilitates direct WebRTC connections between clients for video chatting.
- The server manages room creation and participant connections (as inferred by the room.ejs view).

##### Architectural patterns and design principles
- Separation of Concerns: The client-side code (UI and video functionality) is neatly separated from the server-side logic.
- Real-Time Communication: Socket.io is used to handle real-time bidirectional communication.
- Peer-to-Peer Communication: WebRTC (using PeerJS) handles the actual video data transfer directly between clients.
- Template Rendering: Use of ejs (room.ejs) for dynamic content generation.

##### Relevant technologies
- NodeJS (runtime and server logic)
- Socket.io (real-time communication and signaling)
- PeerJS (simplified WebRTC integration)
- Express (likely used, as inferred by the typical project structure, although not explicitly named)
- EJS (template engine for rendering rooms)
- Static assets (plain HTML/CSS/JS served from the public directory)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Infrastructure
    Heroku["Heroku Deployment"]:::external

    %% Server
    Server["NodeJS Server (Socket.io & PeerJS)"]:::server

    %% Client A Subgraph
    subgraph "Client A (Browser UI)"
        SA_A["Static Assets"]:::client
        HTML_A["Dynamic HTML"]:::client
    end

    %% Client B Subgraph
    subgraph "Client B (Browser UI)"
        SA_B["Static Assets"]:::client
        HTML_B["Dynamic HTML"]:::client
    end

    %% Deployment Relationship
    Heroku -->|"HostedOn"| Server

    %% HTTP Delivery from Server to Clients
    Server -->|"ServesStatic"| SA_A
    Server -->|"ServesDynamic"| HTML_A
    Server -->|"ServesStatic"| SA_B
    Server -->|"ServesDynamic"| HTML_B

    %% Socket.io Signaling Connections (Client to Server)
    HTML_A -->|"Socket.io"| Server
    HTML_B -->|"Socket.io"| Server

    %% Peer-to-Peer connection between Clients using WebRTC via PeerJS
    HTML_A ---|"WebRTC(PeerJS)"| HTML_B

    %% Styles
    classDef client fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef server fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;

    %% Click Events
    click SA_A "https://github.com/itstaranarora/video-chat-v1/tree/master/public/"
    click SA_B "https://github.com/itstaranarora/video-chat-v1/tree/master/public/"
    click HTML_A "https://github.com/itstaranarora/video-chat-v1/blob/master/views/room.ejs"
    click HTML_B "https://github.com/itstaranarora/video-chat-v1/blob/master/views/room.ejs"
    click Server "https://github.com/itstaranarora/video-chat-v1/blob/master/server.js"
```
