# helenc3/hackru architecture

> Architecture diagram of the GitHub repository helenc3/hackru, 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/helenc3/hackru
- Repository: https://github.com/helenc3/hackru

## Overview

Speak Your Way is a single-player Mandarin-practice browser game. The player starts or resumes a session, explores a streamed Shanghai-style city, completes three voice-or-typed NPC quests, and receives deterministic game outcomes; AI assists with dialogue and city composition. The map also includes dictionary support and speech playback. Source excerpts and the index establish several internal links; broader browser/API and product-flow links are documented in the README. Unsampled routes and integrations are shown only where the README supports them.

Main entry points: [`apps/web/src/app/App.tsx`](https://github.com/helenc3/hackru/blob/main/apps/web/src/app/App.tsx) (Game interface), [`apps/server/src/services.ts`](https://github.com/helenc3/hackru/blob/main/apps/server/src/services.ts) (Service assembly), [`apps/server/src/app.ts`](https://github.com/helenc3/hackru/blob/main/apps/server/src/app.ts) (HTTP application), [`apps/server/src/city/world-service.ts`](https://github.com/helenc3/hackru/blob/main/apps/server/src/city/world-service.ts) (World service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser game"]
  node_webapp["Game interface<br/>[App.tsx]"]
  node_sessionhook["Session state<br/>[use-session.ts]"]
  node_sessionclient["Session API client<br/>[session-client.ts]"]
  node_worldview["World renderer<br/>[WorldRenderer.tsx]"]
  node_cityview["Chunk streaming and render<br/>[ChunkRenderer.tsx]"]
  node_audioplay["Reply audio playback"]
end

subgraph group_server["API and services"]
  node_api["HTTP application<br/>[app.ts]"]
  node_gameroutes["Session and quest routes<br/>[game.ts]"]
  node_audi_routes["Audio route<br/>[audio.ts]"]
  node_store[("Session store<br/>[session-store.ts]")]
  node_services["Service assembly<br/>[services.ts]"]
  node_dialogue["Dialogue providers<br/>[dialogue.ts]"]
  node_speech["Speech providers<br/>[speech.ts]"]
  node_livevoice["Live voice relay<br/>[relay.ts]"]
end

subgraph group_game["Game rules and content"]
  node_engine["Quest rules engine<br/>[index.ts]"]
  node_content["Missions and facts<br/>[missions.ts]"]
  node_contracts["Game contracts<br/>[contracts.ts]"]
end

subgraph group_city["Streamed city"]
  node_worldservice["World service<br/>[world-service.ts]"]
  node_citycomposer["AI city composer<br/>[claude-city.ts]"]
  node_cityplanner["City planning and validation<br/>[fallback.ts]"]
  node_citycontracts["City manifest contracts<br/>[contracts.ts]"]
end

subgraph group_language["Language tools"]
  node_dictionaryui["Dictionary interface<br/>[GlossPopover.tsx]"]
  node_dictionaryapi["Dictionary routes and lookup<br/>[router.ts]"]
  node_dictionarydata["Dictionary lookup data<br/>[dictionary.ts]"]
end

node_player(("Player"))

node_player -->|"plays"| node_webapp
node_webapp -->|"manages session"| node_sessionhook
node_sessionhook -->|"requests state"| node_sessionclient
node_sessionclient -->|"sends API requests"| node_api
node_api -->|"routes requests"| node_gameroutes
node_api -->|"mounts route"| node_audi_routes
node_gameroutes -->|"applies game rules"| node_engine
node_gameroutes -->|"reads and writes sessions"| node_store
node_engine -->|"uses missions"| node_content
node_engine -->|"validates state"| node_contracts
node_api -->|"creates services"| node_services
node_services -->|"creates store"| node_store
node_services -->|"creates provider"| node_dialogue
node_services -->|"creates provider"| node_speech
node_services -->|"creates world service"| node_worldservice
node_audi_routes -.->|"serves speech"| node_speech
node_webapp -->|"renders world"| node_worldview
node_worldview -->|"renders city chunks"| node_cityview
node_cityview -->|"requests streamed chunks"| node_worldservice
node_worldservice -->|"requests AI layouts"| node_citycomposer
node_worldservice -->|"plans fallback chunks"| node_cityplanner
node_cityplanner -->|"builds manifests"| node_citycontracts
node_audioplay -->|"fetches reply audio"| node_audi_routes
node_webapp -->|"plays NPC replies"| node_audioplay
node_webapp -->|"shows glosses"| node_dictionaryui
node_dictionaryui -->|"looks up text"| node_dictionaryapi
node_dictionaryapi -->|"segments and looks up"| node_dictionarydata
node_webapp -.->|"supports voice chat"| node_livevoice

click node_webapp "https://github.com/helenc3/hackru/blob/main/apps/web/src/app/App.tsx"
click node_sessionhook "https://github.com/helenc3/hackru/blob/main/apps/web/src/app/use-session.ts"
click node_sessionclient "https://github.com/helenc3/hackru/blob/main/apps/web/src/app/session-client.ts"
click node_worldview "https://github.com/helenc3/hackru/blob/main/apps/web/src/world/WorldRenderer.tsx"
click node_cityview "https://github.com/helenc3/hackru/blob/main/apps/web/src/city/ChunkRenderer.tsx"
click node_audioplay "https://github.com/helenc3/hackru/blob/main/apps/web/src/audio/AudioController.tsx"
click node_api "https://github.com/helenc3/hackru/blob/main/apps/server/src/app.ts"
click node_gameroutes "https://github.com/helenc3/hackru/blob/main/apps/server/src/routes/game.ts"
click node_audi_routes "https://github.com/helenc3/hackru/blob/main/apps/server/src/routes/audio.ts"
click node_store "https://github.com/helenc3/hackru/blob/main/apps/server/src/session-store.ts"
click node_services "https://github.com/helenc3/hackru/blob/main/apps/server/src/services.ts"
click node_dialogue "https://github.com/helenc3/hackru/blob/main/apps/server/src/providers/dialogue.ts"
click node_speech "https://github.com/helenc3/hackru/blob/main/apps/server/src/providers/speech.ts"
click node_engine "https://github.com/helenc3/hackru/blob/main/packages/shared/src/engine/index.ts"
click node_content "https://github.com/helenc3/hackru/blob/main/packages/shared/src/content/missions.ts"
click node_contracts "https://github.com/helenc3/hackru/blob/main/packages/shared/src/contracts.ts"
click node_worldservice "https://github.com/helenc3/hackru/blob/main/apps/server/src/city/world-service.ts"
click node_citycomposer "https://github.com/helenc3/hackru/blob/main/apps/server/src/city/claude-city.ts"
click node_cityplanner "https://github.com/helenc3/hackru/blob/main/packages/shared/src/city/fallback.ts"
click node_citycontracts "https://github.com/helenc3/hackru/blob/main/packages/shared/src/city/contracts.ts"
click node_dictionaryui "https://github.com/helenc3/hackru/blob/main/apps/web/src/dictionary/GlossPopover.tsx"
click node_dictionaryapi "https://github.com/helenc3/hackru/blob/main/apps/server/src/dictionary/router.ts"
click node_dictionarydata "https://github.com/helenc3/hackru/blob/main/apps/server/src/dictionary/dictionary.ts"
click node_livevoice "https://github.com/helenc3/hackru/blob/main/apps/server/src/live/relay.ts"

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_sessionhook,node_sessionclient,node_worldview,node_cityview,node_audioplay toneBlue
class node_api,node_gameroutes,node_audi_routes,node_store,node_services,node_dialogue,node_speech,node_livevoice toneAmber
class node_engine,node_content,node_contracts toneMint
class node_worldservice,node_citycomposer,node_cityplanner,node_citycontracts toneRose
class node_dictionaryui,node_dictionaryapi,node_dictionarydata,node_player toneIndigo
```

## Components

### Browser game

- [Game interface](https://github.com/helenc3/hackru/blob/main/apps/web/src/app/App.tsx): `apps/web/src/app/App.tsx`
- [Session state](https://github.com/helenc3/hackru/blob/main/apps/web/src/app/use-session.ts): `apps/web/src/app/use-session.ts`
- [Session API client](https://github.com/helenc3/hackru/blob/main/apps/web/src/app/session-client.ts): `apps/web/src/app/session-client.ts`
- [World renderer](https://github.com/helenc3/hackru/blob/main/apps/web/src/world/WorldRenderer.tsx): `apps/web/src/world/WorldRenderer.tsx`
- [Chunk streaming and render](https://github.com/helenc3/hackru/blob/main/apps/web/src/city/ChunkRenderer.tsx): `apps/web/src/city/ChunkRenderer.tsx`
- [Reply audio playback](https://github.com/helenc3/hackru/blob/main/apps/web/src/audio/AudioController.tsx): `apps/web/src/audio/AudioController.tsx`

### API and services

- [HTTP application](https://github.com/helenc3/hackru/blob/main/apps/server/src/app.ts): `apps/server/src/app.ts`
- [Session and quest routes](https://github.com/helenc3/hackru/blob/main/apps/server/src/routes/game.ts): `apps/server/src/routes/game.ts`
- [Audio route](https://github.com/helenc3/hackru/blob/main/apps/server/src/routes/audio.ts): `apps/server/src/routes/audio.ts`
- [Session store](https://github.com/helenc3/hackru/blob/main/apps/server/src/session-store.ts): `apps/server/src/session-store.ts`
- [Service assembly](https://github.com/helenc3/hackru/blob/main/apps/server/src/services.ts): `apps/server/src/services.ts`
- [Dialogue providers](https://github.com/helenc3/hackru/blob/main/apps/server/src/providers/dialogue.ts): `apps/server/src/providers/dialogue.ts`
- [Speech providers](https://github.com/helenc3/hackru/blob/main/apps/server/src/providers/speech.ts): `apps/server/src/providers/speech.ts`
- [Live voice relay](https://github.com/helenc3/hackru/blob/main/apps/server/src/live/relay.ts): `apps/server/src/live/relay.ts`

### Game rules and content

- [Quest rules engine](https://github.com/helenc3/hackru/blob/main/packages/shared/src/engine/index.ts): `packages/shared/src/engine/index.ts`
- [Missions and facts](https://github.com/helenc3/hackru/blob/main/packages/shared/src/content/missions.ts): `packages/shared/src/content/missions.ts`
- [Game contracts](https://github.com/helenc3/hackru/blob/main/packages/shared/src/contracts.ts): `packages/shared/src/contracts.ts`

### Streamed city

- [World service](https://github.com/helenc3/hackru/blob/main/apps/server/src/city/world-service.ts): `apps/server/src/city/world-service.ts`
- [AI city composer](https://github.com/helenc3/hackru/blob/main/apps/server/src/city/claude-city.ts): `apps/server/src/city/claude-city.ts`
- [City planning and validation](https://github.com/helenc3/hackru/blob/main/packages/shared/src/city/fallback.ts): `packages/shared/src/city/fallback.ts`
- [City manifest contracts](https://github.com/helenc3/hackru/blob/main/packages/shared/src/city/contracts.ts): `packages/shared/src/city/contracts.ts`

### Language tools

- [Dictionary interface](https://github.com/helenc3/hackru/blob/main/apps/web/src/dictionary/GlossPopover.tsx): `apps/web/src/dictionary/GlossPopover.tsx`
- [Dictionary routes and lookup](https://github.com/helenc3/hackru/blob/main/apps/server/src/dictionary/router.ts): `apps/server/src/dictionary/router.ts`
- [Dictionary lookup data](https://github.com/helenc3/hackru/blob/main/apps/server/src/dictionary/dictionary.ts): `apps/server/src/dictionary/dictionary.ts`

### Other components

- **Player**

## Connections

- Player → Game interface: plays
- Game interface → Session state: manages session (evidence: `apps/web/src/app/App.tsx`)
- Session state → Session API client: requests state (evidence: `apps/web/src/app/use-session.ts`)
- Session API client → HTTP application: sends API requests
- HTTP application → Session and quest routes: routes requests (evidence: `apps/server/src/app.ts`)
- HTTP application → Audio route: mounts route (evidence: `apps/server/src/app.ts`)
- Session and quest routes → Quest rules engine: applies game rules
- Session and quest routes → Session store: reads and writes sessions (evidence: `apps/server/src/routes/game.ts`)
- Quest rules engine → Missions and facts: uses missions (evidence: `packages/shared/src/engine/index.ts`)
- Quest rules engine → Game contracts: validates state (evidence: `packages/shared/src/engine/index.ts`)
- HTTP application → Service assembly: creates services (evidence: `apps/server/src/app.ts`)
- Service assembly → Session store: creates store (evidence: `apps/server/src/services.ts`)
- Service assembly → Dialogue providers: creates provider (evidence: `apps/server/src/services.ts`)
- Service assembly → Speech providers: creates provider (evidence: `apps/server/src/services.ts`)
- Service assembly → World service: creates world service (evidence: `apps/server/src/services.ts`)
- Audio route → Speech providers: serves speech
- Game interface → World renderer: renders world (evidence: `apps/web/src/app/App.tsx`)
- World renderer → Chunk streaming and render: renders city chunks (evidence: `apps/web/src/world/WorldRenderer.tsx`)
- Chunk streaming and render → World service: requests streamed chunks
- World service → AI city composer: requests AI layouts (evidence: `apps/server/src/city/world-service.ts`)
- World service → City planning and validation: plans fallback chunks (evidence: `apps/server/src/city/world-service.ts`)
- City planning and validation → City manifest contracts: builds manifests (evidence: `packages/shared/src/city/fallback.ts`)
- Reply audio playback → Audio route: fetches reply audio
- Game interface → Reply audio playback: plays NPC replies (evidence: `apps/web/src/app/App.tsx`)
- Game interface → Dictionary interface: shows glosses (evidence: `apps/web/src/app/App.tsx`)
- Dictionary interface → Dictionary routes and lookup: looks up text
- Dictionary routes and lookup → Dictionary lookup data: segments and looks up (evidence: `apps/server/src/dictionary/router.ts`)
- Game interface → Live voice relay: supports voice chat
