# danielrmzn1/network-gamer-test architecture

> Architecture diagram of the GitHub repository danielrmzn1/network-gamer-test, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/danielrmzn1/network-gamer-test
- Repository: https://github.com/danielrmzn1/network-gamer-test

## Overview

#### Purpose and execution modes
FRAGRATE is a gamer-focused network measurement system that converts latency, jitter, UDP loss, throughput, and latency-under-load into overall ranks and per-game PLAYABLE/RISKY/NO-GO verdicts. It has two execution modes:
- **Local:** browser UI plus a Node measurement server running on the user’s network.
- **Hosted:** Cloudflare Worker serving the UI; browser-only measurements with optional TURN/WebRTC loss testing.

Entry points: `client/src/main.tsx`, `server/src/index.ts`, and `worker/index.ts`.

#### Shared domain model and scoring
`shared/` is the cross-runtime contract and single source of truth for game definitions, geographic regions, thresholds, grading, baseline values, and wire protocol. Both client and Node server consume these modules, avoiding duplicated scoring or message definitions.
- `shared/catalog.ts`
- `shared/grading.ts`
- `shared/protocol.ts`

Game-specific verdicts derive from collected measurements and genre thresholds; selecting another game or region recomputes from retained measurements rather than requiring another run.

#### Client application and presentation
The client is a Vite/React TypeScript SPA. Routing separates home/report views from game-oriented routes, while `App` composes the main dashboard. Desktop and mobile presentations are distinct component layers over the same measurement state.
- `client/src/main.tsx`
- `client/src/routes.tsx`
- `client/src/App.tsx`
- `client/src/pages/GamePage.tsx`
- `client/src/components/mobile/MobileDashboard.tsx`

SEO metadata/content and localized UI are client-side concerns, while preferences and startup state preserve user choices such as game or region.
- `client/src/seo/Seo.tsx`
- `client/src/state/store.ts`
- `client/src/state/prefs.ts`

#### Browser measurement orchestration
The browser engine owns test sequencing, aggregation, and report-ready metrics. It measures download/upload and bufferbloat from the browser, coordinates server-assisted regional and UDP probes, and feeds updates into application state/UI.
- `client/src/engine/orchestrator.ts`
- `client/src/engine/throughput.ts`
- `client/src/engine/loss.ts`
- `client/src/engine/stats.ts`

Transport boundaries are explicit: browser-to-server realtime commands/results use WebSocket support, while hosted-mode capabilities are detected and constrained by browser networking limitations.
- `client/src/engine/ws.ts`
- `client/src/engine/mode.ts`
- `client/src/engine/regionPing.ts`

#### Local measurement plane
The Node server is deliberately thin: it serves the production client and executes network probes from the machine where it runs. This makes TCP-connect region latency and STUN UDP loss measurements originate from the user’s actual connection rather than a remote application host.
- `server/src/index.ts`
- `server/src/pinger.ts`
- `server/src/stun.ts`
- `server/src/ws/session.ts`

It also provides measurement endpoints for local throughput fallback/static serving. The WebSocket session layer is the primary control boundary between browser orchestration and privileged Node TCP/UDP operations.
- `server/src/speedtest.ts`
- `server/src/static.ts`

#### Hosted Cloudflare boundary
The Worker deployment serves built static assets and exposes a narrowly scoped credential-minting endpoint for Cloudflare Realtime TURN. Long-term TURN credentials remain Worker secrets; the client receives only short-lived ICE server credentials.
- `worker/index.ts`
- `wrangler.jsonc`
- `client/src/engine/loss.ts`

Hosted mode cannot perform arbitrary raw TCP/UDP region probing from a browser. It therefore degrades to browser-capable throughput/bufferbloat and, when configured, WebRTC/TURN packet-loss measurement.

#### Runtime and deployment shape
The repository is a pnpm monorepo with Node 20+ local runtime, React/Vite client build, TypeScript Node server, and Cloudflare Workers deployment. Production local deployment builds the client and has Node serve it on one origin; development uses Vite with server proxying. Cloudflare Workers Static Assets serve `client/dist` in hosted deployment.
- `package.json`
- `pnpm-workspace.yaml`
- `client/vite.config.ts`
- `server/package.json`

