# kubellingham/study-kube architecture

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

## Overview

Studying Kube turns student-provided course materials into structured subjects for guided study. The main workflow is material intake, AI-assisted course building, then learning through lessons and practice; the README also describes exams, flashcards, glossary, mistakes review, and an in-lesson tutor. Billing, access control, and crew membership support those learning capabilities. Several UI and API paths are represented from the tree and README, but their implementation was not sampled; uncertain connections are omitted or marked unverified.

Main entry points: [`app/api/course/ingest/route.ts`](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/api/course/ingest/route.ts) (Course ingestion), [`app/learn/[courseId]/page.tsx`](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/%5BcourseId%5D/page.tsx) (Course workspace), [`lib/entitlement-server.ts`](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/entitlement-server.ts) (Server access checks), [`lib/firebase/admin.ts`](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/firebase/admin.ts) (Server Firebase)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_intake["Course intake"]
  node_material_ui["Add material<br/>[AddMaterial.tsx]"]
  node_ingest["Course ingestion<br/>[route.ts]"]
  node_extract["Material extraction<br/>[client-extract.ts]"]
  node_generation["Course generation<br/>[generate.ts]"]
  node_verification["Lesson verification<br/>[verify.ts]"]
  node_course_types["Course model<br/>[types.ts]"]
  node_registry["Course registry<br/>[index.ts]"]
end

subgraph group_learning["Learning experience"]
  node_learn_home["Course shelf<br/>[page.tsx]"]
  node_course_page["Course workspace<br/>[page.tsx]"]
  node_lesson_page["Lessons and tutor<br/>[page.tsx]"]
  node_practice_page["Practice gym<br/>[page.tsx]"]
  node_exam_page["Mock exams<br/>[page.tsx]"]
  node_flashcards["Flashcards<br/>[route.ts]"]
  node_learning_records["Learning progress<br/>[progress.ts]"]
  node_mistakes["Mistakes review<br/>[mistakes.ts]"]
  node_glossary["Glossary<br/>[glossary.ts]"]
  node_chat_api["Tutor chat API<br/>[route.ts]"]
end

subgraph group_platform["Platform services"]
  node_ai_provider["OpenRouter client<br/>[openrouter.ts]"]
  node_firebase_client[("Client Firebase<br/>[client.ts]")]
  node_firebase_admin[("Server Firebase<br/>[admin.ts]")]
  node_api_auth["API authentication<br/>[api-helpers.ts]"]
  node_usage["AI usage meter<br/>[usage.ts]"]
  node_spend["Spend limits<br/>[spend.ts]"]
end

subgraph group_commercial["Access and billing"]
  node_entitlement_server["Server access checks"]
  node_entitlement["Entitlement policy<br/>[entitlement.ts]"]
  node_stripe_webhook["Subscription updates<br/>[route.ts]"]
  node_crew["Crew membership<br/>[crew.ts]"]
end

node_student(("Student"))

node_student -->|"provides materials"| node_material_ui
node_material_ui -.->|"submits upload"| node_ingest
node_ingest -->|"builds course"| node_generation
node_ingest -->|"verifies lessons"| node_verification
node_generation -->|"calls model"| node_ai_provider
node_ingest -.->|"stores course"| node_firebase_admin
node_ingest -.->|"extracts content"| node_extract
node_learn_home -->|"reads courses"| node_firebase_client
node_learn_home -->|"loads progress"| node_learning_records
node_course_page -->|"reads course data"| node_firebase_client
node_course_page -->|"uses progress"| node_learning_records
node_course_page -->|"uses review data"| node_mistakes
node_course_page -.->|"uses course terms"| node_glossary
node_student -->|"practices topics"| node_practice_page
node_student -->|"takes exams"| node_exam_page
node_student -->|"reviews cards"| node_flashcards
node_student -->|"studies lessons"| node_lesson_page
node_student -->|"asks tutor"| node_chat_api
node_chat_api -->|"checks access"| node_entitlement_server
node_chat_api -.->|"requests response"| node_ai_provider
node_entitlement_server -->|"authenticates user"| node_api_auth
node_entitlement_server -->|"reads grants"| node_firebase_admin
node_entitlement_server -->|"resolves tier"| node_entitlement
node_stripe_webhook -->|"updates records"| node_firebase_admin
node_stripe_webhook -->|"updates access"| node_entitlement
node_stripe_webhook -->|"updates crew"| node_crew
node_spend -->|"checks usage"| node_firebase_admin
node_spend -->|"checks tier"| node_entitlement

