# prathamj2309/tutor_ai_model architecture

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

- Interactive diagram: https://gitdiagram.com/prathamj2309/tutor_ai_model
- Repository: https://github.com/prathamj2309/tutor_ai_model

## Overview

TutorAI is a personalized IIT-JEE learning platform whose main workflow is authenticated student questions—optionally with an image—through a React client and FastAPI API to OCR and subject-routed AI tutoring, with conversation history persisted in Supabase. Separate branches provide OCR, mock exams, and profile/weakness features documented in the README. The graph shows only source-supported calls; quiz, profile, and weakness internals are represented at their known router/service paths because their implementations were not sampled.

Main entry points: [`frontend/src/App.jsx`](https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/App.jsx) (Web application), [`backend/app/routers/chat.py`](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/routers/chat.py) (Chat endpoints), [`backend/app/middleware/auth.py`](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/middleware/auth.py) (Token verification), [`backend/app/routers/quiz.py`](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/routers/quiz.py) (Quiz endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Student experience"]
  node_webapp["Web application<br/>[App.jsx]"]
  node_authui["Sign-in UI<br/>[LoginPage.jsx]"]
  node_authhook["Auth session hook<br/>[useAuth.js]"]
  node_authstate["Auth state<br/>[authStore.js]"]
  node_chatui["Chat experience<br/>[ChatPage.jsx]"]
  node_chathook["Chat workflow<br/>[useChat.js]"]
  node_ocrui["Image question UI<br/>[OCRPage.jsx]"]
  node_quizui["Quiz experience<br/>[QuizPage.jsx]"]
  node_profileui["Profile and progress<br/>[ProfilePage.jsx]"]
end

subgraph group_api["API and identity"]
  node_apiapp["FastAPI application<br/>[main.py]"]
  node_authguard["Token verification<br/>[auth.py]"]
  node_chatroute["Chat endpoints<br/>[chat.py]"]
  node_ocrroute["OCR endpoint<br/>[ocr.py]"]
  node_quizroute["Quiz endpoints<br/>[quiz.py]"]
  node_profileroute["Profile endpoints<br/>[profile.py]"]
  node_schemas["API schemas<br/>[schemas.py]"]
end

subgraph group_tutoring["Tutoring and vision"]
  node_llm["Subject-routed tutor<br/>[llm_service.py]"]
  node_ocrservice["Image extraction service<br/>[ocr_service.py]"]
  node_visionmodel["Qwen image reader<br/>[main.py]"]
end

subgraph group_learning["Assessment and progress"]
  node_mocktest["Mock test generator"]
  node_weakness["Weakness analysis"]
end

subgraph group_state["Persistence and auth"]
  node_history["Conversation history<br/>[history_service.py]"]
  node_supabase["Supabase client<br/>[supabase_client.py]"]
end

node_student(("Student"))
node_supabaseauth["Supabase Auth"]
node_database[("Supabase database")]
node_externalmodels["Model providers"]

node_student -->|"uses"| node_webapp
node_webapp -->|"routes to"| node_authui
node_webapp -->|"routes to"| node_chatui
node_webapp -->|"routes to"| node_ocrui
node_webapp -->|"routes to"| node_quizui
node_webapp -->|"routes to"| node_profileui
node_webapp -->|"initializes"| node_authhook
node_authui -->|"uses"| node_authhook
node_authhook -->|"updates"| node_authstate
node_authhook -->|"authenticates with"| node_supabaseauth
node_chatui -->|"uses"| node_chathook
node_chathook -->|"sends requests"| node_chatroute
node_ocrui -->|"submits images"| node_ocrroute
node_quizui -.->|"uses"| node_quizroute
node_profileui -.->|"uses"| node_profileroute
node_apiapp -->|"registers"| node_chatroute
node_apiapp -->|"registers"| node_ocrroute
node_apiapp -->|"registers"| node_quizroute
node_apiapp -->|"registers"| node_profileroute
node_chatroute -->|"checks identity"| node_authguard
node_ocrroute -->|"checks identity"| node_authguard
node_quizroute -->|"checks identity"| node_authguard
node_profileroute -->|"checks identity"| node_authguard
node_authguard -->|"verifies token"| node_supabase
node_authguard -->|"creates profile"| node_database
node_chatroute -->|"requests answers"| node_llm
node_chatroute -->|"extracts image text"| node_ocrservice
node_ocrroute -->|"extracts image text"| node_ocrservice
node_ocrservice -->|"runs inference"| node_visionmodel
node_llm -->|"loads and generates"| node_externalmodels
node_chatroute -->|"loads and saves"| node_history
node_history -->|"queries"| node_supabase
node_supabase -.->|"reads and writes"| node_database
node_quizroute -->|"generates tests"| node_mocktest
node_quizroute -->|"uses progress"| node_weakness
node_profileroute -->|"loads progress"| node_weakness
node_profileroute -->|"queries profile"| node_supabase

click node_webapp "https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/App.jsx"
click node_authui "https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/components/auth/LoginPage.jsx"
click node_authhook "https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/hooks/useAuth.js"
click node_authstate "https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/store/authStore.js"
click node_chatui "https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/pages/ChatPage.jsx"
click node_chathook "https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/hooks/useChat.js"
click node_ocrui "https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/pages/OCRPage.jsx"
click node_quizui "https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/pages/QuizPage.jsx"
click node_profileui "https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/pages/ProfilePage.jsx"
click node_apiapp "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/main.py"
click node_authguard "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/middleware/auth.py"
click node_chatroute "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/routers/chat.py"
click node_ocrroute "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/routers/ocr.py"
click node_quizroute "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/routers/quiz.py"
click node_profileroute "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/routers/profile.py"
click node_schemas "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/models/schemas.py"
click node_llm "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/services/llm_service.py"
click node_ocrservice "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/services/ocr_service.py"
click node_visionmodel "https://github.com/prathamj2309/tutor_ai_model/blob/main/Image_To_Text_Classifier/main.py"
click node_mocktest "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/services/mock_test_service.py"
click node_weakness "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/services/weakness_service.py"
click node_history "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/services/history_service.py"
click node_supabase "https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/core/supabase_client.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_webapp,node_authui,node_authhook,node_authstate,node_chatui,node_chathook,node_ocrui,node_quizui,node_profileui toneBlue
class node_apiapp,node_authguard,node_chatroute,node_ocrroute,node_quizroute,node_profileroute,node_schemas,node_database toneAmber
class node_llm,node_ocrservice,node_visionmodel toneMint
class node_mocktest,node_weakness toneRose
class node_history,node_supabase,node_student,node_supabaseauth,node_externalmodels toneIndigo
```

## Components

### Student experience

- [Web application](https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Sign-in UI](https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/components/auth/LoginPage.jsx): `frontend/src/components/auth/LoginPage.jsx`
- [Auth session hook](https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/hooks/useAuth.js): `frontend/src/hooks/useAuth.js`
- [Auth state](https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/store/authStore.js): `frontend/src/store/authStore.js`
- [Chat experience](https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/pages/ChatPage.jsx): `frontend/src/pages/ChatPage.jsx`
- [Chat workflow](https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/hooks/useChat.js): `frontend/src/hooks/useChat.js`
- [Image question UI](https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/pages/OCRPage.jsx): `frontend/src/pages/OCRPage.jsx`
- [Quiz experience](https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/pages/QuizPage.jsx): `frontend/src/pages/QuizPage.jsx`
- [Profile and progress](https://github.com/prathamj2309/tutor_ai_model/blob/main/frontend/src/pages/ProfilePage.jsx): `frontend/src/pages/ProfilePage.jsx`

### API and identity

- [FastAPI application](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/main.py): `backend/app/main.py`
- [Token verification](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/middleware/auth.py): `backend/app/middleware/auth.py`
- [Chat endpoints](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/routers/chat.py): `backend/app/routers/chat.py`
- [OCR endpoint](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/routers/ocr.py): `backend/app/routers/ocr.py`
- [Quiz endpoints](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/routers/quiz.py): `backend/app/routers/quiz.py`
- [Profile endpoints](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/routers/profile.py): `backend/app/routers/profile.py`
- [API schemas](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/models/schemas.py): `backend/app/models/schemas.py`

### Tutoring and vision

- [Subject-routed tutor](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/services/llm_service.py): `backend/app/services/llm_service.py`
- [Image extraction service](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/services/ocr_service.py): `backend/app/services/ocr_service.py`
- [Qwen image reader](https://github.com/prathamj2309/tutor_ai_model/blob/main/Image_To_Text_Classifier/main.py): `Image_To_Text_Classifier/main.py`

### Assessment and progress

- [Mock test generator](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/services/mock_test_service.py): `backend/app/services/mock_test_service.py`
- [Weakness analysis](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/services/weakness_service.py): `backend/app/services/weakness_service.py`

### Persistence and auth

- [Conversation history](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/services/history_service.py): `backend/app/services/history_service.py`
- [Supabase client](https://github.com/prathamj2309/tutor_ai_model/blob/main/backend/app/core/supabase_client.py): `backend/app/core/supabase_client.py`

### Other components

- **Student**
- **Supabase Auth**
- **Supabase database**
- **Model providers**

## Connections

- Student → Web application: uses (evidence: `README.md`)
- Web application → Sign-in UI: routes to (evidence: `frontend/src/App.jsx`)
- Web application → Chat experience: routes to (evidence: `frontend/src/App.jsx`)
- Web application → Image question UI: routes to (evidence: `frontend/src/App.jsx`)
- Web application → Quiz experience: routes to (evidence: `frontend/src/App.jsx`)
- Web application → Profile and progress: routes to (evidence: `frontend/src/App.jsx`)
- Web application → Auth session hook: initializes (evidence: `frontend/src/App.jsx`)
- Sign-in UI → Auth session hook: uses (evidence: `frontend/src/components/auth/LoginPage.jsx`)
- Auth session hook → Auth state: updates (evidence: `frontend/src/hooks/useAuth.js`)
- Auth session hook → Supabase Auth: authenticates with (evidence: `frontend/src/hooks/useAuth.js`)
- Chat experience → Chat workflow: uses (evidence: `frontend/src/pages/ChatPage.jsx`)
- Chat workflow → Chat endpoints: sends requests (evidence: `frontend/src/hooks/useChat.js`)
- Image question UI → OCR endpoint: submits images (evidence: `frontend/src/pages/OCRPage.jsx`)
- Quiz experience → Quiz endpoints: uses
- Profile and progress → Profile endpoints: uses
- FastAPI application → Chat endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI application → OCR endpoint: registers (evidence: `backend/app/main.py`)
- FastAPI application → Quiz endpoints: registers (evidence: `backend/app/main.py`)
- FastAPI application → Profile endpoints: registers (evidence: `backend/app/main.py`)
- Chat endpoints → Token verification: checks identity (evidence: `backend/app/routers/chat.py`)
- OCR endpoint → Token verification: checks identity (evidence: `backend/app/routers/ocr.py`)
- Quiz endpoints → Token verification: checks identity (evidence: `backend/app/routers/quiz.py`)
- Profile endpoints → Token verification: checks identity (evidence: `backend/app/routers/profile.py`)
- Token verification → Supabase client: verifies token (evidence: `backend/app/middleware/auth.py`)
- Token verification → Supabase database: creates profile (evidence: `backend/app/middleware/auth.py`)
- Chat endpoints → Subject-routed tutor: requests answers (evidence: `backend/app/routers/chat.py`)
- Chat endpoints → Image extraction service: extracts image text (evidence: `backend/app/routers/chat.py`)
- OCR endpoint → Image extraction service: extracts image text (evidence: `backend/app/routers/ocr.py`)
- Image extraction service → Qwen image reader: runs inference (evidence: `backend/app/services/ocr_service.py`)
- Subject-routed tutor → Model providers: loads and generates (evidence: `backend/app/services/llm_service.py`)
- Chat endpoints → Conversation history: loads and saves (evidence: `backend/app/routers/chat.py`)
- Conversation history → Supabase client: queries (evidence: `backend/app/services/history_service.py`)
- Supabase client → Supabase database: reads and writes
- Quiz endpoints → Mock test generator: generates tests (evidence: `backend/app/routers/quiz.py`)
- Quiz endpoints → Weakness analysis: uses progress (evidence: `backend/app/routers/quiz.py`)
- Profile endpoints → Weakness analysis: loads progress (evidence: `backend/app/routers/profile.py`)
- Profile endpoints → Supabase client: queries profile (evidence: `backend/app/routers/profile.py`)
