# hkirat/omegle architecture

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

- Interactive diagram: https://gitdiagram.com/hkirat/omegle
- Repository: https://github.com/hkirat/omegle

## Overview

##### Main Components

a. Client-Side (Frontend):
- React Components (Landing, Room)
- WebRTC Peer Connection Handler
- Media Stream Handler
- User Interface Layer

b. Server-Side (Backend):
- Room Manager
- User Manager
- WebSocket Connection Handler

c. External Services/APIs:
- Browser's WebRTC API

##### Connection Flows

- Initial HTTP connection for web assets
- WebSocket connection for signaling
- P2P WebRTC connection between peers
- STUN/TURN server connections for NAT traversal

##### Detailed Component Breakdown

Frontend Section:
- React component hierarchy
- WebRTC connection handling
- State management
- Media stream handling

Backend Section:
- Room management system
- User session handling
- Demonstrate WebSocket communication paths

##### Key Interactions to Highlight

a. Connection Establishment:
- Initial user connection
- Room creation/joining flow
- Peer discovery process
- ICE candidate exchange
- Media stream establishment

b. Data Flow:
- Signaling messages
- Peer-to-peer media streams
- Room state updates
- User events

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External["External Services"]
        STUN["STUN/TURN Servers"]:::external
    end

    subgraph Client1["Web Client 1"]
        direction TB
        UI1["User Interface Layer"]:::frontend
        RC1["React Components"]:::frontend
        WRH1["WebRTC Handler"]:::frontend
        MSH1["Media Stream Handler"]:::frontend
        
        UI1 --> RC1
        RC1 --> WRH1
        RC1 --> MSH1
    end

    subgraph Client2["Web Client 2"]
        direction TB
        UI2["User Interface Layer"]:::frontend
        RC2["React Components"]:::frontend
        WRH2["WebRTC Handler"]:::frontend
        MSH2["Media Stream Handler"]:::frontend
        
        UI2 --> RC2
        RC2 --> WRH2
        RC2 --> MSH2
    end

    subgraph Server["Signaling Server"]
        direction TB
        WS["WebSocket Handler"]:::backend
        RM["Room Manager"]:::backend
        UM["User Manager"]:::backend
        
        WS --> RM
        WS --> UM
    end

    %% Connections
    Client1 <--> |WebSocket| Server
    Client2 <--> |WebSocket| Server
    Client1 <--> |WebRTC P2P| Client2
    Client1 <--> |NAT Traversal| STUN
    Client2 <--> |NAT Traversal| STUN

    %% Component Mappings
    click RC1 "https://github.com/hkirat/omegle/blob/master/frontend/src/components/Landing.tsx"
    click RC2 "https://github.com/hkirat/omegle/blob/master/frontend/src/components/Room.tsx"
    click UI1 "https://github.com/hkirat/omegle/blob/master/frontend/src/App.tsx"
    click UI2 "https://github.com/hkirat/omegle/blob/master/frontend/src/main.tsx"
    click RM "https://github.com/hkirat/omegle/blob/master/backend/src/managers/RoomManager.ts"
    click UM "https://github.com/hkirat/omegle/blob/master/backend/src/managers/UserManger.ts"
    click WS "https://github.com/hkirat/omegle/blob/master/backend/src/index.ts"

    %% Styles
    classDef frontend fill:#3498db,color:white
    classDef backend fill:#2ecc71,color:white
    classDef external fill:#e67e22,color:white
    
    %% Legend
    subgraph Legend
        L1[Frontend Component]:::frontend
        L2[Backend Component]:::backend
        L3[External Service]:::external
    end
```
