# mangtrungzos/realtime-chat-app architecture

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

- Interactive diagram: https://gitdiagram.com/mangtrungzos/realtime-chat-app
- Repository: https://github.com/mangtrungzos/realtime-chat-app

## Overview

##### Project type and purpose
- This is a full-stack, real-time video-and-text chat application.
- The `client` folder is a React+TypeScript SPA that provides chat UI, video streams, and room-management.
- The `server` folder is a Node.js/TypeScript Socket.IO service for signaling, room lifecycle, and chat message relaying.
- The `peerjs` folder is a standalone PeerJS signaling server (for WebRTC peer discovery).

##### File structure
- Top level: three peers of responsibility
- client/ (React frontend)
- server/ (Socket.IO backend)
- peerjs/ (PeerJS signaling server)
- The client uses contexts (ChatContext, RoomContext, UserContext), reducers, and Cypress for e2e tests.
- The server has a minimal folder: `src/index.ts` and `src/room/index.ts` for room handling.
- The PeerJS folder contains a Dockerfile to host the PeerJS server in its own container.
- Deployment descriptors: `server/fly.toml` and Dockerfiles in both server and peerjs.

##### README
- Tech stack: React, TypeScript, WebSocket (Socket.IO), Node.js, Tailwind CSS, PeerJS.
- Deployed front end on Vercel; server likely on Fly.io; PeerJS via its own container.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Browser SPA
    subgraph "Browser / React SPA"
        direction TB
        ClientApp["React Frontend"]:::frontend
        click ClientApp "https://github.com/mangtrungzos/realtime-chat-app/tree/master/client/"
        Index["Index.tsx"]:::frontend
        click Index "https://github.com/mangtrungzos/realtime-chat-app/blob/master/client/src/index.tsx"
        App["App.tsx"]:::frontend
        click App "https://github.com/mangtrungzos/realtime-chat-app/blob/master/client/src/App.tsx"
        subgraph Components
            direction TB
            ChatUI["Chat.tsx"]:::frontend
            click ChatUI "https://github.com/mangtrungzos/realtime-chat-app/blob/master/client/src/components/chat/Chat.tsx"
            VideoPlayer["VideoPlayer.tsx"]:::frontend
            click VideoPlayer "https://github.com/mangtrungzos/realtime-chat-app/blob/master/client/src/components/VideoPlayer.tsx"
            Join["Join.tsx"]:::frontend
            click Join "https://github.com/mangtrungzos/realtime-chat-app/blob/master/client/src/components/Join.tsx"
            ShareButton["ShareScreenButton.tsx"]:::frontend
            click ShareButton "https://github.com/mangtrungzos/realtime-chat-app/blob/master/client/src/components/ShareScreenButton.tsx"
        end
        subgraph Contexts
            direction TB
            ChatCtx["ChatContext.tsx"]:::frontend
            click ChatCtx "https://github.com/mangtrungzos/realtime-chat-app/blob/master/client/src/context/ChatContext.tsx"
            RoomCtx["RoomContext.tsx"]:::frontend
            click RoomCtx "https://github.com/mangtrungzos/realtime-chat-app/blob/master/client/src/context/RoomContext.tsx"
            UserCtx["UserContext.tsx"]:::frontend
            click UserCtx "https://github.com/mangtrungzos/realtime-chat-app/blob/master/client/src/context/UserContext.tsx"
        end
        subgraph Reducers
            direction TB
            ChatRed["chatReducer.ts"]:::frontend
            click ChatRed "https://github.com/mangtrungzos/realtime-chat-app/blob/master/client/src/reducers/chatReducer.ts"
            PeerRed["peerReducer.ts"]:::frontend
            click PeerRed "https://github.com/mangtrungzos/realtime-chat-app/blob/master/client/src/reducers/peerReducer.ts"
        end
        subgraph "Public Assets"
            direction TB
            HTML["index.html"]:::frontend
            click HTML "https://github.com/mangtrungzos/realtime-chat-app/blob/master/client/public/index.html"
        end
        subgraph "E2E Tests"
            direction TB
            Cypress["cypress/e2e"]:::frontend
            click Cypress "https://github.com/mangtrungzos/realtime-chat-app/tree/master/client/cypress/e2e"
        end
    end

    %% Static Hosting
    Static["Vercel CDN"]:::infra

    %% Backend Services
    subgraph "Socket.IO Server"
        direction TB
        SocketServer["Signaling & Chat Server"]:::backend
        click SocketServer "https://github.com/mangtrungzos/realtime-chat-app/tree/master/server/"
        ServerIndex["index.ts"]:::backend
        click ServerIndex "https://github.com/mangtrungzos/realtime-chat-app/blob/master/server/src/index.ts"
        RoomMod["room/index.ts"]:::backend
        click RoomMod "https://github.com/mangtrungzos/realtime-chat-app/blob/master/server/src/room/index.ts"
        FlyConfig["fly.toml"]:::backend
        click FlyConfig "https://github.com/mangtrungzos/realtime-chat-app/blob/master/server/fly.toml"
    end

    subgraph "PeerJS Signaling Server"
        direction TB
        PeerJSApp["PeerJS Server"]:::backend
        click PeerJSApp "https://github.com/mangtrungzos/realtime-chat-app/tree/master/peerjs/"
        PeerJSIndex["index.ts"]:::backend
        click PeerJSIndex "https://github.com/mangtrungzos/realtime-chat-app/blob/master/peerjs/src/index.ts"
        PeerJSDocker["Dockerfile"]:::backend
        click PeerJSDocker "https://github.com/mangtrungzos/realtime-chat-app/tree/master/peerjs/Dockerfile"
    end

    %% P2P Media Channel
    Media["P2P Media Channel"]:::media

    %% Connections
    Static -->|"HTTP GET"| ClientApp
    ClientApp -->|"WebSocket (Chat & Signaling)"| SocketServer
    ClientApp -->|"PeerJS Signaling"| PeerJSApp
    ClientApp -.->|"Media Stream (WebRTC)"| Media
    Media -.->|"Media Stream (WebRTC)"| ClientApp

    classDef frontend fill:#D0E8FF,stroke:#333
    classDef backend fill:#D0FFD0,stroke:#333
    classDef infra fill:#F0F0F0,stroke:#333
    classDef media stroke-dasharray:5 5,stroke:#999,fill:#FFF
```
