# lihua23410/xqdj architecture

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

- Interactive diagram: https://gitdiagram.com/lihua23410/xqdj
- Repository: https://github.com/lihua23410/xqdj

## Overview

小球对战 is a local 1v1 spectator simulator: a browser chooses two fighters and a required field, then watches the Go engine advance the match and stream snapshots over WebSocket. `main.go` owns HTTP/WebSocket handling; `internal/sim` owns match state and collision simulation, while fighters and fields register through `internal/unit`. The browser renders snapshots and effects. The README also documents a headless win-rate matrix. Some subsystem links rely on README descriptions because their source was not sampled.

Main entry points: [`internal/sim/match.go`](https://github.com/lihua23410/xqdj/blob/master/internal/sim/match.go) (Match state), [`main.go`](https://github.com/lihua23410/xqdj/blob/master/main.go) (HTTP and WS), [`internal/web/app.js`](https://github.com/lihua23410/xqdj/blob/master/internal/web/app.js) (Selection and renderer), [`internal/unit`](https://github.com/lihua23410/xqdj/tree/master/internal/unit) (Actor protocol)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Server orchestration"]
  node_main["HTTP and WS<br/>[main.go]"]
  node_winrate["Win-rate runner<br/>[main.go]"]
end

subgraph group_engine["Match engine"]
  node_match["Match state<br/>[match.go]"]
  node_physics["Collision physics<br/>[physics.go]"]
  node_unit["Actor protocol"]
end

subgraph group_content["Fighters and fields"]
  node_fighters["Fighter packs"]
  node_fields["Field packs"]
end

subgraph group_browser["Browser display"]
  node_webassets["Embedded web assets<br/>[embed.go]"]
  node_webapp["Selection and renderer<br/>[app.js]"]
  node_browserfx["Fighter effects"]
end

node_viewer(("Spectator"))
node_websocket(("WebSocket client"))
node_report["Win-rate report"]

node_viewer -->|"selects match"| node_webapp
node_webapp -->|"sends commands"| node_websocket
node_websocket -->|"WebSocket messages"| node_main
node_main -->|"routes commands"| node_match
node_main -->|"serves assets"| node_webassets
node_main -->|"broadcasts snapshots"| node_websocket
node_match -->|"advances collisions"| node_physics
node_match -->|"uses protocol"| node_unit
node_match -->|"loads field registry"| node_fields
node_fighters -->|"registers actors"| node_unit
node_fields -->|"registers fields"| node_unit
node_match -->|"dispatches actors"| node_fighters
node_websocket -->|"delivers snapshots"| node_webapp
node_webapp -.->|"loads pack effects"| node_browserfx
node_winrate -->|"runs matches"| node_match
node_winrate -->|"writes results"| node_report

click node_main "https://github.com/lihua23410/xqdj/blob/master/main.go"
click node_winrate "https://github.com/lihua23410/xqdj/blob/master/cmd/winrate/main.go"
click node_match "https://github.com/lihua23410/xqdj/blob/master/internal/sim/match.go"
click node_physics "https://github.com/lihua23410/xqdj/blob/master/internal/sim/physics.go"
click node_unit "https://github.com/lihua23410/xqdj/tree/master/internal/unit"
click node_fighters "https://github.com/lihua23410/xqdj/tree/master/character"
click node_fields "https://github.com/lihua23410/xqdj/tree/master/map"
click node_webassets "https://github.com/lihua23410/xqdj/blob/master/internal/web/embed.go"
click node_webapp "https://github.com/lihua23410/xqdj/blob/master/internal/web/app.js"
click node_browserfx "https://github.com/lihua23410/xqdj/tree/master/character"

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_main,node_winrate,node_websocket toneBlue
class node_match,node_physics,node_unit toneAmber
class node_fighters,node_fields toneMint
class node_webassets,node_webapp,node_browserfx toneRose
class node_viewer,node_report toneIndigo
```

## Components

### Server orchestration

- [HTTP and WS](https://github.com/lihua23410/xqdj/blob/master/main.go): `main.go`
- [Win-rate runner](https://github.com/lihua23410/xqdj/blob/master/cmd/winrate/main.go): `cmd/winrate/main.go`

### Match engine

- [Match state](https://github.com/lihua23410/xqdj/blob/master/internal/sim/match.go): `internal/sim/match.go`
- [Collision physics](https://github.com/lihua23410/xqdj/blob/master/internal/sim/physics.go): `internal/sim/physics.go`
- [Actor protocol](https://github.com/lihua23410/xqdj/tree/master/internal/unit): `internal/unit`

### Fighters and fields

- [Fighter packs](https://github.com/lihua23410/xqdj/tree/master/character): `character`
- [Field packs](https://github.com/lihua23410/xqdj/tree/master/map): `map`

### Browser display

- [Embedded web assets](https://github.com/lihua23410/xqdj/blob/master/internal/web/embed.go): `internal/web/embed.go`
- [Selection and renderer](https://github.com/lihua23410/xqdj/blob/master/internal/web/app.js): `internal/web/app.js`
- [Fighter effects](https://github.com/lihua23410/xqdj/tree/master/character): `character`

### Other components

- **Spectator**
- **WebSocket client**
- **Win-rate report**

## Connections

- Spectator → Selection and renderer: selects match
- Selection and renderer → WebSocket client: sends commands
- WebSocket client → HTTP and WS: WebSocket messages
- HTTP and WS → Match state: routes commands
- HTTP and WS → Embedded web assets: serves assets
- HTTP and WS → WebSocket client: broadcasts snapshots
- Match state → Collision physics: advances collisions
- Match state → Actor protocol: uses protocol
- Match state → Field packs: loads field registry
- Fighter packs → Actor protocol: registers actors
- Field packs → Actor protocol: registers fields
- Match state → Fighter packs: dispatches actors
- WebSocket client → Selection and renderer: delivers snapshots
- Selection and renderer → Fighter effects: loads pack effects
- Win-rate runner → Match state: runs matches
- Win-rate runner → Win-rate report: writes results
