# techwithtim/choose-your-own-adventure-ai architecture

> Architecture diagram of the GitHub repository techwithtim/choose-your-own-adventure-ai, 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/techwithtim/choose-your-own-adventure-ai
- Repository: https://github.com/techwithtim/choose-your-own-adventure-ai

## Overview

This is an interactive, choose-your-own-adventure story generator: a user submits a theme, the backend creates a background job and generates a branching story, and the frontend presents the resulting story. The graph separates the frontend experience, API workflow, generation logic, and persistence. Evidence is strongest for job creation, generation, and story retrieval; the story-viewing component’s fetch details were not excerpted, so that link is shown as unverified.

Main entry points: [`backend/routers/story.py`](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/routers/story.py) (Story endpoints), [`frontend/src/components/StoryGenerator.jsx`](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/components/StoryGenerator.jsx) (Story generator UI), [`backend/core/story_generator.py`](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/core/story_generator.py) (Story generator), [`backend/main.py`](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/main.py) (FastAPI app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Story experience"]
  node_app["App routing<br/>[App.jsx]"]
  node_theme["Theme input<br/>[ThemeInput.jsx]"]
  node_generator_ui["Story generator UI<br/>[StoryGenerator.jsx]"]
  node_loading["Loading status<br/>[LoadingStatus.jsx]"]
  node_loader["Story loader<br/>[StoryLoader.jsx]"]
  node_game["Story game<br/>[StoryGame.jsx]"]
  node_api_client["API URL config<br/>[util.js]"]
end

subgraph group_api["API workflow"]
  node_api_app["FastAPI app<br/>[main.py]"]
  node_story_api["Story endpoints<br/>[story.py]"]
  node_job_api["Job status endpoint<br/>[job.py]"]
  node_story_schema["Story schemas<br/>[story.py]"]
  node_job_schema["Job schemas<br/>[job.py]"]
end

subgraph group_generation["Story generation"]
  node_generator["Story generator<br/>[story_generator.py]"]
  node_prompts["Story prompt<br/>[prompts.py]"]
  node_llm_models["LLM response models<br/>[models.py]"]
end

subgraph group_persistence["Persistence"]
  node_database_config["Database session<br/>[database.py]"]
  node_story_model["Story records<br/>[story.py]"]
  node_job_model["Job records<br/>[job.py]"]
  node_store[("SQL database<br/>[database.py]")]
end

node_user(("Reader"))
node_llm{{"OpenAI-compatible LLM"}}

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_generator_ui
node_app -->|"routes to"| node_loader
node_generator_ui -->|"renders"| node_theme
node_generator_ui -->|"renders"| node_loading
node_generator_ui -->|"uses"| node_api_client
node_generator_ui -->|"requests story and job status"| node_api_app
node_loader -->|"renders"| node_game
node_loader -->|"renders"| node_loading
node_loader -.->|"fetches story"| node_api_app
node_api_app -->|"registers"| node_story_api
node_api_app -->|"registers"| node_job_api
node_api_app -->|"creates tables"| node_database_config
node_story_api -->|"creates and updates"| node_job_model
node_story_api -->|"queries and returns"| node_story_model
node_story_api -->|"generates story"| node_generator
node_story_api -->|"validates and responds"| node_story_schema
node_story_api -->|"responds with"| node_job_schema
node_job_api -->|"queries"| node_job_model
node_job_api -->|"responds with"| node_job_schema
node_generator -->|"uses prompt"| node_prompts
node_generator -->|"parses output"| node_llm_models
node_generator -->|"persists story nodes"| node_story_model
node_generator -->|"invokes"| node_llm
node_story_model -->|"uses base"| node_database_config
node_job_model -->|"uses base"| node_database_config
node_database_config -->|"connects"| node_store

click node_app "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/App.jsx"
click node_theme "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/components/ThemeInput.jsx"
click node_generator_ui "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/components/StoryGenerator.jsx"
click node_loading "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/components/LoadingStatus.jsx"
click node_loader "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/components/StoryLoader.jsx"
click node_game "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/components/StoryGame.jsx"
click node_api_client "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/util.js"
click node_api_app "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/main.py"
click node_story_api "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/routers/story.py"
click node_job_api "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/routers/job.py"
click node_story_schema "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/schemas/story.py"
click node_job_schema "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/schemas/job.py"
click node_generator "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/core/story_generator.py"
click node_prompts "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/core/prompts.py"
click node_llm_models "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/core/models.py"
click node_database_config "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/db/database.py"
click node_story_model "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/models/story.py"
click node_job_model "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/models/job.py"
click node_store "https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/db/database.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_app,node_theme,node_generator_ui,node_loading,node_loader,node_game,node_api_client toneBlue
class node_api_app,node_story_api,node_job_api,node_story_schema,node_job_schema toneAmber
class node_generator,node_prompts,node_llm_models toneMint
class node_database_config,node_story_model,node_job_model,node_store toneRose
class node_user,node_llm toneIndigo
```

## Components

### Story experience

- [App routing](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Theme input](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/components/ThemeInput.jsx): `frontend/src/components/ThemeInput.jsx`
- [Story generator UI](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/components/StoryGenerator.jsx): `frontend/src/components/StoryGenerator.jsx`
- [Loading status](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/components/LoadingStatus.jsx): `frontend/src/components/LoadingStatus.jsx`
- [Story loader](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/components/StoryLoader.jsx): `frontend/src/components/StoryLoader.jsx`
- [Story game](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/components/StoryGame.jsx): `frontend/src/components/StoryGame.jsx`
- [API URL config](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/frontend/src/util.js): `frontend/src/util.js`

### API workflow

- [FastAPI app](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/main.py): `backend/main.py`
- [Story endpoints](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/routers/story.py): `backend/routers/story.py`
- [Job status endpoint](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/routers/job.py): `backend/routers/job.py`
- [Story schemas](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/schemas/story.py): `backend/schemas/story.py`
- [Job schemas](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/schemas/job.py): `backend/schemas/job.py`

### Story generation

- [Story generator](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/core/story_generator.py): `backend/core/story_generator.py`
- [Story prompt](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/core/prompts.py): `backend/core/prompts.py`
- [LLM response models](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/core/models.py): `backend/core/models.py`

### Persistence

- [Database session](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/db/database.py): `backend/db/database.py`
- [Story records](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/models/story.py): `backend/models/story.py`
- [Job records](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/models/job.py): `backend/models/job.py`
- [SQL database](https://github.com/techwithtim/choose-your-own-adventure-ai/blob/main/backend/db/database.py): `backend/db/database.py`

### Other components

- **Reader**
- **OpenAI-compatible LLM**

## Connections

- Reader → App routing: uses (evidence: `frontend/src/App.jsx`)
- App routing → Story generator UI: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Story loader: routes to (evidence: `frontend/src/App.jsx`)
- Story generator UI → Theme input: renders (evidence: `frontend/src/components/StoryGenerator.jsx`)
- Story generator UI → Loading status: renders (evidence: `frontend/src/components/StoryGenerator.jsx`)
- Story generator UI → API URL config: uses (evidence: `frontend/src/components/StoryGenerator.jsx`)
- Story generator UI → FastAPI app: requests story and job status (evidence: `frontend/src/components/StoryGenerator.jsx`)
- Story loader → Story game: renders (evidence: `frontend/src/components/StoryLoader.jsx`)
- Story loader → Loading status: renders (evidence: `frontend/src/components/StoryLoader.jsx`)
- Story loader → FastAPI app: fetches story
- FastAPI app → Story endpoints: registers (evidence: `backend/main.py`)
- FastAPI app → Job status endpoint: registers (evidence: `backend/main.py`)
- FastAPI app → Database session: creates tables (evidence: `backend/main.py`)
- Story endpoints → Job records: creates and updates (evidence: `backend/routers/story.py`)
- Story endpoints → Story records: queries and returns (evidence: `backend/routers/story.py`)
- Story endpoints → Story generator: generates story (evidence: `backend/routers/story.py`)
- Story endpoints → Story schemas: validates and responds (evidence: `backend/routers/story.py`)
- Story endpoints → Job schemas: responds with (evidence: `backend/routers/story.py`)
- Job status endpoint → Job records: queries (evidence: `backend/routers/job.py`)
- Job status endpoint → Job schemas: responds with (evidence: `backend/routers/job.py`)
- Story generator → Story prompt: uses prompt (evidence: `backend/core/story_generator.py`)
- Story generator → LLM response models: parses output (evidence: `backend/core/story_generator.py`)
- Story generator → Story records: persists story nodes (evidence: `backend/core/story_generator.py`)
- Story generator → OpenAI-compatible LLM: invokes (evidence: `backend/core/story_generator.py`)
- Story records → Database session: uses base (evidence: `backend/models/story.py`)
- Job records → Database session: uses base (evidence: `backend/models/job.py`)
- Database session → SQL database: connects (evidence: `backend/db/database.py`)
