# tristan-xo/stock-war architecture

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

- Interactive diagram: https://gitdiagram.com/tristan-xo/stock-war
- Repository: https://github.com/tristan-xo/stock-war

## Overview

Stock Wars is a browser-based, server-authoritative stock-trading simulation for live events. Players register, explore simulated stocks, request trade estimates, place orders, and follow portfolio performance; hosts manage rounds, timing, news, and event operations. The server coordinates these workflows and persists event and market state in SQLite. The README documents additional capabilities—such as SSE updates, recovery, and event export—that are not fully visible in the sampled source, so those links are shown only where documented.

Main entry points: [`public/app.js`](https://github.com/tristan-xo/stock-war/blob/main/public/app.js) (Web Interface), [`server.js`](https://github.com/tristan-xo/stock-war/blob/main/server.js) (HTTP API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Player and Host Experience"]
  node_web["Web Interface<br/>[app.js]"]
end

subgraph group_market["Market and Trading"]
  node_stocks["Stock Catalog<br/>[server.js]"]
  node_discovery["Stock Discovery<br/>[app.js]"]
  node_orders["Order Handling<br/>[server.js]"]
  node_portfolio["Portfolio Accounting<br/>[server.js]"]
  node_pricehistory["Price History<br/>[server.js]"]
end

subgraph group_event["Event Operations"]
  node_roundnews["Round News and Impacts<br/>[server.js]"]
  node_lifecycle["Round Lifecycle<br/>[server.js]"]
  node_hostops["Host Operations<br/>[server.js]"]
  node_audit["Audit and Presence<br/>[server.js]"]
end

subgraph group_platform["Server and Persistence"]
  node_api["HTTP API<br/>[server.js]"]
  node_realtime["Live Updates<br/>[server.js]"]
  node_database[("SQLite Event Store<br/>[server.js]")]
end

node_players(("Players"))
node_hosts(("Hosts"))

node_players -->|"use"| node_web
node_hosts -->|"use"| node_web
node_web -->|"requests"| node_api
node_api -->|"returns data"| node_web
node_api -.->|"publishes updates"| node_realtime
node_realtime -->|"streams state"| node_web
node_web -->|"renders"| node_discovery
node_web -->|"requests catalog"| node_stocks
node_web -->|"requests history"| node_pricehistory
node_web -->|"requests quotes"| node_orders
node_api -->|"handles trades"| node_orders
node_api -->|"serves transactions"| node_portfolio
node_orders -->|"reads and writes"| node_database
node_portfolio -->|"reads and writes"| node_database
node_pricehistory -->|"records prices"| node_database
node_api -->|"generates news"| node_roundnews
node_roundnews -->|"stores impacts"| node_database
node_lifecycle -->|"applies impacts"| node_roundnews
node_lifecycle -->|"commits round"| node_database
node_api -.->|"controls phases"| node_lifecycle
node_web -->|"requests operations"| node_hostops
node_api -->|"serves operations"| node_hostops
node_hostops -->|"updates event state"| node_database
node_api -->|"records activity"| node_audit
node_audit -->|"stores events"| node_database

click node_web "https://github.com/tristan-xo/stock-war/blob/main/public/app.js"
click node_stocks "https://github.com/tristan-xo/stock-war/blob/main/server.js"
click node_discovery "https://github.com/tristan-xo/stock-war/blob/main/public/app.js"
click node_orders "https://github.com/tristan-xo/stock-war/blob/main/server.js"
click node_portfolio "https://github.com/tristan-xo/stock-war/blob/main/server.js"
click node_pricehistory "https://github.com/tristan-xo/stock-war/blob/main/server.js"
click node_roundnews "https://github.com/tristan-xo/stock-war/blob/main/server.js"
click node_lifecycle "https://github.com/tristan-xo/stock-war/blob/main/server.js"
click node_hostops "https://github.com/tristan-xo/stock-war/blob/main/server.js"
click node_audit "https://github.com/tristan-xo/stock-war/blob/main/server.js"
click node_api "https://github.com/tristan-xo/stock-war/blob/main/server.js"
click node_realtime "https://github.com/tristan-xo/stock-war/blob/main/server.js"
click node_database "https://github.com/tristan-xo/stock-war/blob/main/server.js"

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_web toneBlue
class node_stocks,node_discovery,node_orders,node_portfolio,node_pricehistory toneAmber
class node_roundnews,node_lifecycle,node_hostops,node_audit toneMint
class node_api,node_realtime,node_database toneRose
class node_players,node_hosts toneIndigo
```

## Components

### Player and Host Experience

- [Web Interface](https://github.com/tristan-xo/stock-war/blob/main/public/app.js): `public/app.js`

### Market and Trading

- [Stock Catalog](https://github.com/tristan-xo/stock-war/blob/main/server.js): `server.js`
- [Stock Discovery](https://github.com/tristan-xo/stock-war/blob/main/public/app.js): `public/app.js`
- [Order Handling](https://github.com/tristan-xo/stock-war/blob/main/server.js): `server.js`
- [Portfolio Accounting](https://github.com/tristan-xo/stock-war/blob/main/server.js): `server.js`
- [Price History](https://github.com/tristan-xo/stock-war/blob/main/server.js): `server.js`

### Event Operations

- [Round News and Impacts](https://github.com/tristan-xo/stock-war/blob/main/server.js): `server.js`
- [Round Lifecycle](https://github.com/tristan-xo/stock-war/blob/main/server.js): `server.js`
- [Host Operations](https://github.com/tristan-xo/stock-war/blob/main/server.js): `server.js`
- [Audit and Presence](https://github.com/tristan-xo/stock-war/blob/main/server.js): `server.js`

### Server and Persistence

- [HTTP API](https://github.com/tristan-xo/stock-war/blob/main/server.js): `server.js`
- [Live Updates](https://github.com/tristan-xo/stock-war/blob/main/server.js): `server.js`
- [SQLite Event Store](https://github.com/tristan-xo/stock-war/blob/main/server.js): `server.js`

### Other components

- **Players**
- **Hosts**

## Connections

- Players → Web Interface: use (evidence: `README.md`)
- Hosts → Web Interface: use (evidence: `README.md`)
- Web Interface → HTTP API: requests (evidence: `public/app.js`)
- HTTP API → Web Interface: returns data (evidence: `public/app.js`)
- HTTP API → Live Updates: publishes updates (evidence: `server.js`)
- Live Updates → Web Interface: streams state (evidence: `README.md`)
- Web Interface → Stock Discovery: renders (evidence: `public/app.js`)
- Web Interface → Stock Catalog: requests catalog (evidence: `public/app.js`)
- Web Interface → Price History: requests history (evidence: `public/app.js`)
- Web Interface → Order Handling: requests quotes (evidence: `public/app.js`)
- HTTP API → Order Handling: handles trades (evidence: `server.js`)
- HTTP API → Portfolio Accounting: serves transactions (evidence: `server.js`)
- Order Handling → SQLite Event Store: reads and writes (evidence: `server.js`)
- Portfolio Accounting → SQLite Event Store: reads and writes (evidence: `server.js`)
- Price History → SQLite Event Store: records prices (evidence: `server.js`)
- HTTP API → Round News and Impacts: generates news (evidence: `server.js`)
- Round News and Impacts → SQLite Event Store: stores impacts (evidence: `server.js`)
- Round Lifecycle → Round News and Impacts: applies impacts (evidence: `server.js`)
- Round Lifecycle → SQLite Event Store: commits round (evidence: `server.js`)
- HTTP API → Round Lifecycle: controls phases (evidence: `server.js`)
- Web Interface → Host Operations: requests operations (evidence: `public/app.js`)
- HTTP API → Host Operations: serves operations (evidence: `server.js`)
- Host Operations → SQLite Event Store: updates event state (evidence: `server.js`)
- HTTP API → Audit and Presence: records activity (evidence: `server.js`)
- Audit and Presence → SQLite Event Store: stores events (evidence: `server.js`)
