# shyamalp16/cloudgaming architecture

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

- Interactive diagram: https://gitdiagram.com/shyamalp16/cloudgaming
- Repository: https://github.com/shyamalp16/cloudgaming

## Overview

##### Main Components
- Host Module (Screen Capture and Streaming):
- Contains the core capture logic (files like main.cpp, FrameCaptureThread.cpp, Encoder.cpp).
- Utilizes Windows.Graphics.Capture and Direct3D 11 (as indicated by names like D3DHelpers).
- Handles encoding, frame capturing, and likely WebSocket-based signaling (see Websocket.cpp).
- Implements observers for SDP offer/answer negotiation (MyCreateSdpObserver, MySetRemoteObserver).

- Client Module:
- Found in the Client directory and includes files such as PeerClient.js and an HTML server (index.html).
- Likely responsible for receiving the streaming data and rendering the captured video.
- Uses JavaScript and node’s package management (package.json, package-lock.json) to facilitate client operations.

- Server Module (Matchmaking/Signaling Server):
- Located in the Server directory, containing PureSignalingServer.js and SignalingServer.js.
- Provides the lightweight matchmaking service needed to connect hosts and clients via a P2P overlay.

- Additional/Supporting Components:
- gortc_main in Go may be an alternative or complementary signaling/connection module.
- Build configuration files (DisplayCaptureProject.sln, .vcxproj files) indicate the Host is built using Visual Studio.
- Auxiliary scripts (create_def.py, test.bat) could be used for definition generation or automation tasks.

##### Detail Relationships & Interactions
- Data Flow:
- The Host module captures the screen using Direct3D 11 and Windows.Graphics.Capture, encodes the frames (Encoder.cpp), and then streams the data.
- The streaming mechanism employs a P2P network, where signaling messages allow for negotiation via SDP methods (MyCreateSdpObserver and MySetRemoteObserver).
- The Server (SignalingServer) acts as the intermediary for connection setup, receiving and redistributing signaling information between Host and Client.
- The Client module (including the HTML server and JavaScript code) sets up a peer connection with the Host after matchmaking, enabling display of the captured gameplay.

- Architectural Patterns:
- Modular architecture: separation of concerns into distinct modules (capture/streaming, client display, and signaling).
- Use of client–server patterns for match-making.
- Utilization of observer patterns for SDP negotiation.
- Clear separation between presentation (Client), processing (Host), and coordination (Server).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host Module
    subgraph "Host - Capture & Stream"
        H_main["main.cpp"]:::host
        H_FCT["FrameCaptureThread.cpp"]:::host
        H_Enc["Encoder.cpp"]:::host
        H_SdpObs["MyCreateSdpObserver.cpp"]:::host
        H_SetObs["MySetRemoteObserver.cpp"]:::host
        H_WS["Websocket.cpp"]:::host
        H_D3D["Direct3D & Win.Graphics.Capture"]:::host
    end

    %% Client Module
    subgraph "Client - Peer Viewer"
        C_PC["PeerClient.js"]:::client
        C_HTML["index.html"]:::client
        C_Pkg["package.json (Client)"]:::client
        C_PkgLock["package-lock.json (Client)"]:::client
    end

    %% Server Module
    subgraph "Signaling Server - Matchmaking"
        S_PS["PureSignalingServer.js"]:::server
        S_Sig["SignalingServer.js"]:::server
        S_Pkg["package.json (Server)"]:::server
        S_PkgLock["package-lock.json (Server)"]:::server
    end

    %% Alternative Signaling/Connection Component (Go)
    G_Main["main.go (gortc_main)"]:::go

    %% Build Configuration
    subgraph "Build Configuration"
        B_Sln["DisplayCaptureProject.sln"]:::build
        B_Vcxproj["DisplayCaptureProject.vcxproj"]:::build
        B_Filters["DisplayCaptureProject.vcxproj.filters"]:::build
    end

    %% Auxiliary Scripts
    subgraph "Auxiliary Scripts"
        A_Py["create_def.py"]:::aux
        A_Bat["test.bat"]:::aux
    end

    %% Interactions and Data Flow
    H_main -->|"ScreenCaptureStream"| C_PC
    H_main -->|"SDPNegotiation"| S_PS
    C_PC -->|"SDPNegotiation"| S_PS
    G_Main -->|"AltSignaling"| S_PS
    B_Sln ---|"BuildConfig"| H_main
    A_Py ---|"Automation"| B_Sln
    A_Bat ---|"Automation"| B_Sln

    %% Click Events for Host Module
    click H_main "https://github.com/shyamalp16/cloudgaming/blob/master/Host/main.cpp"
    click H_FCT "https://github.com/shyamalp16/cloudgaming/blob/master/Host/FrameCaptureThread.cpp"
    click H_Enc "https://github.com/shyamalp16/cloudgaming/blob/master/Host/Encoder.cpp"
    click H_SdpObs "https://github.com/shyamalp16/cloudgaming/blob/master/Host/MyCreateSdpObserver.cpp"
    click H_SetObs "https://github.com/shyamalp16/cloudgaming/blob/master/Host/MySetRemoteObserver.cpp"
    click H_WS "https://github.com/shyamalp16/cloudgaming/blob/master/Host/Websocket.cpp"

    %% Click Events for Client Module
    click C_PC "https://github.com/shyamalp16/cloudgaming/blob/master/Client/PeerClient.js"
    click C_HTML "https://github.com/shyamalp16/cloudgaming/blob/master/Client/html-server/index.html"
    click C_Pkg "https://github.com/shyamalp16/cloudgaming/blob/master/Client/package.json"
    click C_PkgLock "https://github.com/shyamalp16/cloudgaming/blob/master/Client/package-lock.json"

    %% Click Events for Server Module
    click S_PS "https://github.com/shyamalp16/cloudgaming/blob/master/Server/PureSignalingServer.js"
    click S_Sig "https://github.com/shyamalp16/cloudgaming/blob/master/Server/SignalingServer.js"
    click S_Pkg "https://github.com/shyamalp16/cloudgaming/blob/master/Server/package.json"
    click S_PkgLock "https://github.com/shyamalp16/cloudgaming/blob/master/Server/package-lock.json"

    %% Click Event for Alternative Signaling/Connection Component
    click G_Main "https://github.com/shyamalp16/cloudgaming/blob/master/gortc_main/main.go"

    %% Click Events for Build Configuration
    click B_Sln "https://github.com/shyamalp16/cloudgaming/blob/master/DisplayCaptureProject.sln"
    click B_Vcxproj "https://github.com/shyamalp16/cloudgaming/blob/master/DisplayCaptureProject.vcxproj"
    click B_Filters "https://github.com/shyamalp16/cloudgaming/blob/master/DisplayCaptureProject.vcxproj.filters"

    %% Click Events for Auxiliary Scripts
    click A_Py "https://github.com/shyamalp16/cloudgaming/blob/master/create_def.py"
    click A_Bat "https://github.com/shyamalp16/cloudgaming/blob/master/test.bat"

    %% Styles
    classDef host fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef client fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef server fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef go fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef build fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef aux fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
```
