# aniket04bit/omegleclgonly architecture

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

- Interactive diagram: https://gitdiagram.com/aniket04bit/omegleclgonly
- Repository: https://github.com/aniket04bit/omegleclgonly

## Overview

##### Project Type and Purpose
- This is a full-stack web application that replicates Omegle’s functionality using WebRTC for peer-to-peer connections.
- The frontend is a React + Vite TypeScript app that handles UI and WebRTC peer setup.
- The backend is a Node.js/TypeScript signaling server that matches users into rooms and mediates WebRTC offer/answer and ICE candidate exchange.

##### Main Components
a. Frontend (Browser)
- App shell (index.html, main.tsx, App.tsx)
- Landing component (user enters “start chat”)
- Room component (WebRTC connection logic, media streams)
b. Backend (Signaling Server)
- HTTP/WebSocket endpoint (src/index.ts)
- RoomManager (creates and tracks active rooms)
- UserManager (tracks connected users, socket sessions)
c. External Services
- STUN/TURN servers for NAT traversal (public ICE servers)
- Optional: Hosting/CDN for frontend assets
d. Peer-to-Peer Data/Media Channel
- Direct browser-to-browser media and data channels after signaling

##### Relationships and Data Flows
1. User opens browser → loads React app from hosting/CDN.
2. React app establishes WebSocket (or HTTP fallback) connection to signaling server.
3. On “Start Chat,” frontend emits a “join” event to backend.
4. Backend UserManager places the socket in RoomManager. If a pair is ready, backend signals “ready” to both clients.
5. Frontend A sends WebRTC offer → backend forwards to frontend B.
6. Frontend B sends WebRTC answer → backend forwards to A.
7. Both clients exchange ICE candidates (via backend) until a direct P2P channel is established.
8. Media and/or data flow directly between browsers (no further backend involvement).

##### Architectural Patterns and Design Principles
- Manager Pattern on the backend: RoomManager & UserManager isolate room/user logic.
- Separation of concerns: Signaling vs. media transport.
- Event-driven communication via WebSockets.
- Stateless media path: after signaling, media is direct P2P.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Container
    subgraph "Frontend (Browser)" 
        direction TB
        subgraph "App Shell"
            direction TB
            IndexHTML["index.html"] 
            MainTSX["main.tsx"] 
            AppTSX["App.tsx"] 
        end
        Landing["Landing Component"] 
        subgraph "Room Component"
            direction TB
            RoomA["Room (Client A)"] 
            RoomB["Room (Client B)"] 
        end
        subgraph "Styling & Assets"
            direction TB
            AppCSS["App.css"]
            IndexCSS["index.css"]
            Assets["assets/"]
        end
    end

    %% Backend Container
    subgraph "Backend (Signaling Server)"
        direction TB
        API["HTTP/WebSocket API"]
        subgraph "Managers"
            direction TB
            RoomManager["RoomManager"]
            UserManager["UserManager"]
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        CDN["CDN / Hosting"]
        STUNTURN["STUN/TURN Servers"]
    end

    %% Flows
    CDN -->|"Load App"| IndexHTML
    IndexHTML -->|"serves React App"| Landing
    Landing -->|"joinRoom"| API
    API -->|"register user"| UserManager
    UserManager -->|"assign to room"| RoomManager
    RoomManager -->|"ready"| API
    API -->|"ready"| RoomA
    API -->|"forward offer/ice"| RoomB
    RoomA -->|"offer/ice| API
    RoomB -->|"answer/ice| API
    RoomA <-->|"media-stream"| RoomB
    RoomA -->|"ice-candidate"| API
    RoomB -->|"ice-candidate"| API
    API -->|"forward ice-candidate"| RoomA

    %% Click Events
    click IndexHTML "https://github.com/aniket04bit/omegleclgonly/blob/master/frontend/index.html"
    click MainTSX "https://github.com/aniket04bit/omegleclgonly/blob/master/frontend/src/main.tsx"
    click AppTSX "https://github.com/aniket04bit/omegleclgonly/blob/master/frontend/src/App.tsx"
    click Landing "https://github.com/aniket04bit/omegleclgonly/blob/master/frontend/src/components/Landing.tsx"
    click RoomA "https://github.com/aniket04bit/omegleclgonly/blob/master/frontend/src/components/Room.tsx"
    click RoomB "https://github.com/aniket04bit/omegleclgonly/blob/master/frontend/src/components/Room.tsx"
    click AppCSS "https://github.com/aniket04bit/omegleclgonly/blob/master/frontend/src/App.css"
    click IndexCSS "https://github.com/aniket04bit/omegleclgonly/blob/master/frontend/src/index.css"
    click Assets "https://github.com/aniket04bit/omegleclgonly/tree/master/frontend/src/assets"
    click API "https://github.com/aniket04bit/omegleclgonly/blob/master/backend/src/index.ts"
    click RoomManager "https://github.com/aniket04bit/omegleclgonly/blob/master/backend/src/managers/RoomManager.ts"
    click UserManager "https://github.com/aniket04bit/omegleclgonly/blob/master/backend/src/managers/UserManger.ts"
    click BackPkg "https://github.com/aniket04bit/omegleclgonly/blob/master/backend/package.json"
    click BackTSConfig "https://github.com/aniket04bit/omegleclgonly/blob/master/backend/tsconfig.json"
    click FrontPkg "https://github.com/aniket04bit/omegleclgonly/blob/master/frontend/package.json"
    click FrontTSConfig "https://github.com/aniket04bit/omegleclgonly/blob/master/frontend/tsconfig.json"
    click ViteConfig "https://github.com/aniket04bit/omegleclgonly/blob/master/frontend/vite.config.ts"

    %% Styles
    classDef frontend fill:#DDEEFF,stroke:#009,stroke-width:1px
    classDef backend fill:#DDFFDD,stroke:#090,stroke-width:1px
    classDef external fill:#FFE5CC,stroke:#F60,stroke-width:1px

    class IndexHTML,MainTSX,AppTSX,Landing,RoomA,RoomB,AppCSS,IndexCSS,Assets frontend
    class API,RoomManager,UserManager backend
    class CDN,STUNTURN external
```
