# boyedandtoyed/studyai architecture

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

- Interactive diagram: https://gitdiagram.com/boyedandtoyed/studyai
- Repository: https://github.com/boyedandtoyed/studyai

## Overview

StudyAI is a PDF-based study assistant. A student uploads notes; the backend indexes their content, then uses retrieval-augmented generation to answer questions with source context. The API also handles accounts, document and study-history operations, and quiz/flashcard features. The main internal layers are the FastAPI application, the RAG engine, and per-user persistence. The README documents PDF text and diagram processing, vector search, and model use; unsampled route implementations are represented only where documented.

Main entry points: [`main_fastapi.py`](https://github.com/boyedandtoyed/studyai/blob/main/main_fastapi.py) (FastAPI routes), [`gg.py`](https://github.com/boyedandtoyed/studyai/blob/main/gg.py) (PDF ingestion), [`backend/user_store.py`](https://github.com/boyedandtoyed/studyai/blob/main/backend/user_store.py) (Account and history), [`backend/db.py`](https://github.com/boyedandtoyed/studyai/blob/main/backend/db.py) (Relational database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Backend API"]
  node_fastapi["FastAPI routes<br/>[main_fastapi.py]"]
end

subgraph group_rag["RAG and Study"]
  node_ingest["PDF ingestion<br/>[gg.py]"]
  node_retrieve["Context retrieval<br/>[gg.py]"]
  node_answer["Answer generation<br/>[gg.py]"]
  node_studygen["Quiz and cards<br/>[gg.py]"]
  node_chroma[("Vector index<br/>[gg.py]")]
end

subgraph group_storage["User Storage"]
  node_userstore["Account and history<br/>[user_store.py]"]
  node_sqlite[("Relational database<br/>[db.py]")]
end

subgraph group_models["AI Models"]
  node_ollama["Ollama models"]
  node_openrouter["OpenRouter models"]
end

node_student(("Student"))

node_student -->|"uses API"| node_fastapi
node_fastapi -->|"indexes uploads"| node_ingest
node_fastapi -->|"requests context"| node_retrieve
node_retrieve -->|"searches chunks"| node_chroma
node_ingest -->|"stores vectors"| node_chroma
node_ingest -->|"embeds content"| node_ollama
node_ingest -->|"describes diagrams"| node_ollama
node_fastapi -.->|"generates response"| node_answer
node_answer -->|"calls model"| node_ollama
node_answer -->|"calls model"| node_openrouter
node_fastapi -.->|"requests study sets"| node_studygen
node_studygen -->|"uses context"| node_retrieve
node_fastapi -->|"reads and updates"| node_userstore
node_userstore -->|"reads and writes"| node_sqlite

click node_fastapi "https://github.com/boyedandtoyed/studyai/blob/main/main_fastapi.py"
click node_ingest "https://github.com/boyedandtoyed/studyai/blob/main/gg.py"
click node_retrieve "https://github.com/boyedandtoyed/studyai/blob/main/gg.py"
click node_answer "https://github.com/boyedandtoyed/studyai/blob/main/gg.py"
click node_studygen "https://github.com/boyedandtoyed/studyai/blob/main/gg.py"
click node_chroma "https://github.com/boyedandtoyed/studyai/blob/main/gg.py"
click node_userstore "https://github.com/boyedandtoyed/studyai/blob/main/backend/user_store.py"
click node_sqlite "https://github.com/boyedandtoyed/studyai/blob/main/backend/db.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_fastapi toneBlue
class node_ingest,node_retrieve,node_answer,node_studygen,node_chroma toneAmber
class node_userstore,node_sqlite toneMint
class node_ollama,node_openrouter toneRose
class node_student toneIndigo
```

## Components

### Backend API

- [FastAPI routes](https://github.com/boyedandtoyed/studyai/blob/main/main_fastapi.py): `main_fastapi.py`

### RAG and Study

- [PDF ingestion](https://github.com/boyedandtoyed/studyai/blob/main/gg.py): `gg.py`
- [Context retrieval](https://github.com/boyedandtoyed/studyai/blob/main/gg.py): `gg.py`
- [Answer generation](https://github.com/boyedandtoyed/studyai/blob/main/gg.py): `gg.py`
- [Quiz and cards](https://github.com/boyedandtoyed/studyai/blob/main/gg.py): `gg.py`
- [Vector index](https://github.com/boyedandtoyed/studyai/blob/main/gg.py): `gg.py`

### User Storage

- [Account and history](https://github.com/boyedandtoyed/studyai/blob/main/backend/user_store.py): `backend/user_store.py`
- [Relational database](https://github.com/boyedandtoyed/studyai/blob/main/backend/db.py): `backend/db.py`

### AI Models

- **Ollama models**
- **OpenRouter models**

### Other components

- **Student**

## Connections

- Student → FastAPI routes: uses API (evidence: `README.md`)
- FastAPI routes → PDF ingestion: indexes uploads (evidence: `README.md`)
- FastAPI routes → Context retrieval: requests context (evidence: `main_fastapi.py`)
- Context retrieval → Vector index: searches chunks (evidence: `README.md`)
- PDF ingestion → Vector index: stores vectors (evidence: `README.md`)
- PDF ingestion → Ollama models: embeds content (evidence: `README.md`)
- PDF ingestion → Ollama models: describes diagrams (evidence: `gg.py`)
- FastAPI routes → Answer generation: generates response (evidence: `main_fastapi.py`)
- Answer generation → Ollama models: calls model (evidence: `gg.py`)
- Answer generation → OpenRouter models: calls model (evidence: `gg.py`)
- FastAPI routes → Quiz and cards: requests study sets (evidence: `main_fastapi.py`)
- Quiz and cards → Context retrieval: uses context (evidence: `gg.py`)
- FastAPI routes → Account and history: reads and updates (evidence: `main_fastapi.py`)
- Account and history → Relational database: reads and writes (evidence: `backend/user_store.py`)