click node_material_ui "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/components/AddMaterial.tsx"
click node_ingest "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/api/course/ingest/route.ts"
click node_extract "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/ingest/client-extract.ts"
click node_generation "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/course/generate.ts"
click node_verification "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/course/verify.ts"
click node_course_types "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/course/types.ts"
click node_registry "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/course/index.ts"
click node_ai_provider "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/openrouter.ts"
click node_learn_home "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/page.tsx"
click node_course_page "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/%5BcourseId%5D/page.tsx"
click node_lesson_page "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/%5BcourseId%5D/lesson/%5BtopicId%5D/page.tsx"
click node_practice_page "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/%5BcourseId%5D/practice/page.tsx"
click node_exam_page "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/%5BcourseId%5D/exam/page.tsx"
click node_flashcards "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/api/course/flashcards/route.ts"
click node_learning_records "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/learn/progress.ts"
click node_mistakes "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/learn/mistakes.ts"
click node_glossary "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/learn/glossary.ts"
click node_chat_api "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/api/learn/chat/route.ts"
click node_firebase_client "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/firebase/client.ts"
click node_firebase_admin "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/firebase/admin.ts"
click node_api_auth "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/api-helpers.ts"
click node_entitlement_server "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/entitlement-server.ts"
click node_entitlement "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/entitlement.ts"
click node_usage "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/usage.ts"
click node_spend "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/spend.ts"
click node_stripe_webhook "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/api/stripe/webhook/route.ts"
click node_crew "https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/crew.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_material_ui,node_ingest,node_extract,node_generation,node_verification,node_course_types,node_registry toneBlue
class node_learn_home,node_course_page,node_lesson_page,node_practice_page,node_exam_page,node_flashcards,node_learning_records,node_mistakes,node_glossary,node_chat_api toneAmber
class node_ai_provider,node_firebase_client,node_firebase_admin,node_api_auth,node_usage,node_spend toneMint
class node_entitlement_server,node_entitlement,node_stripe_webhook,node_crew toneRose
class node_student toneIndigo
```

## Components

### Course intake

- [Add material](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/components/AddMaterial.tsx): `app/learn/components/AddMaterial.tsx`
- [Course ingestion](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/api/course/ingest/route.ts): `app/api/course/ingest/route.ts`
- [Material extraction](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/ingest/client-extract.ts): `lib/ingest/client-extract.ts`
- [Course generation](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/course/generate.ts): `lib/course/generate.ts`
- [Lesson verification](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/course/verify.ts): `lib/course/verify.ts`
- [Course model](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/course/types.ts): `lib/course/types.ts`
- [Course registry](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/course/index.ts): `lib/course/index.ts`

### Learning experience

- [Course shelf](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/page.tsx): `app/learn/page.tsx`
- [Course workspace](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/%5BcourseId%5D/page.tsx): `app/learn/[courseId]/page.tsx`
- [Lessons and tutor](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/%5BcourseId%5D/lesson/%5BtopicId%5D/page.tsx): `app/learn/[courseId]/lesson/[topicId]/page.tsx`
- [Practice gym](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/%5BcourseId%5D/practice/page.tsx): `app/learn/[courseId]/practice/page.tsx`
- [Mock exams](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/learn/%5BcourseId%5D/exam/page.tsx): `app/learn/[courseId]/exam/page.tsx`
- [Flashcards](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/api/course/flashcards/route.ts): `app/api/course/flashcards/route.ts`
- [Learning progress](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/learn/progress.ts): `lib/learn/progress.ts`
- [Mistakes review](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/learn/mistakes.ts): `lib/learn/mistakes.ts`
- [Glossary](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/learn/glossary.ts): `lib/learn/glossary.ts`
- [Tutor chat API](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/api/learn/chat/route.ts): `app/api/learn/chat/route.ts`

### Platform services

- [OpenRouter client](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/openrouter.ts): `lib/openrouter.ts`
- [Client Firebase](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/firebase/client.ts): `lib/firebase/client.ts`
- [Server Firebase](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/firebase/admin.ts): `lib/firebase/admin.ts`
- [API authentication](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/api-helpers.ts): `lib/api-helpers.ts`
- [AI usage meter](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/usage.ts): `lib/usage.ts`
- [Spend limits](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/spend.ts): `lib/spend.ts`

### Access and billing

- [Server access checks](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/entitlement-server.ts): `lib/entitlement-server.ts`
- [Entitlement policy](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/entitlement.ts): `lib/entitlement.ts`
- [Subscription updates](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/app/api/stripe/webhook/route.ts): `app/api/stripe/webhook/route.ts`
- [Crew membership](https://github.com/kubellingham/study-kube/blob/claude/studying-kube-tool-yrybsj/lib/crew.ts): `lib/crew.ts`

### Other components

- **Student**

## Connections

- Student → Add material: provides materials (evidence: `README.md`)
- Add material → Course ingestion: submits upload
- Course ingestion → Course generation: builds course (evidence: `app/api/course/ingest/route.ts`)
- Course ingestion → Lesson verification: verifies lessons (evidence: `app/api/course/ingest/route.ts`)
- Course generation → OpenRouter client: calls model (evidence: `lib/course/generate.ts`)
- Course ingestion → Server Firebase: stores course (evidence: `app/api/course/ingest/route.ts`)
- Course ingestion → Material extraction: extracts content
- Course shelf → Client Firebase: reads courses (evidence: `app/learn/page.tsx`)
- Course shelf → Learning progress: loads progress (evidence: `app/learn/page.tsx`)
- Course workspace → Client Firebase: reads course data (evidence: `app/learn/[courseId]/page.tsx`)
- Course workspace → Learning progress: uses progress (evidence: `app/learn/[courseId]/page.tsx`)
- Course workspace → Mistakes review: uses review data (evidence: `app/learn/[courseId]/page.tsx`)
- Course workspace → Glossary: uses course terms
- Student → Practice gym: practices topics (evidence: `README.md`)
- Student → Mock exams: takes exams (evidence: `README.md`)
- Student → Flashcards: reviews cards (evidence: `README.md`)
- Student → Lessons and tutor: studies lessons (evidence: `README.md`)
- Student → Tutor chat API: asks tutor (evidence: `README.md`)
- Tutor chat API → Server access checks: checks access (evidence: `app/api/learn/chat/route.ts`)
- Tutor chat API → OpenRouter client: requests response (evidence: `app/api/learn/chat/route.ts`)
- Server access checks → API authentication: authenticates user (evidence: `lib/entitlement-server.ts`)
- Server access checks → Server Firebase: reads grants (evidence: `lib/entitlement-server.ts`)
- Server access checks → Entitlement policy: resolves tier (evidence: `lib/entitlement-server.ts`)
- Subscription updates → Server Firebase: updates records (evidence: `app/api/stripe/webhook/route.ts`)
- Subscription updates → Entitlement policy: updates access (evidence: `app/api/stripe/webhook/route.ts`)
- Subscription updates → Crew membership: updates crew (evidence: `app/api/stripe/webhook/route.ts`)
- Spend limits → Server Firebase: checks usage (evidence: `lib/spend.ts`)
- Spend limits → Entitlement policy: checks tier (evidence: `lib/spend.ts`)
