# aestheticsuraj234/ai-study-buddy-build architecture

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

- Interactive diagram: https://gitdiagram.com/aestheticsuraj234/ai-study-buddy-build
- Repository: https://github.com/aestheticsuraj234/ai-study-buddy-build

## Overview

AI Study Buddy is an Expo study app backed by a TypeScript API. Users create study sets, add notes, PDFs, or web sources, then use the resulting material for chat, summaries, and flashcards. The graph follows the evidenced client actions and API routes into ingestion and retrieval, and includes authentication, billing, and data access. Some screens and server route implementations were not excerpted; their links are included only where the source index records references, and uncertain connections are omitted.

Main entry points: [`server/src/lib/supabase.ts`](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/lib/supabase.ts) (Server Supabase), [`server/src/index.ts`](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/index.ts) (API Server), [`server/src/lib/ai.ts`](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/lib/ai.ts) (AI Models), [`server/src/service/ingest.ts`](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/service/ingest.ts) (Source Ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Study App"]
  node_study_ui["Study Screens"]
  node_library_ui["Study Set Library<br/>[index.tsx]"]
  node_empty["Empty State<br/>[empty-state.tsx]"]
end

subgraph group_study["Study Features"]
  node_study_actions["Study Set Actions<br/>[actions.ts]"]
  node_study_queries["Study Set Queries<br/>[query.ts]"]
  node_source_upload["Source Upload<br/>[source.ts]"]
  node_client_api["API Client<br/>[api-client.ts]"]
  node_client_supabase["Client Supabase<br/>[supabase.ts]"]
end

subgraph group_api["API and AI"]
  node_api_server["API Server<br/>[index.ts]"]
  node_auth_middleware["Token Auth<br/>[auth.ts]"]
  node_source_routes["Source Routes<br/>[sources.ts]"]
  node_chat_routes["Chat Route<br/>[chat.ts]"]
  node_summary_routes["Summary Route<br/>[summaries.ts]"]
  node_flashcard_routes["Flashcard Route<br/>[flashcards.ts]"]
  node_ingestion["Source Ingestion<br/>[ingest.ts]"]
  node_pdf["PDF Extraction<br/>[pdf.ts]"]
  node_web["Web Extraction<br/>[web.ts]"]
  node_rag["Context Retrieval<br/>[rag.ts]"]
  node_ai_models["AI Models<br/>[ai.ts]"]
  node_server_supabase["Server Supabase<br/>[supabase.ts]"]
  node_env["Server Settings<br/>[env.ts]"]
end

subgraph group_account["Identity and Billing"]
  node_auth_ui["Auth Screens and State<br/>[auth.tsx]"]
  node_subscription["Subscription State"]
  node_purchases["Purchase Operations<br/>[purchases.ts]"]
  node_billing_config["Billing Config<br/>[billing.ts]"]
end

node_learner(("Learner"))
node_supabase_store[("Supabase Data")]
node_openai["OpenAI"]
node_revenuecat["RevenueCat"]

node_learner -.->|"uses"| node_study_ui
node_learner -.->|"uses"| node_library_ui
node_study_ui -.->|"invokes"| node_study_actions
node_study_ui -.->|"queries"| node_study_queries
node_library_ui -->|"queries"| node_study_queries
node_library_ui -->|"invokes"| node_study_actions
node_library_ui -->|"renders"| node_empty
node_study_actions -->|"reads and writes"| node_client_supabase
node_study_actions -->|"uploads PDF"| node_source_upload
node_study_actions -->|"processes sources"| node_client_api
node_study_queries -->|"reads"| node_client_supabase
node_client_supabase -.->|"accesses"| node_supabase_store
node_client_api -->|"gets token"| node_auth_ui
node_client_api -->|"gets session"| node_client_supabase
node_client_api -->|"posts requests"| node_api_server
node_api_server -->|"registers"| node_auth_middleware
node_api_server -->|"registers"| node_source_routes
node_api_server -->|"registers"| node_chat_routes
node_api_server -->|"registers"| node_summary_routes
node_api_server -->|"registers"| node_flashcard_routes
node_source_routes -->|"invokes"| node_ingestion
node_ingestion -->|"extracts PDF"| node_pdf
node_ingestion -->|"fetches web text"| node_web
node_ingestion -->|"embeds chunks"| node_ai_models
node_ingestion -->|"stores chunks"| node_server_supabase
node_chat_routes -->|"retrieves context"| node_rag
node_chat_routes -->|"generates reply"| node_ai_models
node_chat_routes -->|"reads and writes"| node_server_supabase
node_summary_routes -->|"retrieves context"| node_rag
node_summary_routes -->|"generates summary"| node_ai_models
node_summary_routes -->|"reads and writes"| node_server_supabase
node_flashcard_routes -->|"retrieves context"| node_rag
node_flashcard_routes -->|"generates cards"| node_ai_models
node_flashcard_routes -->|"reads and writes"| node_server_supabase
node_rag -->|"embeds query"| node_ai_models
node_rag -->|"searches chunks"| node_server_supabase
node_server_supabase -.->|"accesses"| node_supabase_store
node_auth_middleware -->|"validates token"| node_server_supabase
node_ai_models -->|"reads settings"| node_env
node_server_supabase -->|"reads settings"| node_env
node_subscription -->|"gets user"| node_auth_ui
node_subscription -->|"manages purchases"| node_purchases
node_subscription -.->|"checks entitlement"| node_revenuecat
node_purchases -->|"uses config"| node_billing_config

click node_study_ui "https://github.com/aestheticsuraj234/ai-study-buddy-build/tree/master/src/app/(app)/(tabs)/(library)"
click node_library_ui "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/app/(app)/(tabs)/(library)/index.tsx"
click node_empty "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/components/empty-state.tsx"
click node_study_actions "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/features/study-sets/actions.ts"
click node_study_queries "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/features/study-sets/query.ts"
click node_source_upload "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/lib/source.ts"
click node_client_api "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/lib/api-client.ts"
click node_auth_ui "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/features/auth/auth.tsx"
click node_client_supabase "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/utils/supabase.ts"
click node_subscription "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/features/billing/use-subscription.ts"
click node_purchases "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/features/billing/purchases.ts"
click node_billing_config "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/lib/billing.ts"
click node_api_server "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/index.ts"
click node_auth_middleware "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/middleware/auth.ts"
click node_source_routes "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/routes/sources.ts"
click node_chat_routes "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/routes/chat.ts"
click node_summary_routes "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/routes/summaries.ts"
click node_flashcard_routes "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/routes/flashcards.ts"
click node_ingestion "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/service/ingest.ts"
click node_pdf "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/service/pdf.ts"
click node_web "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/service/web.ts"
click node_rag "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/service/rag.ts"
click node_ai_models "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/lib/ai.ts"
click node_server_supabase "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/lib/supabase.ts"
click node_env "https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/env.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_study_ui,node_library_ui,node_empty toneBlue
class node_study_actions,node_study_queries,node_source_upload,node_client_api,node_client_supabase,node_supabase_store toneAmber
class node_api_server,node_auth_middleware,node_source_routes,node_chat_routes,node_summary_routes,node_flashcard_routes,node_ingestion,node_pdf,node_web,node_rag,node_ai_models,node_server_supabase,node_env toneMint
class node_auth_ui,node_subscription,node_purchases,node_billing_config toneRose
class node_learner,node_openai,node_revenuecat toneIndigo
```

## Components

### Study App

- [Study Screens](https://github.com/aestheticsuraj234/ai-study-buddy-build/tree/master/src/app/(app)/(tabs)/(library)): `src/app/(app)/(tabs)/(library)`
- [Study Set Library](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/app/(app)/(tabs)/(library)/index.tsx): `src/app/(app)/(tabs)/(library)/index.tsx`
- [Empty State](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/components/empty-state.tsx): `src/components/empty-state.tsx`

### Study Features

- [Study Set Actions](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/features/study-sets/actions.ts): `src/features/study-sets/actions.ts`
- [Study Set Queries](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/features/study-sets/query.ts): `src/features/study-sets/query.ts`
- [Source Upload](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/lib/source.ts): `src/lib/source.ts`
- [API Client](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/lib/api-client.ts): `src/lib/api-client.ts`
- [Client Supabase](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/utils/supabase.ts): `src/utils/supabase.ts`

### API and AI

- [API Server](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/index.ts): `server/src/index.ts`
- [Token Auth](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/middleware/auth.ts): `server/src/middleware/auth.ts`
- [Source Routes](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/routes/sources.ts): `server/src/routes/sources.ts`
- [Chat Route](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/routes/chat.ts): `server/src/routes/chat.ts`
- [Summary Route](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/routes/summaries.ts): `server/src/routes/summaries.ts`
- [Flashcard Route](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/routes/flashcards.ts): `server/src/routes/flashcards.ts`
- [Source Ingestion](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/service/ingest.ts): `server/src/service/ingest.ts`
- [PDF Extraction](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/service/pdf.ts): `server/src/service/pdf.ts`
- [Web Extraction](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/service/web.ts): `server/src/service/web.ts`
- [Context Retrieval](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/service/rag.ts): `server/src/service/rag.ts`
- [AI Models](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/lib/ai.ts): `server/src/lib/ai.ts`
- [Server Supabase](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/lib/supabase.ts): `server/src/lib/supabase.ts`
- [Server Settings](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/server/src/env.ts): `server/src/env.ts`

### Identity and Billing

- [Auth Screens and State](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/features/auth/auth.tsx): `src/features/auth/auth.tsx`
- [Subscription State](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/features/billing/use-subscription.ts): `src/features/billing/use-subscription.ts`
- [Purchase Operations](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/features/billing/purchases.ts): `src/features/billing/purchases.ts`
- [Billing Config](https://github.com/aestheticsuraj234/ai-study-buddy-build/blob/master/src/lib/billing.ts): `src/lib/billing.ts`

### Other components

- **Learner**
- **Supabase Data**
- **OpenAI**
- **RevenueCat**

## Connections

- Learner → Study Screens: uses
- Learner → Study Set Library: uses
- Study Screens → Study Set Actions: invokes (evidence: `src/app/(app)/(tabs)/(library)/[studySetId]/index.tsx`)
- Study Screens → Study Set Queries: queries (evidence: `src/app/(app)/(tabs)/(library)/[studySetId]/index.tsx`)
- Study Set Library → Study Set Queries: queries (evidence: `src/app/(app)/(tabs)/(library)/index.tsx`)
- Study Set Library → Study Set Actions: invokes (evidence: `src/app/(app)/(tabs)/(library)/index.tsx`)
- Study Set Library → Empty State: renders (evidence: `src/app/(app)/(tabs)/(library)/index.tsx`)
- Study Set Actions → Client Supabase: reads and writes (evidence: `src/features/study-sets/actions.ts`)
- Study Set Actions → Source Upload: uploads PDF (evidence: `src/features/study-sets/actions.ts`)
- Study Set Actions → API Client: processes sources (evidence: `src/features/study-sets/actions.ts`)
- Study Set Queries → Client Supabase: reads (evidence: `src/features/study-sets/query.ts`)
- Client Supabase → Supabase Data: accesses
- API Client → Auth Screens and State: gets token (evidence: `src/lib/api-client.ts`)
- API Client → Client Supabase: gets session (evidence: `src/lib/api-client.ts`)
- API Client → API Server: posts requests (evidence: `src/lib/api-client.ts`)
- API Server → Token Auth: registers (evidence: `server/src/index.ts`)
- API Server → Source Routes: registers (evidence: `server/src/index.ts`)
- API Server → Chat Route: registers (evidence: `server/src/index.ts`)
- API Server → Summary Route: registers (evidence: `server/src/index.ts`)
- API Server → Flashcard Route: registers (evidence: `server/src/index.ts`)
- Source Routes → Source Ingestion: invokes (evidence: `server/src/routes/sources.ts`)
- Source Ingestion → PDF Extraction: extracts PDF (evidence: `server/src/service/ingest.ts`)
- Source Ingestion → Web Extraction: fetches web text (evidence: `server/src/service/ingest.ts`)
- Source Ingestion → AI Models: embeds chunks (evidence: `server/src/service/ingest.ts`)
- Source Ingestion → Server Supabase: stores chunks (evidence: `server/src/service/ingest.ts`)
- Chat Route → Context Retrieval: retrieves context (evidence: `server/src/routes/chat.ts`)
- Chat Route → AI Models: generates reply (evidence: `server/src/routes/chat.ts`)
- Chat Route → Server Supabase: reads and writes (evidence: `server/src/routes/chat.ts`)
- Summary Route → Context Retrieval: retrieves context (evidence: `server/src/routes/summaries.ts`)
- Summary Route → AI Models: generates summary (evidence: `server/src/routes/summaries.ts`)
- Summary Route → Server Supabase: reads and writes (evidence: `server/src/routes/summaries.ts`)
- Flashcard Route → Context Retrieval: retrieves context (evidence: `server/src/routes/flashcards.ts`)
- Flashcard Route → AI Models: generates cards (evidence: `server/src/routes/flashcards.ts`)
- Flashcard Route → Server Supabase: reads and writes (evidence: `server/src/routes/flashcards.ts`)
- Context Retrieval → AI Models: embeds query (evidence: `server/src/service/rag.ts`)
- Context Retrieval → Server Supabase: searches chunks (evidence: `server/src/service/rag.ts`)
- Server Supabase → Supabase Data: accesses
- Token Auth → Server Supabase: validates token (evidence: `server/src/middleware/auth.ts`)
- AI Models → Server Settings: reads settings (evidence: `server/src/lib/ai.ts`)
- Server Supabase → Server Settings: reads settings (evidence: `server/src/lib/supabase.ts`)
- Subscription State → Auth Screens and State: gets user (evidence: `src/features/billing/use-subscription.ts`)
- Subscription State → Purchase Operations: manages purchases (evidence: `src/features/billing/use-subscription.ts`)
- Subscription State → RevenueCat: checks entitlement
- Purchase Operations → Billing Config: uses config (evidence: `src/features/billing/purchases.ts`)
