# ozbaya/battle_of_the_books architecture

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

- Interactive diagram: https://gitdiagram.com/ozbaya/battle_of_the_books
- Repository: https://github.com/ozbaya/battle_of_the_books

## Overview

Battle of the Books Trainer lets an admin configure a team-versus-robots game, while players join from phones, buzz in, and submit spoken answers; a shared screen follows the round and a scores page reports results. Separate solo practice and title/author quiz modes use the same answer-evaluation capabilities, and practice scores feed the leaderboard. The team-game runtime advances state on requests and persists it through a selectable store. Relationships for unsampled pages and routes are included only where the README or source index documents them; not all route implementations were inspected.

Main entry points: [`src/app/api/games`](https://github.com/ozbaya/battle_of_the_books/tree/main/src/app/api/games) (Team Game API), [`src/lib/store/index.ts`](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/store/index.ts) (Game Store Facade), [`src/app/api/quiz/answer/route.ts`](https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/api/quiz/answer/route.ts) (Quiz Answer API), [`src/app/api/admin/games`](https://github.com/ozbaya/battle_of_the_books/tree/main/src/app/api/admin/games) (Admin Game API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_team["Team Game"]
  node_admin["Game Admin<br/>[page.tsx]"]
  node_player["Player Device<br/>[page.tsx]"]
  node_screen["Game Screen<br/>[page.tsx]"]
  node_scores["Game Scores<br/>[page.tsx]"]
  node_team_api["Team Game API"]
  node_admin_api["Admin Game API"]
  node_state_hook["Game State Poller<br/>[useGameState.ts]"]
  node_answer_ui["Answer Recording UI"]
  node_recorder["Audio Recorder<br/>[recorder.ts]"]
  node_engine["Game Engine<br/>[engine.ts]"]
  node_config["Game Rules<br/>[config.ts]"]
  node_admin_auth["Admin Authentication<br/>[admin-auth.ts]"]
end

subgraph group_solo["Solo Learning"]
  node_practice_page["Practice Page<br/>[page.tsx]"]
  node_practice_api["Practice Answer API<br/>[route.ts]"]
  node_practice_questions["Practice Question API<br/>[route.ts]"]
  node_quiz_page["Title And Author Quiz<br/>[page.tsx]"]
  node_quiz_api["Quiz Answer API<br/>[route.ts]"]
  node_quiz_bank["Quiz Bank<br/>[quiz.ts]"]
end

subgraph group_content["Questions And Judging"]
  node_questions["Question Sets<br/>[questions.ts]"]
  node_transcribe["Speech Transcription<br/>[transcribe.ts]"]
  node_judge["Answer Judge<br/>[judge.ts]"]
  node_scoring["Answer Scoring<br/>[scoring.ts]"]
end

subgraph group_state["State And Results"]
  node_store["Game Store Facade<br/>[index.ts]"]
  node_memory_store[("Memory Store<br/>[memory.ts]")]
  node_redis_store[("Redis Store<br/>[redis.ts]")]
  node_leaderboard["Leaderboard<br/>[leaderboard.ts]"]
  node_leaderboard_api["Leaderboard API<br/>[route.ts]"]
  node_usage["Usage Records<br/>[usage.ts]"]
  node_usage_api["Usage API<br/>[route.ts]"]
end

node_admin_actor(("Game Administrator"))
node_kids_actor(("Players"))
node_openai["OpenAI Services"]
node_redis[("Upstash Redis")]

node_admin_actor -->|"configures"| node_admin
node_admin -->|"creates games"| node_admin_api
node_admin_api -->|"checks access"| node_admin_auth
node_admin_api -->|"selects set"| node_questions
node_admin_api -->|"creates state"| node_engine
node_admin_api -->|"saves game"| node_store
node_kids_actor -->|"joins game"| node_player
node_player -->|"submits actions"| node_team_api
node_player -->|"polls state"| node_state_hook
node_state_hook -->|"requests state"| node_team_api
node_player -->|"records answer"| node_answer_ui
node_answer_ui -->|"captures audio"| node_recorder
node_team_api -->|"updates game"| node_store
node_store -->|"advances state"| node_engine
node_store -->|"uses fallback"| node_memory_store
node_store -->|"selects store"| node_redis_store
node_redis_store -.->|"persists state"| node_redis
node_team_api -->|"transcribes audio"| node_transcribe
node_team_api -->|"judges transcript"| node_judge
node_team_api -->|"loads questions"| node_questions
node_team_api -->|"applies judgment"| node_engine
node_transcribe -.->|"requests transcript"| node_openai
node_judge -.->|"requests grading"| node_openai
node_screen -.->|"polls state"| node_state_hook
node_scores -.->|"polls state"| node_state_hook
node_engine -->|"uses timings"| node_config
node_engine -->|"scores answers"| node_scoring
node_practice_page -.->|"loads questions"| node_practice_questions
node_practice_page -.->|"submits answers"| node_practice_api
node_practice_api -->|"resolves question"| node_questions
node_practice_api -->|"transcribes audio"| node_transcribe
node_practice_api -->|"judges answer"| node_judge
node_practice_api -->|"scores answer"| node_scoring
node_quiz_page -.->|"submits answers"| node_quiz_api
node_quiz_api -->|"loads entry"| node_quiz_bank
node_quiz_api -->|"builds hint"| node_questions
node_quiz_api -->|"transcribes audio"| node_transcribe
node_quiz_api -->|"judges answer"| node_judge
node_quiz_api -->|"scores answer"| node_scoring
node_leaderboard_api -->|"loads standings"| node_leaderboard
node_leaderboard -->|"weights sessions"| node_usage
node_leaderboard_api -->|"reads sessions"| node_store
node_usage_api -->|"validates logs"| node_usage
node_usage_api -->|"records sessions"| node_store

click node_admin "https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/admin/page.tsx"
click node_player "https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/play/%5Bcode%5D/page.tsx"
click node_screen "https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/screen/%5Bcode%5D/page.tsx"
click node_scores "https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/scores/%5Bcode%5D/page.tsx"
click node_team_api "https://github.com/ozbaya/battle_of_the_books/tree/main/src/app/api/games"
click node_admin_api "https://github.com/ozbaya/battle_of_the_books/tree/main/src/app/api/admin/games"
click node_state_hook "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/hooks/useGameState.ts"
click node_answer_ui "https://github.com/ozbaya/battle_of_the_books/blob/main/src/components/RealRecordingPanel.tsx"
click node_recorder "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/audio/recorder.ts"
click node_engine "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/game/engine.ts"
click node_config "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/game/config.ts"
click node_admin_auth "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/admin-auth.ts"
click node_practice_page "https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/practice/page.tsx"
click node_practice_api "https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/api/practice/answer/route.ts"
click node_practice_questions "https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/api/practice/questions/route.ts"
click node_quiz_page "https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/quiz/page.tsx"
click node_quiz_api "https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/api/quiz/answer/route.ts"
click node_quiz_bank "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/quiz.ts"
click node_questions "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/questions.ts"
click node_transcribe "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/ai/transcribe.ts"
click node_judge "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/ai/judge.ts"
click node_scoring "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/game/scoring.ts"
click node_store "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/store/index.ts"
click node_memory_store "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/store/memory.ts"
click node_redis_store "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/store/redis.ts"
click node_leaderboard "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/leaderboard.ts"
click node_leaderboard_api "https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/api/leaderboard/route.ts"
click node_usage "https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/usage.ts"
click node_usage_api "https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/api/usage/log/route.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_admin,node_player,node_screen,node_scores,node_team_api,node_admin_api,node_state_hook,node_answer_ui,node_recorder,node_engine,node_config,node_admin_auth toneBlue
class node_practice_page,node_practice_api,node_practice_questions,node_quiz_page,node_quiz_api,node_quiz_bank,node_redis toneAmber
class node_questions,node_transcribe,node_judge,node_scoring toneMint
class node_store,node_memory_store,node_redis_store,node_leaderboard,node_leaderboard_api,node_usage,node_usage_api toneRose
class node_admin_actor,node_kids_actor,node_openai toneIndigo
```

## Components

### Team Game

- [Game Admin](https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/admin/page.tsx): `src/app/admin/page.tsx`
- [Player Device](https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/play/%5Bcode%5D/page.tsx): `src/app/play/[code]/page.tsx`
- [Game Screen](https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/screen/%5Bcode%5D/page.tsx): `src/app/screen/[code]/page.tsx`
- [Game Scores](https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/scores/%5Bcode%5D/page.tsx): `src/app/scores/[code]/page.tsx`
- [Team Game API](https://github.com/ozbaya/battle_of_the_books/tree/main/src/app/api/games): `src/app/api/games`
- [Admin Game API](https://github.com/ozbaya/battle_of_the_books/tree/main/src/app/api/admin/games): `src/app/api/admin/games`
- [Game State Poller](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/hooks/useGameState.ts): `src/lib/hooks/useGameState.ts`
- [Answer Recording UI](https://github.com/ozbaya/battle_of_the_books/blob/main/src/components/RealRecordingPanel.tsx): `src/components/RealRecordingPanel.tsx`
- [Audio Recorder](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/audio/recorder.ts): `src/lib/audio/recorder.ts`
- [Game Engine](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/game/engine.ts): `src/lib/game/engine.ts`
- [Game Rules](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/game/config.ts): `src/lib/game/config.ts`
- [Admin Authentication](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/admin-auth.ts): `src/lib/admin-auth.ts`

### Solo Learning

- [Practice Page](https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/practice/page.tsx): `src/app/practice/page.tsx`
- [Practice Answer API](https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/api/practice/answer/route.ts): `src/app/api/practice/answer/route.ts`
- [Practice Question API](https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/api/practice/questions/route.ts): `src/app/api/practice/questions/route.ts`
- [Title And Author Quiz](https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/quiz/page.tsx): `src/app/quiz/page.tsx`
- [Quiz Answer API](https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/api/quiz/answer/route.ts): `src/app/api/quiz/answer/route.ts`
- [Quiz Bank](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/quiz.ts): `src/lib/quiz.ts`

### Questions And Judging

- [Question Sets](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/questions.ts): `src/lib/questions.ts`
- [Speech Transcription](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/ai/transcribe.ts): `src/lib/ai/transcribe.ts`
- [Answer Judge](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/ai/judge.ts): `src/lib/ai/judge.ts`
- [Answer Scoring](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/game/scoring.ts): `src/lib/game/scoring.ts`

### State And Results

- [Game Store Facade](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/store/index.ts): `src/lib/store/index.ts`
- [Memory Store](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/store/memory.ts): `src/lib/store/memory.ts`
- [Redis Store](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/store/redis.ts): `src/lib/store/redis.ts`
- [Leaderboard](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/leaderboard.ts): `src/lib/leaderboard.ts`
- [Leaderboard API](https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/api/leaderboard/route.ts): `src/app/api/leaderboard/route.ts`
- [Usage Records](https://github.com/ozbaya/battle_of_the_books/blob/main/src/lib/usage.ts): `src/lib/usage.ts`
- [Usage API](https://github.com/ozbaya/battle_of_the_books/blob/main/src/app/api/usage/log/route.ts): `src/app/api/usage/log/route.ts`

### Other components

- **Game Administrator**
- **Players**
- **OpenAI Services**
- **Upstash Redis**

## Connections

- Game Administrator → Game Admin: configures (evidence: `README.md`)
- Game Admin → Admin Game API: creates games (evidence: `README.md`)
- Admin Game API → Admin Authentication: checks access (evidence: `src/app/api/admin/games/route.ts`)
- Admin Game API → Question Sets: selects set (evidence: `src/app/api/admin/games/route.ts`)
- Admin Game API → Game Engine: creates state (evidence: `src/app/api/admin/games/route.ts`)
- Admin Game API → Game Store Facade: saves game (evidence: `src/app/api/admin/games/route.ts`)
- Players → Player Device: joins game (evidence: `README.md`)
- Player Device → Team Game API: submits actions (evidence: `README.md`)
- Player Device → Game State Poller: polls state (evidence: `src/lib/hooks/useGameState.ts`)
- Game State Poller → Team Game API: requests state (evidence: `src/lib/hooks/useGameState.ts`)
- Player Device → Answer Recording UI: records answer (evidence: `README.md`)
- Answer Recording UI → Audio Recorder: captures audio (evidence: `src/components/RealRecordingPanel.tsx`)
- Team Game API → Game Store Facade: updates game (evidence: `src/app/api/games/[code]/answer/route.ts`)
- Game Store Facade → Game Engine: advances state (evidence: `src/lib/store/index.ts`)
- Game Store Facade → Memory Store: uses fallback (evidence: `src/lib/store/index.ts`)
- Game Store Facade → Redis Store: selects store (evidence: `src/lib/store/index.ts`)
- Redis Store → Upstash Redis: persists state (evidence: `README.md`)
- Team Game API → Speech Transcription: transcribes audio (evidence: `src/app/api/games/[code]/answer/route.ts`)
- Team Game API → Answer Judge: judges transcript (evidence: `src/app/api/games/[code]/answer/route.ts`)
- Team Game API → Question Sets: loads questions (evidence: `src/app/api/games/[code]/answer/route.ts`)
- Team Game API → Game Engine: applies judgment (evidence: `src/app/api/games/[code]/answer/route.ts`)
- Speech Transcription → OpenAI Services: requests transcript (evidence: `README.md`)
- Answer Judge → OpenAI Services: requests grading (evidence: `README.md`)
- Game Screen → Game State Poller: polls state (evidence: `README.md`)
- Game Scores → Game State Poller: polls state (evidence: `README.md`)
- Game Engine → Game Rules: uses timings (evidence: `src/lib/game/engine.ts`)
- Game Engine → Answer Scoring: scores answers (evidence: `src/lib/game/engine.ts`)
- Practice Page → Practice Question API: loads questions (evidence: `README.md`)
- Practice Page → Practice Answer API: submits answers (evidence: `README.md`)
- Practice Answer API → Question Sets: resolves question (evidence: `src/app/api/practice/answer/route.ts`)
- Practice Answer API → Speech Transcription: transcribes audio (evidence: `src/app/api/practice/answer/route.ts`)
- Practice Answer API → Answer Judge: judges answer (evidence: `src/app/api/practice/answer/route.ts`)
- Practice Answer API → Answer Scoring: scores answer (evidence: `src/app/api/practice/answer/route.ts`)
- Title And Author Quiz → Quiz Answer API: submits answers (evidence: `README.md`)
- Quiz Answer API → Quiz Bank: loads entry (evidence: `src/app/api/quiz/answer/route.ts`)
- Quiz Answer API → Question Sets: builds hint (evidence: `src/app/api/quiz/answer/route.ts`)
- Quiz Answer API → Speech Transcription: transcribes audio (evidence: `src/app/api/quiz/answer/route.ts`)
- Quiz Answer API → Answer Judge: judges answer (evidence: `src/app/api/quiz/answer/route.ts`)
- Quiz Answer API → Answer Scoring: scores answer (evidence: `src/app/api/quiz/answer/route.ts`)
- Leaderboard API → Leaderboard: loads standings (evidence: `src/app/api/leaderboard/route.ts`)
- Leaderboard → Usage Records: weights sessions (evidence: `src/lib/leaderboard.ts`)
- Leaderboard API → Game Store Facade: reads sessions (evidence: `src/app/api/leaderboard/route.ts`)
- Usage API → Usage Records: validates logs (evidence: `src/app/api/usage/log/route.ts`)
- Usage API → Game Store Facade: records sessions (evidence: `src/app/api/usage/log/route.ts`)
