# vtrider/statsgate architecture

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

- Interactive diagram: https://gitdiagram.com/vtrider/statsgate
- Repository: https://github.com/vtrider/statsgate

## Overview

Statsgate is a game-session statistics recorder for BZCC. Its documented main workflow is to launch the freestanding client while the game is open, capture mission events into a protobuf session, and save the session locally; console commands expose control and configuration. The tree also contains DLL- and Lua-hosted client entry points and mission-hook support. Source excerpts establish the entry-point and recorder relationships, but do not show the full serialization and file-writing implementation, so those links are documented rather than inferred from unsampled code.

Main entry points: [`src/stat_client.cpp`](https://github.com/vtrider/statsgate/blob/main/src/stat_client.cpp) (Stat client), [`statsgate/src/freestanding_client.cpp`](https://github.com/vtrider/statsgate/blob/main/statsgate/src/freestanding_client.cpp) (Freestanding entry), [`statsgate/src/dll_client.cpp`](https://github.com/vtrider/statsgate/blob/main/statsgate/src/dll_client.cpp) (DLL entry), [`src/command.h`](https://github.com/vtrider/statsgate/blob/main/src/command.h) (Command registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Client runtime"]
  node_free_entry["Freestanding entry"]
  node_dll_entry["DLL entry<br/>[dll_client.cpp]"]
  node_lua_entry["Lua entry<br/>[lua_client.cpp]"]
  node_singleton["Singleton guard<br/>[dllmain.cpp]"]
  node_thread_guard["Thread guard<br/>[thread_guard.cpp]"]
end

subgraph group_capture["Mission capture"]
  node_client["Stat client<br/>[stat_client.cpp]"]
  node_client_api["Recorder interface<br/>[stat_client.h]"]
  node_mission_hooks["Mission hooks<br/>[mission_hook.cpp]"]
end

subgraph group_events["Stat events"]
  node_schema["Session schema<br/>[statsgate.proto]"]
  node_protobuf["Protobuf messages<br/>[statsgate.pb.h]"]
  node_sessions[("Saved sessions<br/>[stat_client.cpp]")]
end

subgraph group_interfaces["Client interfaces"]
  node_commands["Console commands<br/>[command.cpp]"]
  node_command_api["Command registry<br/>[command.h]"]
end

node_player(("Player"))
node_launcher(("Stats launcher"))
node_game["BZCC game"]
node_external_stats(("Stats consumer"))

node_launcher -->|"starts client"| node_free_entry
node_free_entry -->|"creates"| node_client
node_free_entry -->|"guards setup"| node_thread_guard
node_dll_entry -.->|"checks instance"| node_singleton
node_dll_entry -->|"creates"| node_client
node_lua_entry -->|"creates"| node_client
node_client -->|"implements"| node_client_api
node_client -->|"applies hooks"| node_mission_hooks
node_client -->|"registers handlers"| node_command_api
node_command_api -->|"dispatches"| node_commands
node_game -.->|"provides callbacks"| node_mission_hooks
node_game -->|"supplies game state"| node_client
node_client -->|"records events"| node_protobuf
node_schema -->|"defines messages"| node_protobuf
node_client -->|"saves sessions"| node_sessions
node_sessions -->|"contributes stats"| node_external_stats
node_player -->|"starts recording"| node_launcher

click node_free_entry "https://github.com/vtrider/statsgate/blob/main/statsgate/src/freestanding_client.cpp"
click node_dll_entry "https://github.com/vtrider/statsgate/blob/main/statsgate/src/dll_client.cpp"
click node_lua_entry "https://github.com/vtrider/statsgate/blob/main/statsgate/src/lua_client.cpp"
click node_singleton "https://github.com/vtrider/statsgate/blob/main/src/dllmain.cpp"
click node_client "https://github.com/vtrider/statsgate/blob/main/src/stat_client.cpp"
click node_client_api "https://github.com/vtrider/statsgate/blob/main/src/stat_client.h"
click node_mission_hooks "https://github.com/vtrider/statsgate/blob/main/src/mission_hook.cpp"
click node_thread_guard "https://github.com/vtrider/statsgate/blob/main/src/thread_guard.cpp"
click node_commands "https://github.com/vtrider/statsgate/blob/main/src/command.cpp"
click node_command_api "https://github.com/vtrider/statsgate/blob/main/src/command.h"
click node_schema "https://github.com/vtrider/statsgate/blob/main/statsgate.proto"
click node_protobuf "https://github.com/vtrider/statsgate/blob/main/src/statsgate.pb.h"
click node_sessions "https://github.com/vtrider/statsgate/blob/main/src/stat_client.cpp"

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_free_entry,node_dll_entry,node_lua_entry,node_singleton,node_thread_guard toneBlue
class node_client,node_client_api,node_mission_hooks toneAmber
class node_schema,node_protobuf,node_sessions toneMint
class node_commands,node_command_api toneRose
class node_player,node_launcher,node_game,node_external_stats toneIndigo
```

## Components

### Client runtime

- [Freestanding entry](https://github.com/vtrider/statsgate/blob/main/statsgate/src/freestanding_client.cpp): `statsgate/src/freestanding_client.cpp`
- [DLL entry](https://github.com/vtrider/statsgate/blob/main/statsgate/src/dll_client.cpp): `statsgate/src/dll_client.cpp`
- [Lua entry](https://github.com/vtrider/statsgate/blob/main/statsgate/src/lua_client.cpp): `statsgate/src/lua_client.cpp`
- [Singleton guard](https://github.com/vtrider/statsgate/blob/main/src/dllmain.cpp): `src/dllmain.cpp`
- [Thread guard](https://github.com/vtrider/statsgate/blob/main/src/thread_guard.cpp): `src/thread_guard.cpp`

### Mission capture

- [Stat client](https://github.com/vtrider/statsgate/blob/main/src/stat_client.cpp): `src/stat_client.cpp`
- [Recorder interface](https://github.com/vtrider/statsgate/blob/main/src/stat_client.h): `src/stat_client.h`
- [Mission hooks](https://github.com/vtrider/statsgate/blob/main/src/mission_hook.cpp): `src/mission_hook.cpp`

### Stat events

- [Session schema](https://github.com/vtrider/statsgate/blob/main/statsgate.proto): `statsgate.proto`
- [Protobuf messages](https://github.com/vtrider/statsgate/blob/main/src/statsgate.pb.h): `src/statsgate.pb.h`
- [Saved sessions](https://github.com/vtrider/statsgate/blob/main/src/stat_client.cpp): `src/stat_client.cpp`

### Client interfaces

- [Console commands](https://github.com/vtrider/statsgate/blob/main/src/command.cpp): `src/command.cpp`
- [Command registry](https://github.com/vtrider/statsgate/blob/main/src/command.h): `src/command.h`

### Other components

- **Player**
- **Stats launcher**
- **BZCC game**
- **Stats consumer**

## Connections

- Stats launcher → Freestanding entry: starts client (evidence: `README.md`)
- Freestanding entry → Stat client: creates (evidence: `statsgate/src/freestanding_client.cpp`)
- Freestanding entry → Thread guard: guards setup (evidence: `statsgate/src/freestanding_client.cpp`)
- DLL entry → Singleton guard: checks instance
- DLL entry → Stat client: creates (evidence: `statsgate/src/dll_client.cpp`)
- Lua entry → Stat client: creates (evidence: `statsgate/src/lua_client.cpp`)
- Stat client → Recorder interface: implements (evidence: `src/stat_client.h`)
- Stat client → Mission hooks: applies hooks (evidence: `src/stat_client.cpp`)
- Stat client → Command registry: registers handlers (evidence: `src/stat_client.cpp`)
- Command registry → Console commands: dispatches (evidence: `src/command.cpp`)
- BZCC game → Mission hooks: provides callbacks
- BZCC game → Stat client: supplies game state (evidence: `src/stat_client.cpp`)
- Stat client → Protobuf messages: records events (evidence: `src/stat_client.cpp`)
- Session schema → Protobuf messages: defines messages (evidence: `src/statsgate.pb.h`)
- Stat client → Saved sessions: saves sessions (evidence: `README.md`)
- Saved sessions → Stats consumer: contributes stats (evidence: `README.md`)
- Player → Stats launcher: starts recording (evidence: `README.md`)