Main entry points: [`server/src/ws/session.ts`](https://github.com/danielrmzn1/network-gamer-test/blob/main/server/src/ws/session.ts) (WebSocket session), [`client/src/engine/orchestrator.ts`](https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/engine/orchestrator.ts) (Measurement orchestrator), [`client/src/engine/mode.ts`](https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/engine/mode.ts) (Mode and transports), [`server/src/index.ts`](https://github.com/danielrmzn1/network-gamer-test/blob/main/server/src/index.ts) (Local Node server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser Client"]
  node_client_entry["Client entry<br/>Vite React entry<br/>[main.tsx]"]
  node_routes["Routes and dashboard<br/>React presentation<br/>[routes.tsx]"]
  node_game_page["Game views<br/>React page<br/>[GamePage.tsx]"]
  node_mobile_dashboard["Mobile dashboard<br/>React mobile UI"]
  node_client_state["Measurement state and prefs<br/>client state<br/>[store.ts]"]
  node_orchestrator{{"Measurement orchestrator<br/>browser engine<br/>[orchestrator.ts]"}}
  node_browser_tests["Browser tests<br/>throughput and loss<br/>[throughput.ts]"]
  node_transport_mode["Mode and transports<br/>browser transport<br/>[mode.ts]"]
end

subgraph group_shared["Shared Contract"]
  node_shared_model["Catalog and grading<br/>shared domain model<br/>[grading.ts]"]
  node_protocol["Wire protocol<br/>shared protocol<br/>[protocol.ts]"]
end

subgraph group_local["Local Measurement Plane"]
  node_node_server["Local Node server<br/>Node runtime<br/>[index.ts]"]
  node_ws_session{{"WebSocket session<br/>realtime control<br/>[session.ts]"}}
  node_region_pinger["TCP region pinger<br/>network probe<br/>[pinger.ts]"]
  node_stun_probe["STUN UDP loss probe<br/>network probe<br/>[stun.ts]"]
  node_local_speed_static["Local speed and static assets<br/>HTTP endpoints<br/>[speedtest.ts]"]
end

subgraph group_hosted["Hosted Deployment"]
  node_worker["Cloudflare Worker<br/>Worker runtime<br/>[index.ts]"]
  node_static_assets["Worker static assets<br/>Cloudflare assets<br/>[wrangler.jsonc]"]
  node_turn_loss["WebRTC/TURN loss test<br/>hosted loss measurement<br/>[loss.ts]"]
end

node_client_entry -->|"mounts"| node_routes
node_routes -->|"renders"| node_game_page
node_game_page -.->|"mobile presentation"| node_mobile_dashboard
node_game_page -->|"reads updates"| node_client_state
node_orchestrator -->|"publishes metrics"| node_client_state
node_orchestrator -->|"runs"| node_browser_tests
node_orchestrator -->|"selects capabilities"| node_transport_mode
node_client_state -->|"regrades retained results"| node_shared_model
node_orchestrator -->|"uses thresholds"| node_shared_model
node_transport_mode -->|"uses messages"| node_protocol
node_transport_mode -->|"local WebSocket"| node_ws_session
node_node_server -->|"hosts"| node_ws_session
node_ws_session -->|"commands"| node_region_pinger
node_ws_session -->|"commands"| node_stun_probe
node_ws_session -->|"implements"| node_protocol
node_node_server -->|"serves"| node_local_speed_static
node_transport_mode -.->|"local fallback"| node_local_speed_static
node_worker -->|"serves"| node_static_assets
node_worker -->|"mints ICE credentials"| node_turn_loss
node_browser_tests -.->|"hosted loss path"| node_turn_loss
node_worker -.->|"hosts SPA"| node_client_entry
node_node_server -.->|"hosts SPA locally"| node_client_entry

click node_client_entry "https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/main.tsx"
click node_routes "https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/routes.tsx"
click node_game_page "https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/pages/GamePage.tsx"
click node_mobile_dashboard "https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/components/mobile/MobileDashboard.tsx"
click node_client_state "https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/state/store.ts"
click node_orchestrator "https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/engine/orchestrator.ts"
click node_browser_tests "https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/engine/throughput.ts"
click node_transport_mode "https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/engine/mode.ts"
click node_shared_model "https://github.com/danielrmzn1/network-gamer-test/blob/main/shared/grading.ts"
click node_protocol "https://github.com/danielrmzn1/network-gamer-test/blob/main/shared/protocol.ts"
click node_node_server "https://github.com/danielrmzn1/network-gamer-test/blob/main/server/src/index.ts"
click node_ws_session "https://github.com/danielrmzn1/network-gamer-test/blob/main/server/src/ws/session.ts"
click node_region_pinger "https://github.com/danielrmzn1/network-gamer-test/blob/main/server/src/pinger.ts"
click node_stun_probe "https://github.com/danielrmzn1/network-gamer-test/blob/main/server/src/stun.ts"
click node_local_speed_static "https://github.com/danielrmzn1/network-gamer-test/blob/main/server/src/speedtest.ts"
click node_worker "https://github.com/danielrmzn1/network-gamer-test/blob/main/worker/index.ts"
click node_static_assets "https://github.com/danielrmzn1/network-gamer-test/blob/main/wrangler.jsonc"
click node_turn_loss "https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/engine/loss.ts"

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_client_entry,node_routes,node_game_page,node_mobile_dashboard,node_client_state,node_orchestrator,node_browser_tests,node_transport_mode toneBlue
class node_shared_model,node_protocol toneAmber
class node_node_server,node_ws_session,node_region_pinger,node_stun_probe,node_local_speed_static toneMint
class node_worker,node_static_assets,node_turn_loss toneRose
```

## Components

### Browser Client

React SPA and browser-side measurement runtime.

- [Client entry](https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/main.tsx): Vite React entry · `client/src/main.tsx`
- [Routes and dashboard](https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/routes.tsx): React presentation · Routes select report and game views around the main dashboard. · `client/src/routes.tsx`
- [Game views](https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/pages/GamePage.tsx): React page · Desktop and mobile layers present shared measurement state. · `client/src/pages/GamePage.tsx`
- [Mobile dashboard](https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/components/mobile/MobileDashboard.tsx): React mobile UI · `client/src/components/mobile/MobileDashboard.tsx`
- [Measurement state and prefs](https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/state/store.ts): client state · Retains measurements and user game or region choices. · `client/src/state/store.ts`
- [Measurement orchestrator](https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/engine/orchestrator.ts): browser engine · Sequences tests and produces report-ready metrics. · `client/src/engine/orchestrator.ts`
- [Browser tests](https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/engine/throughput.ts): throughput and loss · Runs browser throughput, bufferbloat, aggregation, and hosted loss tests. · `client/src/engine/throughput.ts`
- [Mode and transports](https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/engine/mode.ts): browser transport · Selects local WebSocket probing or hosted-capable measurements. · `client/src/engine/mode.ts`

### Shared Contract

Cross-runtime scoring and protocol source of truth.

- [Catalog and grading](https://github.com/danielrmzn1/network-gamer-test/blob/main/shared/grading.ts): shared domain model · Games, regions, thresholds, baselines, ranks, and verdicts. · `shared/grading.ts`
- [Wire protocol](https://github.com/danielrmzn1/network-gamer-test/blob/main/shared/protocol.ts): shared protocol · Browser and Node realtime message contract. · `shared/protocol.ts`

### Local Measurement Plane

Node runtime on the user's network.

- [Local Node server](https://github.com/danielrmzn1/network-gamer-test/blob/main/server/src/index.ts): Node runtime · Serves the built client and hosts privileged local probes. · `server/src/index.ts`
- [WebSocket session](https://github.com/danielrmzn1/network-gamer-test/blob/main/server/src/ws/session.ts): realtime control · Control boundary for browser commands and probe results. · `server/src/ws/session.ts`
- [TCP region pinger](https://github.com/danielrmzn1/network-gamer-test/blob/main/server/src/pinger.ts): network probe · Measures regional TCP-connect latency from the user's connection. · `server/src/pinger.ts`
- [STUN UDP loss probe](https://github.com/danielrmzn1/network-gamer-test/blob/main/server/src/stun.ts): network probe · Measures UDP loss from the user's connection. · `server/src/stun.ts`
- [Local speed and static assets](https://github.com/danielrmzn1/network-gamer-test/blob/main/server/src/speedtest.ts): HTTP endpoints · Provides throughput fallback and production SPA serving. · `server/src/speedtest.ts`

### Hosted Deployment

Cloudflare-hosted browser-only mode.

- [Cloudflare Worker](https://github.com/danielrmzn1/network-gamer-test/blob/main/worker/index.ts): Worker runtime · Serves static assets and mints narrowly scoped TURN credentials. · `worker/index.ts`
- [Worker static assets](https://github.com/danielrmzn1/network-gamer-test/blob/main/wrangler.jsonc): Cloudflare assets · Serves the built client distribution. · `wrangler.jsonc`
- [WebRTC/TURN loss test](https://github.com/danielrmzn1/network-gamer-test/blob/main/client/src/engine/loss.ts): hosted loss measurement · Uses short-lived ICE credentials when configured. · `client/src/engine/loss.ts`

## Connections

- Client entry → Routes and dashboard: mounts
- Routes and dashboard → Game views: renders
- Game views → Mobile dashboard: mobile presentation
- Game views → Measurement state and prefs: reads updates
- Measurement orchestrator → Measurement state and prefs: publishes metrics
- Measurement orchestrator → Browser tests: runs
- Measurement orchestrator → Mode and transports: selects capabilities
- Measurement state and prefs → Catalog and grading: regrades retained results
- Measurement orchestrator → Catalog and grading: uses thresholds
- Mode and transports → Wire protocol: uses messages
- Mode and transports → WebSocket session: local WebSocket
- Local Node server → WebSocket session: hosts
- WebSocket session → TCP region pinger: commands
- WebSocket session → STUN UDP loss probe: commands
- WebSocket session → Wire protocol: implements
- Local Node server → Local speed and static assets: serves
- Mode and transports → Local speed and static assets: local fallback
- Cloudflare Worker → Worker static assets: serves
- Cloudflare Worker → WebRTC/TURN loss test: mints ICE credentials
- Browser tests → WebRTC/TURN loss test: hosted loss path
- Cloudflare Worker → Client entry: hosts SPA
- Local Node server → Client entry: hosts SPA locally
