# genshinsim/gcsim architecture

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

- Interactive diagram: https://gitdiagram.com/genshinsim/gcsim
- Repository: https://github.com/genshinsim/gcsim

## Overview

gcsim is a Genshin Impact combat Monte Carlo simulator. Users provide a configuration of characters, targets, options, and actions; the web app or CLI runs simulations and returns aggregate statistics and optionally a frame-by-frame sample. The map emphasizes configuration parsing, combat setup and execution, result aggregation, and the documented web, local-server, and CLI entry points. Several UI and simulation modules named by the source index are absent from the supplied tree, so uncertain implementation links are omitted.

Main entry points: [`pkg/simulation/setup.go`](https://github.com/genshinsim/gcsim/blob/main/pkg/simulation/setup.go) (Simulation setup), [`cmd/wasm/main.go`](https://github.com/genshinsim/gcsim/blob/main/cmd/wasm/main.go) (WASM bridge), [`ui/packages/web/src/App.tsx`](https://github.com/genshinsim/gcsim/blob/main/ui/packages/web/src/App.tsx) (Web app), [`pkg/servermode/server.go`](https://github.com/genshinsim/gcsim/blob/main/pkg/servermode/server.go) (Server routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_webapp["Web app<br/>[App.tsx]"]
  node_webworkers["Web workers<br/>[storage.ts]"]
  node_wasm["WASM bridge<br/>[main.go]"]
  node_cli["CLI runner<br/>[main.go]"]
  node_localserver["Local server<br/>[main.go]"]
  node_servermode["Server routes<br/>[server.go]"]
end

subgraph group_runtime["Simulation runtime"]
  node_parser["Config parser<br/>[parser.go]"]
  node_simulation["Simulation setup<br/>[setup.go]"]
  node_simulator["Simulation runner<br/>[simulator.go]"]
  node_workerpool["Worker pool<br/>[worker.go]"]
end

subgraph group_domain["Combat domain"]
  node_characters["Character catalog<br/>[character.dm.go]"]
  node_artifacts["Artifact effects"]
  node_weapons["Weapon effects"]
  node_reactions["Reactions<br/>[reactable.go]"]
end

subgraph group_results["Results and sharing"]
  node_aggregation["Result aggregation<br/>[summary_gen.go]"]
  node_statistics["Result statistics<br/>[result_gen.go]"]
  node_share[("Share storage<br/>[storage.ts]")]
  node_mongo[("MongoDB service<br/>[mongo.go]")]
end

node_user(("Simulator user"))

node_user -->|"configures"| node_webapp
node_webapp -.->|"runs simulation"| node_wasm
node_webapp -.->|"requests simulation"| node_servermode
node_user -->|"runs config"| node_cli
node_localserver -->|"starts"| node_servermode
node_wasm -->|"parses config"| node_parser
node_parser -.->|"provides config"| node_simulation
node_simulation -->|"loads character data"| node_characters
node_simulation -->|"uses reactions"| node_reactions
node_simulation -.->|"loads effects"| node_artifacts
node_simulation -.->|"loads effects"| node_weapons
node_workerpool -->|"creates core"| node_simulation
node_workerpool -->|"runs simulation"| node_simulator
node_wasm -->|"creates core"| node_simulation
node_wasm -->|"summarizes run"| node_aggregation
node_cli -->|"runs simulation"| node_simulator
node_simulator -.->|"produces results"| node_aggregation
node_aggregation -->|"generates statistics"| node_statistics
node_webworkers -->|"stores shares"| node_share
node_servermode -.->|"uses persistence"| node_mongo

click node_webapp "https://github.com/genshinsim/gcsim/blob/main/ui/packages/web/src/App.tsx"
click node_webworkers "https://github.com/genshinsim/gcsim/blob/main/ui/packages/workers/src/share/storage.ts"
click node_wasm "https://github.com/genshinsim/gcsim/blob/main/cmd/wasm/main.go"
click node_cli "https://github.com/genshinsim/gcsim/blob/main/cmd/gcsim/main.go"
click node_localserver "https://github.com/genshinsim/gcsim/blob/main/cmd/server/main.go"
click node_servermode "https://github.com/genshinsim/gcsim/blob/main/pkg/servermode/server.go"
click node_parser "https://github.com/genshinsim/gcsim/blob/main/pkg/gcs/parser/parser.go"
click node_simulation "https://github.com/genshinsim/gcsim/blob/main/pkg/simulation/setup.go"
click node_simulator "https://github.com/genshinsim/gcsim/blob/main/pkg/simulator/simulator.go"
click node_workerpool "https://github.com/genshinsim/gcsim/blob/main/pkg/worker/worker.go"
click node_characters "https://github.com/genshinsim/gcsim/blob/main/pkg/catalog/character.dm.go"
click node_artifacts "https://github.com/genshinsim/gcsim/tree/main/internal/artifacts"
click node_weapons "https://github.com/genshinsim/gcsim/tree/main/internal/weapons"
click node_reactions "https://github.com/genshinsim/gcsim/blob/main/pkg/reactable/reactable.go"
click node_aggregation "https://github.com/genshinsim/gcsim/blob/main/pkg/agg/summary_gen.go"
click node_statistics "https://github.com/genshinsim/gcsim/blob/main/pkg/stats/result_gen.go"
click node_share "https://github.com/genshinsim/gcsim/blob/main/ui/packages/workers/src/share/storage.ts"
click node_mongo "https://github.com/genshinsim/gcsim/blob/main/backend/pkg/api/mongo.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_webworkers,node_wasm,node_cli,node_localserver,node_servermode,node_user toneBlue
class node_parser,node_simulation,node_simulator,node_workerpool toneAmber
class node_characters,node_artifacts,node_weapons,node_reactions toneMint
class node_aggregation,node_statistics,node_share,node_mongo toneRose
```

## Components

### User interfaces

- [Web app](https://github.com/genshinsim/gcsim/blob/main/ui/packages/web/src/App.tsx): `ui/packages/web/src/App.tsx`
- [Web workers](https://github.com/genshinsim/gcsim/blob/main/ui/packages/workers/src/share/storage.ts): `ui/packages/workers/src/share/storage.ts`
- [WASM bridge](https://github.com/genshinsim/gcsim/blob/main/cmd/wasm/main.go): `cmd/wasm/main.go`
- [CLI runner](https://github.com/genshinsim/gcsim/blob/main/cmd/gcsim/main.go): `cmd/gcsim/main.go`
- [Local server](https://github.com/genshinsim/gcsim/blob/main/cmd/server/main.go): `cmd/server/main.go`
- [Server routes](https://github.com/genshinsim/gcsim/blob/main/pkg/servermode/server.go): `pkg/servermode/server.go`

### Simulation runtime

- [Config parser](https://github.com/genshinsim/gcsim/blob/main/pkg/gcs/parser/parser.go): `pkg/gcs/parser/parser.go`
- [Simulation setup](https://github.com/genshinsim/gcsim/blob/main/pkg/simulation/setup.go): `pkg/simulation/setup.go`
- [Simulation runner](https://github.com/genshinsim/gcsim/blob/main/pkg/simulator/simulator.go): `pkg/simulator/simulator.go`
- [Worker pool](https://github.com/genshinsim/gcsim/blob/main/pkg/worker/worker.go): `pkg/worker/worker.go`

### Combat domain

- [Character catalog](https://github.com/genshinsim/gcsim/blob/main/pkg/catalog/character.dm.go): `pkg/catalog/character.dm.go`
- [Artifact effects](https://github.com/genshinsim/gcsim/tree/main/internal/artifacts): `internal/artifacts`
- [Weapon effects](https://github.com/genshinsim/gcsim/tree/main/internal/weapons): `internal/weapons`
- [Reactions](https://github.com/genshinsim/gcsim/blob/main/pkg/reactable/reactable.go): `pkg/reactable/reactable.go`

### Results and sharing

- [Result aggregation](https://github.com/genshinsim/gcsim/blob/main/pkg/agg/summary_gen.go): `pkg/agg/summary_gen.go`
- [Result statistics](https://github.com/genshinsim/gcsim/blob/main/pkg/stats/result_gen.go): `pkg/stats/result_gen.go`
- [Share storage](https://github.com/genshinsim/gcsim/blob/main/ui/packages/workers/src/share/storage.ts): `ui/packages/workers/src/share/storage.ts`
- [MongoDB service](https://github.com/genshinsim/gcsim/blob/main/backend/pkg/api/mongo.go): `backend/pkg/api/mongo.go`

### Other components

- **Simulator user**

## Connections

- Simulator user → Web app: configures (evidence: `README.md`)
- Web app → WASM bridge: runs simulation
- Web app → Server routes: requests simulation
- Simulator user → CLI runner: runs config (evidence: `README.md`)
- Local server → Server routes: starts (evidence: `cmd/server/main.go`)
- WASM bridge → Config parser: parses config (evidence: `cmd/wasm/main.go`)
- Config parser → Simulation setup: provides config
- Simulation setup → Character catalog: loads character data (evidence: `pkg/simulation/setup.go`)
- Simulation setup → Reactions: uses reactions (evidence: `pkg/simulation/setup.go`)
- Simulation setup → Artifact effects: loads effects
- Simulation setup → Weapon effects: loads effects
- Worker pool → Simulation setup: creates core (evidence: `pkg/worker/worker.go`)
- Worker pool → Simulation runner: runs simulation (evidence: `pkg/worker/worker.go`)
- WASM bridge → Simulation setup: creates core (evidence: `cmd/wasm/main.go`)
- WASM bridge → Result aggregation: summarizes run (evidence: `cmd/wasm/main.go`)
- CLI runner → Simulation runner: runs simulation (evidence: `cmd/gcsim/main.go`)
- Simulation runner → Result aggregation: produces results
- Result aggregation → Result statistics: generates statistics (evidence: `pkg/agg/summary_gen.go`)
- Web workers → Share storage: stores shares (evidence: `ui/packages/workers/src/share/storage.ts`)
- Server routes → MongoDB service: uses persistence
