# sunzsh/internal-chat architecture

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

- Interactive diagram: https://gitdiagram.com/sunzsh/internal-chat
- Repository: https://github.com/sunzsh/internal-chat

## Overview

##### Main Components

a) Client-Side Components (Browser):
- Web Interface (HTML/CSS)
- WebRTC Peer Connection Manager
- User Management Module
- File Transfer Module

b) Server Components:
- WebSocket Signaling Server
- Online Users Registry

c) Network Layer:
- WebRTC P2P connections (between clients)
- WebSocket connection (client-server)

##### Component Relationships

- Signaling traffic (yellow)
- P2P data transfer (blue)
- User list updates (green)

##### Key Elements to Highlight

a) Client Architecture:
- Relationship between index.html, index.js, and xchatuser.js
- WebRTC connection management
- File/text transfer handlers

b) Server Architecture:
- WebSocket server (index.js)
- User data management (data.js)
- Signaling service

##### Flow Descriptions

Numbered annotations showing:

##### Technical Details

- Technologies used:
- WebRTC
- WebSocket
- Node.js
- Nginx (as reverse proxy)
- Protocol indicators:
- WSS/WS
- HTTPS/HTTP
- WebRTC protocols

##### Deployment Context

A section showing:
- Nginx reverse proxy configuration
- Local network boundary
- Optional HTTPS termination

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Browser
        WI[Web Interface]
        WRTC[WebRTC Peer Connection Manager]
        UM[User Management Module]
        FT[File Transfer Module]
        
        WI --> WRTC
        WI --> UM
        WI --> FT
        WRTC --> FT
        UM --> WRTC
    end

    subgraph Server
        WSS[WebSocket Signaling Server]
        URS[Online Users Registry]
        
        WSS --> URS
    end

    subgraph "Local Network"
        Browser1[Browser Instance 1]
        Browser2[Browser Instance 2]
        
        Browser1 -.-|WebRTC P2P| Browser2
    end

    subgraph "Reverse Proxy"
        RP[Nginx Proxy]
    end

    Browser -.->|WebSocket| WSS
    RP -->|Forward| WSS

    %% Click events for component mapping
    click WI "https://github.com/sunzsh/internal-chat/blob/master/www/index.html"
    click WRTC "https://github.com/sunzsh/internal-chat/blob/master/www/index.js"
    click UM "https://github.com/sunzsh/internal-chat/blob/master/www/xchatuser.js"
    click FT "https://github.com/sunzsh/internal-chat/blob/master/www/index.js"
    click WSS "https://github.com/sunzsh/internal-chat/blob/master/server/index.js"
    click URS "https://github.com/sunzsh/internal-chat/blob/master/server/data.js"
    click RP "https://github.com/sunzsh/internal-chat/blob/master/nginxvhost.conf"

    %% Styling
    classDef browser fill:#e1f5fe,stroke:#01579b
    classDef server fill:#e8f5e9,stroke:#1b5e20
    classDef network fill:#fff3e0,stroke:#ff6f00
    classDef proxy fill:#f3e5f5,stroke:#4a148c

    class WI,WRTC,UM,FT browser
    class WSS,URS server
    class Browser1,Browser2 network
    class RP proxy

    %% Legend
    subgraph Legend
        L1[Client Components]:::browser
        L2[Server Components]:::server
        L3[Network Components]:::network
        L4[Proxy Components]:::proxy
        L5["-.-"] --> L6["WebSocket/P2P"]
        L7["-->"] --> L8["Direct Connection"]
    end
```
