# giongto35/cloud-game architecture

> Architecture diagram of the GitHub repository giongto35/cloud-game, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/giongto35/cloud-game
- Repository: https://github.com/giongto35/cloud-game

## Overview

CloudRetro runs retro games on remote worker processes and streams gameplay to browser players. The main flow is browser gameplay through coordinator-managed user sessions to a worker, where a game is selected, emulated, encoded, and delivered over WebRTC; coordinator handlers also relay controls such as save, load, reset, and recording. The README documents collaborative and online multiplayer, scaling, and cloud saves. Some subsystem paths and relationships are based on the README or import references in the SOURCE INDEX; unsampled implementation links are omitted where their caller is unclear.

Main entry points: [`pkg/worker/coordinatorhandlers.go`](https://github.com/giongto35/cloud-game/blob/master/pkg/worker/coordinatorhandlers.go) (Game handlers), [`web/js/app.js`](https://github.com/giongto35/cloud-game/blob/master/web/js/app.js) (Browser app), [`pkg/worker/worker.go`](https://github.com/giongto35/cloud-game/blob/master/pkg/worker/worker.go) (Worker service), [`pkg/coordinator/userhandlers.go`](https://github.com/giongto35/cloud-game/blob/master/pkg/coordinator/userhandlers.go) (User handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_webapp["Browser app<br/>[app.js]"]
  node_webinput["Game input"]
  node_webstream["Browser streaming<br/>[webrtc.js]"]
end

subgraph group_coord["Coordination"]
  node_coordinator["Coordinator<br/>[coordinator.go]"]
  node_userhandlers["User handlers<br/>[userhandlers.go]"]
  node_workerregistry["Worker registry<br/>[worker.go]"]
  node_api["Protocol types<br/>[api.go]"]
end

subgraph group_runtime["Worker runtime"]
  node_worker["Worker service<br/>[worker.go]"]
  node_workerhandlers["Game handlers"]
  node_gamelibrary["Game library<br/>[library.go]"]
  node_emulator["Libretro emulator"]
  node_room["Game rooms<br/>[room.go]"]
end

subgraph group_stream["Media transport"]
  node_media["Media encoder<br/>[gstreamer.go]"]
  node_webrtc["WebRTC transport<br/>[webrtc.go]"]
end

subgraph group_state["Storage and services"]
  node_cloudstore[("Cloud storage")]
  node_savestate["Save-state storage<br/>[storage.go]"]
  node_recorder["Game recording<br/>[recorder.go]"]
  node_monitoring["Monitoring<br/>[monitoring.go]"]
end

node_player(("Player"))
node_gamesource[("Game files")]

node_player -->|"plays in"| node_webapp
node_webapp -->|"collects input"| node_webinput
node_webapp -->|"streams gameplay"| node_webstream
node_webapp -.->|"requests gameplay"| node_coordinator
node_coordinator -.->|"routes users"| node_userhandlers
node_userhandlers -->|"dispatches game actions"| node_workerregistry
node_userhandlers -->|"uses requests"| node_api
node_worker -->|"handles coordinator requests"| node_workerhandlers
node_workerhandlers -->|"selects games"| node_gamelibrary
node_gamesource -->|"scans games"| node_gamelibrary
node_workerhandlers -->|"starts game"| node_emulator
node_workerhandlers -->|"creates room"| node_room
node_workerhandlers -->|"initializes encoding"| node_media
node_workerhandlers -->|"creates peer"| node_webrtc
node_webstream -.->|"exchanges media"| node_webrtc
node_workerhandlers -->|"enables cloud saves"| node_cloudstore
node_emulator -.->|"loads and saves state"| node_savestate
node_worker -->|"configures storage"| node_cloudstore
node_worker -->|"starts service"| node_monitoring
node_workerhandlers -.->|"records gameplay"| node_recorder
node_workerregistry -.->|"connects workers"| node_worker

click node_webapp "https://github.com/giongto35/cloud-game/blob/master/web/js/app.js"
click node_webinput "https://github.com/giongto35/cloud-game/tree/master/web/js/input"
click node_webstream "https://github.com/giongto35/cloud-game/blob/master/web/js/network/webrtc.js"
click node_coordinator "https://github.com/giongto35/cloud-game/blob/master/pkg/coordinator/coordinator.go"
click node_userhandlers "https://github.com/giongto35/cloud-game/blob/master/pkg/coordinator/userhandlers.go"
click node_workerregistry "https://github.com/giongto35/cloud-game/blob/master/pkg/coordinator/worker.go"
click node_api "https://github.com/giongto35/cloud-game/blob/master/pkg/api/api.go"
click node_worker "https://github.com/giongto35/cloud-game/blob/master/pkg/worker/worker.go"
click node_workerhandlers "https://github.com/giongto35/cloud-game/blob/master/pkg/worker/coordinatorhandlers.go"
click node_gamelibrary "https://github.com/giongto35/cloud-game/blob/master/pkg/games/library.go"
click node_emulator "https://github.com/giongto35/cloud-game/tree/master/pkg/worker/caged/libretro"
click node_room "https://github.com/giongto35/cloud-game/blob/master/pkg/worker/room/room.go"
click node_media "https://github.com/giongto35/cloud-game/blob/master/pkg/worker/media/gstreamer.go"
click node_webrtc "https://github.com/giongto35/cloud-game/blob/master/pkg/network/webrtc/webrtc.go"
click node_cloudstore "https://github.com/giongto35/cloud-game/tree/master/pkg/worker/cloud"
click node_savestate "https://github.com/giongto35/cloud-game/blob/master/pkg/worker/caged/libretro/storage.go"
click node_recorder "https://github.com/giongto35/cloud-game/blob/master/pkg/worker/recorder/recorder.go"
click node_monitoring "https://github.com/giongto35/cloud-game/blob/master/pkg/monitoring/monitoring.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_webapp,node_webinput,node_webstream toneBlue
class node_coordinator,node_userhandlers,node_workerregistry,node_api,node_gamesource toneAmber
class node_worker,node_workerhandlers,node_gamelibrary,node_emulator,node_room toneMint
class node_media,node_webrtc toneRose
class node_cloudstore,node_savestate,node_recorder,node_monitoring,node_player toneIndigo
```

## Components

### Browser client

- [Browser app](https://github.com/giongto35/cloud-game/blob/master/web/js/app.js): `web/js/app.js`
- [Game input](https://github.com/giongto35/cloud-game/tree/master/web/js/input): `web/js/input`
- [Browser streaming](https://github.com/giongto35/cloud-game/blob/master/web/js/network/webrtc.js): `web/js/network/webrtc.js`

### Coordination

- [Coordinator](https://github.com/giongto35/cloud-game/blob/master/pkg/coordinator/coordinator.go): `pkg/coordinator/coordinator.go`
- [User handlers](https://github.com/giongto35/cloud-game/blob/master/pkg/coordinator/userhandlers.go): `pkg/coordinator/userhandlers.go`
- [Worker registry](https://github.com/giongto35/cloud-game/blob/master/pkg/coordinator/worker.go): `pkg/coordinator/worker.go`
- [Protocol types](https://github.com/giongto35/cloud-game/blob/master/pkg/api/api.go): `pkg/api/api.go`

### Worker runtime

- [Worker service](https://github.com/giongto35/cloud-game/blob/master/pkg/worker/worker.go): `pkg/worker/worker.go`
- [Game handlers](https://github.com/giongto35/cloud-game/blob/master/pkg/worker/coordinatorhandlers.go): `pkg/worker/coordinatorhandlers.go`
- [Game library](https://github.com/giongto35/cloud-game/blob/master/pkg/games/library.go): `pkg/games/library.go`
- [Libretro emulator](https://github.com/giongto35/cloud-game/tree/master/pkg/worker/caged/libretro): `pkg/worker/caged/libretro`
- [Game rooms](https://github.com/giongto35/cloud-game/blob/master/pkg/worker/room/room.go): `pkg/worker/room/room.go`

### Media transport

- [Media encoder](https://github.com/giongto35/cloud-game/blob/master/pkg/worker/media/gstreamer.go): `pkg/worker/media/gstreamer.go`
- [WebRTC transport](https://github.com/giongto35/cloud-game/blob/master/pkg/network/webrtc/webrtc.go): `pkg/network/webrtc/webrtc.go`

### Storage and services

- [Cloud storage](https://github.com/giongto35/cloud-game/tree/master/pkg/worker/cloud): `pkg/worker/cloud`
- [Save-state storage](https://github.com/giongto35/cloud-game/blob/master/pkg/worker/caged/libretro/storage.go): `pkg/worker/caged/libretro/storage.go`
- [Game recording](https://github.com/giongto35/cloud-game/blob/master/pkg/worker/recorder/recorder.go): `pkg/worker/recorder/recorder.go`
- [Monitoring](https://github.com/giongto35/cloud-game/blob/master/pkg/monitoring/monitoring.go): `pkg/monitoring/monitoring.go`

### Other components

- **Player**
- **Game files**

## Connections

- Player → Browser app: plays in (evidence: `README.md`)
- Browser app → Game input: collects input (evidence: `web/js/app.js`)
- Browser app → Browser streaming: streams gameplay (evidence: `README.md`)
- Browser app → Coordinator: requests gameplay
- Coordinator → User handlers: routes users
- User handlers → Worker registry: dispatches game actions (evidence: `pkg/coordinator/userhandlers.go`)
- User handlers → Protocol types: uses requests (evidence: `pkg/coordinator/userhandlers.go`)
- Worker service → Game handlers: handles coordinator requests (evidence: `pkg/worker/worker.go`)
- Game handlers → Game library: selects games (evidence: `pkg/worker/coordinatorhandlers.go`)
- Game files → Game library: scans games
- Game handlers → Libretro emulator: starts game (evidence: `pkg/worker/coordinatorhandlers.go`)
- Game handlers → Game rooms: creates room (evidence: `pkg/worker/coordinatorhandlers.go`)
- Game handlers → Media encoder: initializes encoding (evidence: `pkg/worker/coordinatorhandlers.go`)
- Game handlers → WebRTC transport: creates peer (evidence: `pkg/worker/coordinatorhandlers.go`)
- Browser streaming → WebRTC transport: exchanges media
- Game handlers → Cloud storage: enables cloud saves (evidence: `pkg/worker/coordinatorhandlers.go`)
- Libretro emulator → Save-state storage: loads and saves state
- Worker service → Cloud storage: configures storage (evidence: `pkg/worker/worker.go`)
- Worker service → Monitoring: starts service (evidence: `pkg/worker/worker.go`)
- Game handlers → Game recording: records gameplay
- Worker registry → Worker service: connects workers (evidence: `README.md`)
