# linhkhanhhoang/youtube-streaming-party architecture

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

- Interactive diagram: https://gitdiagram.com/linhkhanhhoang/youtube-streaming-party
- Repository: https://github.com/linhkhanhhoang/youtube-streaming-party

## Overview

##### Project Type and Purpose
- This is a full-stack real-time web application (“youtube-streaming-party”) that lets a host and multiple participants watch/sync YouTube videos together with chat.
- Frontend: React + Redux app served as static files.
- Backend: Python async WebSocket server powered by aiohttp + python-socketio.
- Real-time communication: Socket.IO over WebSockets.

##### File Structure
- Top-level “client/streaming-client” contains the React code:
- public/: static HTML/CSS/manifest/robots
- src/: React components (App.js, Home.js, Room.js), Redux store (store.js), socket wrapper (socket.js)
- Top-level “server/server.py”: Single Python process handling Socket.IO events and room state.
- No persistent database—state (rooms, user lists, video position) is in-memory.

##### Extract Additional Insights from README
- Users join a room; host controls playback (play/pause/seek).
- Clients sync playback state via WebSocket events.
- Chat and system events flow over the same socket channel.
- Redux is used on the client; customized middleware intercepts actions and emits socket events.

##### Main Components & Interactions
a. Components
- Browser Client
– React UI (Home screen, Room screen)
– Redux Store & Middleware
– Socket.IO-client module
– YouTube IFrame Player API
- Python Socket.IO Server
– aiohttp HTTP server (optional for serving client or health checks)
– python-socketio server for WebSocket event routing
– In-memory Room Manager (tracks hosts, participants, video state)
- External Service
– YouTube Data / IFrame API (for embedding and controlling video)
b. Relationships & Data Flows
1. Client HTTP GET → Server (or static host) → browser downloads index.html + JS/CSS
2. Browser initializes React app → Redux store setup → socket.js connects to Server via WebSocket
3. User action dispatches Redux action → Middleware translates certain actions into socket.emit events to server
4. Server receives event (e.g., “play”, “pause”, “chat message”) → updates in-memory state → broadcasts via socket.emit to all clients in same room
5. Clients receive socket events → dispatch Redux actions to update local state and UI (e.g., seek YouTube iframe, append chat message)
6. React components call YouTube IFrame API methods under the hood to control playback
c. Architectural Patterns & Principles
- Single-page application (SPA) on the client
- Flux/Redux uni-directional data flow
- WebSocket-driven pub/sub for real-time sync (Socket.IO abstraction)
- In-memory room management (no external database)
- Separation of concerns: UI layer, state management layer, transport layer
d. Key Technologies
- React, Redux, react-redux, @reduxjs/toolkit
- socket.io-client, redux-socket.io (middleware)
- Python 3, aiohttp, python-socketio

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Browser Client"
        subgraph "UI Components"
            App["App.js"]:::client
            Home["Home.js"]:::client
            Room["Room.js"]:::client
        end
        Redux["Redux Store & Middleware\n(store.js)"]:::client
        SocketIOClient["Socket.IO Client\n(socket.js)"]:::client
        StaticAssets["Static Asset Delivery\n(public)"]:::client
        YouTubeAPI["YouTube IFrame Player API"]:::external
    end

    subgraph "Server"
        HTTPServer["aiohttp HTTP Server"]:::server
        SocketIOServer["python-socketio Server"]:::server
        RoomManager["In-Memory Room Manager"]:::server
    end

    StaticAssets -->|"HTTP GET"| App
    StaticAssets -->|"HTTP GET"| Home
    StaticAssets -->|"HTTP GET"| Room

    App -->|"dispatch action"| Redux
    Home -->|"dispatch action"| Redux
    Room -->|"dispatch action"| Redux

    Redux -->|"emit events"| SocketIOClient

    SocketIOClient -->|"WebSocket handshake"| SocketIOServer
    SocketIOClient -->|"socket.emit (play/pause/chat)"| SocketIOServer

    SocketIOServer -->|"update state"| RoomManager
    RoomManager -->|"broadcast events"| SocketIOServer

    SocketIOServer -->|"socket.emit (play/pause/chat)"| SocketIOClient
    SocketIOClient -->|"dispatch event"| Redux
    Redux -->|"update UI"| Room

    Room -->|"call play/pause/seek"| YouTubeAPI

    %% Click Events
    click App "https://github.com/linhkhanhhoang/youtube-streaming-party/blob/main/client/streaming-client/src/App.js"
    click Home "https://github.com/linhkhanhhoang/youtube-streaming-party/blob/main/client/streaming-client/src/Home.js"
    click Room "https://github.com/linhkhanhhoang/youtube-streaming-party/blob/main/client/streaming-client/src/Room.js"
    click Redux "https://github.com/linhkhanhhoang/youtube-streaming-party/blob/main/client/streaming-client/src/store.js"
    click SocketIOClient "https://github.com/linhkhanhhoang/youtube-streaming-party/blob/main/client/streaming-client/src/socket.js"
    click StaticAssets "https://github.com/linhkhanhhoang/youtube-streaming-party/tree/main/client/streaming-client/public"
    click HTTPServer "https://github.com/linhkhanhhoang/youtube-streaming-party/blob/main/server/server.py"
    click SocketIOServer "https://github.com/linhkhanhhoang/youtube-streaming-party/blob/main/server/server.py"
    click RoomManager "https://github.com/linhkhanhhoang/youtube-streaming-party/blob/main/server/server.py"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1B4F72,color:#1B2631;
    classDef server fill:#A9DFBF,stroke:#145A32,color:#0B5345;
    classDef external fill:#F9E79F,stroke:#7D6608,color:#7D6608;
```
