# sobbify/ai-tutor architecture

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

- Interactive diagram: https://gitdiagram.com/sobbify/ai-tutor
- Repository: https://github.com/sobbify/ai-tutor

## Overview

ELSA is a private English-speaking tutor for teachers. Learners enter through the host app, follow a 15-day journey or rehearse on demand, learn a moment, practise with an AI parent, and review feedback and progress. The graph also preserves stories, phrasebook, groups, and the admin console. Several backend routes and frontend screens are documented but unsampled; those links cite the README, while internal service links use the source index or excerpts as evidence.

Main entry points: [`src/features/journey/JourneyPage.tsx`](https://github.com/sobbify/ai-tutor/blob/main/src/features/journey/JourneyPage.tsx) (Journey and home), [`src/features/conversation/useConversation.ts`](https://github.com/sobbify/ai-tutor/blob/main/src/features/conversation/useConversation.ts) (Conversation control), [`src/features/conversation/ConversationPage.tsx`](https://github.com/sobbify/ai-tutor/blob/main/src/features/conversation/ConversationPage.tsx) (Role-play screen), [`backend/src/ai_tutor/services/content.py`](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/content.py) (Practice content)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_learner["Learner experience"]
  node_app["Learner app<br/>[App.tsx]"]
  node_journey["Journey and home<br/>[JourneyPage.tsx]"]
  node_learn["Learn moment<br/>[LearnPage.tsx]"]
  node_progress["Progress and certificate<br/>[ProgressPage.tsx]"]
  node_phrasebook["Phrasebook<br/>[PhrasebookPage.tsx]"]
  node_groups["Practice groups<br/>[GroupPage.tsx]"]
  node_stories["Tell a story<br/>[StoryPage.tsx]"]
  node_button["Shared UI button<br/>[Button.tsx]"]
  node_icons["Shared UI icons<br/>[Icons.tsx]"]
end

subgraph group_practice["Practice and feedback"]
  node_conversation["Role-play screen"]
  node_conversation_logic["Conversation control<br/>[useConversation.ts]"]
  node_live_reply["Live reply capture<br/>[useLiveReply.ts]"]
  node_recorder["Audio recorder<br/>[useRecorder.ts]"]
  node_bubbles["Chat and feedback<br/>[ChatBubbles.tsx]"]
  node_queries["Learner data queries<br/>[queries.ts]"]
  node_api_types["Tutor API contract<br/>[types.ts]"]
end

subgraph group_backend["Tutor backend"]
  node_backend_app["FastAPI application<br/>[main.py]"]
  node_practice_ws["Practice websocket<br/>[practice_ws.py]"]
  node_journey_service["Journey service<br/>[journey.py]"]
  node_content["Practice content<br/>[content.py]"]
  node_listen["Speech listener<br/>[listen.py]"]
  node_audio["Audio processing<br/>[audio.py]"]
  node_evaluator["Reply evaluator<br/>[evaluator.py]"]
  node_voice["Tutor voice<br/>[voice.py]"]
  node_keys["Gemini key pool<br/>[keys.py]"]
  node_models[("Persistent domain models<br/>[models.py]")]
  node_schemas["Domain schemas<br/>[schemas.py]"]
end

subgraph group_operations["Admin and operations"]
  node_admin["Admin console<br/>[AdminApp.tsx]"]
  node_admin_api["Admin API client<br/>[api.ts]"]
  node_admin_routes["Admin endpoints<br/>[admin.py]"]
  node_admin_service["Admin operations<br/>[admin.py]"]
  node_content_editor["Moment editor<br/>[MomentEditor.tsx]"]
end

node_teacher(("Teacher"))
node_host["Buddy's World host"]

node_host -->|"opens signed link"| node_backend_app
node_backend_app -->|"sets session"| node_teacher
node_teacher -->|"uses"| node_app
node_app -->|"routes to"| node_journey
node_app -->|"routes to"| node_conversation
node_journey -->|"starts lesson"| node_learn
node_learn -->|"continues to"| node_conversation
node_journey -->|"offers progress"| node_progress
node_journey -->|"offers phrasebook"| node_phrasebook
node_journey -->|"offers groups"| node_groups
node_journey -->|"offers stories"| node_stories
node_conversation -->|"uses"| node_conversation_logic
node_conversation_logic -->|"loads run data"| node_queries
node_conversation_logic -->|"captures live reply"| node_live_reply
node_conversation_logic -->|"uses fallback"| node_recorder
node_conversation -->|"renders transcript"| node_bubbles
node_queries -->|"uses API contract"| node_api_types
node_live_reply -->|"streams practice audio"| node_practice_ws
node_backend_app -.->|"serves practice"| node_practice_ws
node_practice_ws -.->|"handles speech"| node_listen
node_listen -->|"uses audio processing"| node_audio
node_listen -->|"requests evaluation"| node_evaluator
node_evaluator -->|"selects credentials"| node_keys
node_journey_service -->|"loads content"| node_content
node_journey_service -->|"evaluates replies"| node_evaluator
node_voice -->|"uses audio"| node_audio
node_voice -->|"loads content"| node_content
node_voice -->|"uses credentials"| node_keys
node_content -->|"reads domain records"| node_models
node_content -->|"validates content"| node_schemas
node_admin -->|"uses"| node_admin_api
node_content_editor -->|"saves content"| node_admin_api
node_admin_api -.->|"calls admin API"| node_admin_routes
node_admin_routes -.->|"delegates operations"| node_admin_service
node_admin_service -.->|"manages records"| node_models

click node_app "https://github.com/sobbify/ai-tutor/blob/main/src/app/App.tsx"
click node_journey "https://github.com/sobbify/ai-tutor/blob/main/src/features/journey/JourneyPage.tsx"
click node_learn "https://github.com/sobbify/ai-tutor/blob/main/src/features/learn/LearnPage.tsx"
click node_progress "https://github.com/sobbify/ai-tutor/blob/main/src/features/progress/ProgressPage.tsx"
click node_phrasebook "https://github.com/sobbify/ai-tutor/blob/main/src/features/phrasebook/PhrasebookPage.tsx"
click node_groups "https://github.com/sobbify/ai-tutor/blob/main/src/features/group/GroupPage.tsx"
click node_stories "https://github.com/sobbify/ai-tutor/blob/main/src/features/story/StoryPage.tsx"
click node_conversation "https://github.com/sobbify/ai-tutor/blob/main/src/features/conversation/ConversationPage.tsx"
click node_conversation_logic "https://github.com/sobbify/ai-tutor/blob/main/src/features/conversation/useConversation.ts"
click node_live_reply "https://github.com/sobbify/ai-tutor/blob/main/src/hooks/useLiveReply.ts"
click node_recorder "https://github.com/sobbify/ai-tutor/blob/main/src/hooks/useRecorder.ts"
click node_bubbles "https://github.com/sobbify/ai-tutor/blob/main/src/features/conversation/ChatBubbles.tsx"
click node_queries "https://github.com/sobbify/ai-tutor/blob/main/src/hooks/queries.ts"
click node_api_types "https://github.com/sobbify/ai-tutor/blob/main/src/api/types.ts"
click node_backend_app "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/main.py"
click node_practice_ws "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/api/practice_ws.py"
click node_journey_service "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/journey.py"
click node_content "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/content.py"
click node_listen "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/listen.py"
click node_audio "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/audio.py"
click node_evaluator "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/evaluator.py"
click node_voice "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/voice.py"
click node_keys "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/keys.py"
click node_models "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/models.py"
click node_admin "https://github.com/sobbify/ai-tutor/blob/main/src/admin/AdminApp.tsx"
click node_admin_api "https://github.com/sobbify/ai-tutor/blob/main/src/admin/api.ts"
click node_admin_routes "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/api/admin.py"
click node_admin_service "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/admin.py"
click node_content_editor "https://github.com/sobbify/ai-tutor/blob/main/src/admin/pages/MomentEditor.tsx"
click node_button "https://github.com/sobbify/ai-tutor/blob/main/src/components/ui/Button.tsx"
click node_icons "https://github.com/sobbify/ai-tutor/blob/main/src/components/ui/Icons.tsx"
click node_schemas "https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/schemas.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_journey,node_learn,node_progress,node_phrasebook,node_groups,node_stories,node_button,node_icons toneBlue
class node_conversation,node_conversation_logic,node_live_reply,node_recorder,node_bubbles,node_queries,node_api_types toneAmber
class node_backend_app,node_practice_ws,node_journey_service,node_content,node_listen,node_audio,node_evaluator,node_voice,node_keys,node_models,node_schemas toneMint
class node_admin,node_admin_api,node_admin_routes,node_admin_service,node_content_editor toneRose
class node_teacher,node_host toneIndigo
```

## Components

### Learner experience

- [Learner app](https://github.com/sobbify/ai-tutor/blob/main/src/app/App.tsx): `src/app/App.tsx`
- [Journey and home](https://github.com/sobbify/ai-tutor/blob/main/src/features/journey/JourneyPage.tsx): `src/features/journey/JourneyPage.tsx`
- [Learn moment](https://github.com/sobbify/ai-tutor/blob/main/src/features/learn/LearnPage.tsx): `src/features/learn/LearnPage.tsx`
- [Progress and certificate](https://github.com/sobbify/ai-tutor/blob/main/src/features/progress/ProgressPage.tsx): `src/features/progress/ProgressPage.tsx`
- [Phrasebook](https://github.com/sobbify/ai-tutor/blob/main/src/features/phrasebook/PhrasebookPage.tsx): `src/features/phrasebook/PhrasebookPage.tsx`
- [Practice groups](https://github.com/sobbify/ai-tutor/blob/main/src/features/group/GroupPage.tsx): `src/features/group/GroupPage.tsx`
- [Tell a story](https://github.com/sobbify/ai-tutor/blob/main/src/features/story/StoryPage.tsx): `src/features/story/StoryPage.tsx`
- [Shared UI button](https://github.com/sobbify/ai-tutor/blob/main/src/components/ui/Button.tsx): `src/components/ui/Button.tsx`
- [Shared UI icons](https://github.com/sobbify/ai-tutor/blob/main/src/components/ui/Icons.tsx): `src/components/ui/Icons.tsx`

### Practice and feedback

- [Role-play screen](https://github.com/sobbify/ai-tutor/blob/main/src/features/conversation/ConversationPage.tsx): `src/features/conversation/ConversationPage.tsx`
- [Conversation control](https://github.com/sobbify/ai-tutor/blob/main/src/features/conversation/useConversation.ts): `src/features/conversation/useConversation.ts`
- [Live reply capture](https://github.com/sobbify/ai-tutor/blob/main/src/hooks/useLiveReply.ts): `src/hooks/useLiveReply.ts`
- [Audio recorder](https://github.com/sobbify/ai-tutor/blob/main/src/hooks/useRecorder.ts): `src/hooks/useRecorder.ts`
- [Chat and feedback](https://github.com/sobbify/ai-tutor/blob/main/src/features/conversation/ChatBubbles.tsx): `src/features/conversation/ChatBubbles.tsx`
- [Learner data queries](https://github.com/sobbify/ai-tutor/blob/main/src/hooks/queries.ts): `src/hooks/queries.ts`
- [Tutor API contract](https://github.com/sobbify/ai-tutor/blob/main/src/api/types.ts): `src/api/types.ts`

### Tutor backend

- [FastAPI application](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/main.py): `backend/src/ai_tutor/main.py`
- [Practice websocket](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/api/practice_ws.py): `backend/src/ai_tutor/api/practice_ws.py`
- [Journey service](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/journey.py): `backend/src/ai_tutor/services/journey.py`
- [Practice content](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/content.py): `backend/src/ai_tutor/services/content.py`
- [Speech listener](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/listen.py): `backend/src/ai_tutor/services/listen.py`
- [Audio processing](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/audio.py): `backend/src/ai_tutor/services/audio.py`
- [Reply evaluator](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/evaluator.py): `backend/src/ai_tutor/services/evaluator.py`
- [Tutor voice](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/voice.py): `backend/src/ai_tutor/services/voice.py`
- [Gemini key pool](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/keys.py): `backend/src/ai_tutor/services/keys.py`
- [Persistent domain models](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/models.py): `backend/src/ai_tutor/models.py`
- [Domain schemas](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/schemas.py): `backend/src/ai_tutor/schemas.py`

### Admin and operations

- [Admin console](https://github.com/sobbify/ai-tutor/blob/main/src/admin/AdminApp.tsx): `src/admin/AdminApp.tsx`
- [Admin API client](https://github.com/sobbify/ai-tutor/blob/main/src/admin/api.ts): `src/admin/api.ts`
- [Admin endpoints](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/api/admin.py): `backend/src/ai_tutor/api/admin.py`
- [Admin operations](https://github.com/sobbify/ai-tutor/blob/main/backend/src/ai_tutor/services/admin.py): `backend/src/ai_tutor/services/admin.py`
- [Moment editor](https://github.com/sobbify/ai-tutor/blob/main/src/admin/pages/MomentEditor.tsx): `src/admin/pages/MomentEditor.tsx`

### Other components

- **Teacher**
- **Buddy's World host**

## Connections

- Buddy's World host → FastAPI application: opens signed link
- FastAPI application → Teacher: sets session
- Teacher → Learner app: uses
- Learner app → Journey and home: routes to
- Learner app → Role-play screen: routes to
- Journey and home → Learn moment: starts lesson
- Learn moment → Role-play screen: continues to
- Journey and home → Progress and certificate: offers progress
- Journey and home → Phrasebook: offers phrasebook
- Journey and home → Practice groups: offers groups
- Journey and home → Tell a story: offers stories
- Role-play screen → Conversation control: uses
- Conversation control → Learner data queries: loads run data (evidence: `src/features/conversation/useConversation.ts`)
- Conversation control → Live reply capture: captures live reply (evidence: `src/features/conversation/useConversation.ts`)
- Conversation control → Audio recorder: uses fallback (evidence: `src/features/conversation/useConversation.ts`)
- Role-play screen → Chat and feedback: renders transcript
- Learner data queries → Tutor API contract: uses API contract (evidence: `src/hooks/queries.ts`)
- Live reply capture → Practice websocket: streams practice audio
- FastAPI application → Practice websocket: serves practice (evidence: `backend/src/ai_tutor/main.py`)
- Practice websocket → Speech listener: handles speech
- Speech listener → Audio processing: uses audio processing (evidence: `backend/src/ai_tutor/services/listen.py`)
- Speech listener → Reply evaluator: requests evaluation (evidence: `backend/src/ai_tutor/services/listen.py`)
- Reply evaluator → Gemini key pool: selects credentials (evidence: `backend/src/ai_tutor/services/evaluator.py`)
- Journey service → Practice content: loads content (evidence: `backend/src/ai_tutor/services/journey.py`)
- Journey service → Reply evaluator: evaluates replies (evidence: `backend/src/ai_tutor/services/journey.py`)
- Tutor voice → Audio processing: uses audio (evidence: `backend/src/ai_tutor/services/voice.py`)
- Tutor voice → Practice content: loads content (evidence: `backend/src/ai_tutor/services/voice.py`)
- Tutor voice → Gemini key pool: uses credentials (evidence: `backend/src/ai_tutor/services/voice.py`)
- Practice content → Persistent domain models: reads domain records (evidence: `backend/src/ai_tutor/services/content.py`)
- Practice content → Domain schemas: validates content (evidence: `backend/src/ai_tutor/services/content.py`)
- Admin console → Admin API client: uses
- Moment editor → Admin API client: saves content (evidence: `src/admin/pages/MomentEditor.tsx`)
- Admin API client → Admin endpoints: calls admin API
- Admin endpoints → Admin operations: delegates operations
- Admin operations → Persistent domain models: manages records
