# ybz777/china-1937-survivalgame architecture

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

- Interactive diagram: https://gitdiagram.com/ybz777/china-1937-survivalgame
- Repository: https://github.com/ybz777/china-1937-survivalgame

## Overview

China 1937 is a browser-based historical survival game. Players create a campaign, explore a changing wartime map, encounter events and people, manage supplies, and resolve combat; campaign state is saved locally with optional cloud backup. The graph preserves the major gameplay domains and the UI/state layer. Evidence for some modules comes from SOURCE INDEX references or README capability descriptions; unsampled internals are not assumed to define additional call paths.

Main entry points: [`frontend/src/game/engine.ts`](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/engine.ts) (Campaign simulation), [`frontend/src/ui/Game.tsx`](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/Game.tsx) (Game shell), [`frontend/src/game/world.ts`](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/world.ts) (Cities and routes), [`frontend/src/ui/Create.tsx`](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/Create.tsx) (Campaign creation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Game interface"]
  node_game_ui["Game shell<br/>[Game.tsx]"]
  node_creation["Campaign creation<br/>[Create.tsx]"]
  node_world_ui["Travel interface<br/>[World.tsx]"]
  node_panels["Journal and panels<br/>[Panels.tsx]"]
  node_equipment_ui["Equipment interface<br/>[Equipment.tsx]"]
  node_common["Shared controls<br/>[common.tsx]"]
end

subgraph group_runtime["Campaign runtime"]
  node_engine["Campaign simulation<br/>[engine.ts]"]
  node_events["Dynamic events<br/>[events.ts]"]
  node_combat["Tactical combat<br/>[combat.ts]"]
  node_ambush["Ambush encounters<br/>[ambush.ts]"]
  node_audio["Audio and music<br/>[audio.ts]"]
end

subgraph group_content["World and content"]
  node_items["Items and inventory<br/>[items.ts]"]
  node_acquisition["Scavenging and trade<br/>[acquisition.ts]"]
  node_world["Cities and routes<br/>[world.ts]"]
  node_people["NPCs and companions<br/>[people.ts]"]
  node_historical["Historical events"]
  node_major_events["Major encounters<br/>[majorEvents.ts]"]
  node_targets["Major targets<br/>[majorTargets.ts]"]
  node_firepower["Weapon performance<br/>[firepower.ts]"]
end

subgraph group_state["Campaign state"]
  node_store["Game state store<br/>[store.ts]"]
  node_persistence["Save management<br/>[persistence.ts]"]
end

subgraph group_services["Persistence services"]
  node_backend["FastAPI save service<br/>[server.py]"]
  node_mongodb[("MongoDB")]
end

node_player(("Player"))

node_player -->|"creates campaign"| node_creation
node_player -->|"explores map"| node_world_ui
node_player -->|"plays game"| node_game_ui
node_game_ui -->|"renders"| node_creation
node_game_ui -->|"reads state"| node_store
node_game_ui -->|"dispatches gameplay"| node_engine
node_game_ui -->|"renders"| node_world_ui
node_game_ui -->|"controls audio"| node_audio
node_creation -->|"starts campaign"| node_engine
node_creation -->|"reads locations"| node_world
node_creation -->|"reads backgrounds"| node_people
node_creation -->|"selects purchases"| node_items
node_world_ui -->|"reads routes"| node_world
node_world_ui -->|"requests travel"| node_engine
node_world_ui -->|"dispatches action"| node_store
node_panels -->|"reads campaign date"| node_engine
node_equipment_ui -->|"reads equipment"| node_items
node_equipment_ui -->|"uses game logic"| node_engine
node_common -->|"renders item data"| node_items
node_common -->|"reads labels"| node_store
node_common -->|"plays click sound"| node_audio
node_engine -->|"selects events"| node_events
node_engine -->|"updates inventory"| node_items
node_engine -->|"resolves acquisition"| node_acquisition
node_engine -->|"uses routes and control"| node_world
node_engine -->|"uses character data"| node_people
node_engine -->|"runs combat"| node_combat
node_engine -->|"uses ambush data"| node_historical
node_engine -->|"uses encounter data"| node_major_events
node_events -->|"checks control"| node_world
node_events -->|"includes events"| node_historical
node_events -->|"includes encounters"| node_major_events
node_events -->|"includes ambush events"| node_ambush
node_combat -->|"uses simulation actions"| node_engine
node_combat -->|"uses weapons"| node_items
node_combat -->|"loads enemy data"| node_targets
node_combat -->|"uses weapon stats"| node_firepower
node_ambush -->|"checks locations"| node_world
node_ambush -->|"uses event content"| node_historical
node_ambush -->|"uses major content"| node_major_events
node_acquisition -->|"uses item catalog"| node_items
node_major_events -->|"checks control"| node_world
node_major_events -->|"uses target data"| node_targets
node_major_events -->|"uses inspection rules"| node_historical
node_world -.->|"defines exploration"| node_player
node_game_ui -->|"renders"| node_panels
node_game_ui -->|"renders"| node_equipment_ui
node_store -->|"loads and saves"| node_persistence

click node_game_ui "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/Game.tsx"
click node_creation "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/Create.tsx"
click node_world_ui "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/World.tsx"
click node_panels "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/Panels.tsx"
click node_equipment_ui "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/Equipment.tsx"
click node_common "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/common.tsx"
click node_engine "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/engine.ts"
click node_events "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/events.ts"
click node_combat "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/combat.ts"
click node_ambush "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/ambush.ts"
click node_items "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/items.ts"
click node_acquisition "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/acquisition.ts"
click node_world "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/world.ts"
click node_people "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/people.ts"
click node_historical "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/historicalEvents.ts"
click node_major_events "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/majorEvents.ts"
click node_targets "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/majorTargets.ts"
click node_firepower "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/firepower.ts"
click node_audio "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/audio.ts"
click node_store "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/store.ts"
click node_persistence "https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/persistence.ts"
click node_backend "https://github.com/ybz777/china-1937-survivalgame/blob/main/backend/server.py"

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_game_ui,node_creation,node_world_ui,node_panels,node_equipment_ui,node_common toneBlue
class node_engine,node_events,node_combat,node_ambush,node_audio toneAmber
class node_items,node_acquisition,node_world,node_people,node_historical,node_major_events,node_targets,node_firepower toneMint
class node_store,node_persistence toneRose
class node_backend,node_mongodb,node_player toneIndigo
```

## Components

### Game interface

- [Game shell](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/Game.tsx): `frontend/src/ui/Game.tsx`
- [Campaign creation](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/Create.tsx): `frontend/src/ui/Create.tsx`
- [Travel interface](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/World.tsx): `frontend/src/ui/World.tsx`
- [Journal and panels](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/Panels.tsx): `frontend/src/ui/Panels.tsx`
- [Equipment interface](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/Equipment.tsx): `frontend/src/ui/Equipment.tsx`
- [Shared controls](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/ui/common.tsx): `frontend/src/ui/common.tsx`

### Campaign runtime

- [Campaign simulation](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/engine.ts): `frontend/src/game/engine.ts`
- [Dynamic events](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/events.ts): `frontend/src/game/events.ts`
- [Tactical combat](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/combat.ts): `frontend/src/game/combat.ts`
- [Ambush encounters](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/ambush.ts): `frontend/src/game/ambush.ts`
- [Audio and music](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/audio.ts): `frontend/src/game/audio.ts`

### World and content

- [Items and inventory](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/items.ts): `frontend/src/game/items.ts`
- [Scavenging and trade](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/acquisition.ts): `frontend/src/game/acquisition.ts`
- [Cities and routes](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/world.ts): `frontend/src/game/world.ts`
- [NPCs and companions](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/people.ts): `frontend/src/game/people.ts`
- [Historical events](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/historicalEvents.ts): `frontend/src/game/historicalEvents.ts`
- [Major encounters](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/majorEvents.ts): `frontend/src/game/majorEvents.ts`
- [Major targets](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/majorTargets.ts): `frontend/src/game/majorTargets.ts`
- [Weapon performance](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/firepower.ts): `frontend/src/game/firepower.ts`

### Campaign state

- [Game state store](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/store.ts): `frontend/src/game/store.ts`
- [Save management](https://github.com/ybz777/china-1937-survivalgame/blob/main/frontend/src/game/persistence.ts): `frontend/src/game/persistence.ts`

### Persistence services

- [FastAPI save service](https://github.com/ybz777/china-1937-survivalgame/blob/main/backend/server.py): `backend/server.py`
- **MongoDB**

### Other components

- **Player**

## Connections

- Player → Campaign creation: creates campaign (evidence: `README.md`)
- Player → Travel interface: explores map (evidence: `README.md`)
- Player → Game shell: plays game (evidence: `README.md`)
- Game shell → Campaign creation: renders (evidence: `frontend/src/ui/Game.tsx`)
- Game shell → Game state store: reads state (evidence: `frontend/src/ui/Game.tsx`)
- Game shell → Campaign simulation: dispatches gameplay (evidence: `frontend/src/ui/Game.tsx`)
- Game shell → Travel interface: renders (evidence: `frontend/src/ui/Game.tsx`)
- Game shell → Audio and music: controls audio (evidence: `frontend/src/ui/Game.tsx`)
- Campaign creation → Campaign simulation: starts campaign (evidence: `frontend/src/ui/Create.tsx`)
- Campaign creation → Cities and routes: reads locations (evidence: `frontend/src/ui/Create.tsx`)
- Campaign creation → NPCs and companions: reads backgrounds (evidence: `frontend/src/ui/Create.tsx`)
- Campaign creation → Items and inventory: selects purchases (evidence: `frontend/src/ui/Create.tsx`)
- Travel interface → Cities and routes: reads routes (evidence: `frontend/src/ui/World.tsx`)
- Travel interface → Campaign simulation: requests travel (evidence: `frontend/src/ui/World.tsx`)
- Travel interface → Game state store: dispatches action (evidence: `frontend/src/ui/World.tsx`)
- Journal and panels → Campaign simulation: reads campaign date (evidence: `frontend/src/ui/Panels.tsx`)
- Equipment interface → Items and inventory: reads equipment (evidence: `frontend/src/ui/Equipment.tsx`)
- Equipment interface → Campaign simulation: uses game logic (evidence: `frontend/src/ui/Equipment.tsx`)
- Shared controls → Items and inventory: renders item data (evidence: `frontend/src/ui/common.tsx`)
- Shared controls → Game state store: reads labels (evidence: `frontend/src/ui/common.tsx`)
- Shared controls → Audio and music: plays click sound (evidence: `frontend/src/ui/common.tsx`)
- Campaign simulation → Dynamic events: selects events (evidence: `frontend/src/game/engine.ts`)
- Campaign simulation → Items and inventory: updates inventory (evidence: `frontend/src/game/engine.ts`)
- Campaign simulation → Scavenging and trade: resolves acquisition (evidence: `frontend/src/game/engine.ts`)
- Campaign simulation → Cities and routes: uses routes and control (evidence: `frontend/src/game/engine.ts`)
- Campaign simulation → NPCs and companions: uses character data (evidence: `frontend/src/game/engine.ts`)
- Campaign simulation → Tactical combat: runs combat (evidence: `frontend/src/game/engine.ts`)
- Campaign simulation → Historical events: uses ambush data (evidence: `frontend/src/game/engine.ts`)
- Campaign simulation → Major encounters: uses encounter data (evidence: `frontend/src/game/engine.ts`)
- Dynamic events → Cities and routes: checks control (evidence: `frontend/src/game/events.ts`)
- Dynamic events → Historical events: includes events (evidence: `frontend/src/game/events.ts`)
- Dynamic events → Major encounters: includes encounters (evidence: `frontend/src/game/events.ts`)
- Dynamic events → Ambush encounters: includes ambush events (evidence: `frontend/src/game/events.ts`)
- Tactical combat → Campaign simulation: uses simulation actions (evidence: `frontend/src/game/combat.ts`)
- Tactical combat → Items and inventory: uses weapons (evidence: `frontend/src/game/combat.ts`)
- Tactical combat → Major targets: loads enemy data (evidence: `frontend/src/game/combat.ts`)
- Tactical combat → Weapon performance: uses weapon stats (evidence: `frontend/src/game/combat.ts`)
- Ambush encounters → Cities and routes: checks locations (evidence: `frontend/src/game/ambush.ts`)
- Ambush encounters → Historical events: uses event content (evidence: `frontend/src/game/ambush.ts`)
- Ambush encounters → Major encounters: uses major content (evidence: `frontend/src/game/ambush.ts`)
- Scavenging and trade → Items and inventory: uses item catalog (evidence: `frontend/src/game/acquisition.ts`)
- Major encounters → Cities and routes: checks control (evidence: `frontend/src/game/majorEvents.ts`)
- Major encounters → Major targets: uses target data (evidence: `frontend/src/game/majorEvents.ts`)
- Major encounters → Historical events: uses inspection rules (evidence: `frontend/src/game/majorEvents.ts`)
- Cities and routes → Player: defines exploration (evidence: `README.md`)
- Game shell → Journal and panels: renders (evidence: `frontend/src/ui/Game.tsx`)
- Game shell → Equipment interface: renders (evidence: `frontend/src/ui/Game.tsx`)
- Game state store → Save management: loads and saves (evidence: `frontend/src/game/store.ts`)
