# sand-box-dev/notepad-ai architecture

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

- Interactive diagram: https://gitdiagram.com/sand-box-dev/notepad-ai
- Repository: https://github.com/sand-box-dev/notepad-ai

## Overview

Notepad AI turns uploaded learning documents into locally grounded concept maps, cited chat, and study materials. The main user flow is authenticate, upload/select a document, process its passages, then explore the resulting map, ask streaming questions, or generate quizzes, flashcards, and essay tasks. The graph also includes project/workspace navigation and the offline-first authentication, database failover, and sync layers. Some route and UI links are documented or indexed but not excerpted; those relationships are identified by their available evidence rather than inferred from naming alone.

Main entry points: [`backend/app/main.py`](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/main.py) (FastAPI app), [`backend/app/database.py`](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/database.py) (DB failover), [`frontend/src/pages/Workspace.tsx`](https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/pages/Workspace.tsx) (Workspace), [`frontend/src/services/api.ts`](https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/services/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Workspace client"]
  node_app["App shell<br/>[App.tsx]"]
  node_workspace["Workspace<br/>[Workspace.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
  node_reviewer_chat["Reviewer chat<br/>[ReviewerChat.tsx]"]
  node_concept_map["Concept map<br/>[ConceptMap.tsx]"]
  node_study_mode["Study mode<br/>[StudyMode.tsx]"]
  node_cover_storage[("Cover storage<br/>[coverStorage.ts]")]
end

subgraph group_api["API and domain workflows"]
  node_fastapi["FastAPI app<br/>[main.py]"]
  node_document_routes["Document routes<br/>[documents.py]"]
  node_chat_routes["Chat routes<br/>[chat.py]"]
  node_concept_routes["Concept routes<br/>[concepts.py]"]
  node_study_routes["Study routes<br/>[study.py]"]
  node_project_routes["Project routes<br/>[projects.py]"]
end

subgraph group_ai["Local AI processing"]
  node_document_service["Document processing"]
  node_vector_service["Passage vectors<br/>[vector_service.py]"]
  node_concept_service["Concept extraction<br/>[concept_service.py]"]
  node_chat_service["Grounded chat<br/>[chat_service.py]"]
  node_study_service["Study generation<br/>[study_service.py]"]
  node_ollama{{"Ollama model"}}
end

subgraph group_state["Persistence and sync"]
  node_database["DB failover<br/>[database.py]"]
  node_models["Domain records<br/>[models.py]"]
  node_sync_service["Cloud sync<br/>[sync_service.py]"]
  node_postgres[("Supabase Postgres")]
  node_sqlite[("Offline SQLite")]
end

subgraph group_identity["Identity"]
  node_auth_routes["Auth routes<br/>[auth.py]"]
  node_auth_service["Online auth<br/>[auth.py]"]
  node_offline_auth[("Offline credentials<br/>[offline_auth.py]")]
end

node_user(("Learner"))

node_user -->|"uses"| node_app
node_app -->|"opens workspace"| node_workspace
node_app -->|"checks session"| node_api_client
node_workspace -->|"requests data"| node_api_client
node_workspace -->|"renders"| node_reviewer_chat
node_workspace -->|"renders"| node_concept_map
node_workspace -->|"renders"| node_study_mode
node_workspace -->|"removes cover"| node_cover_storage
node_reviewer_chat -->|"streams questions"| node_api_client
node_study_mode -->|"requests study"| node_api_client
node_api_client -->|"HTTP and SSE"| node_fastapi
node_fastapi -->|"registers"| node_document_routes
node_fastapi -->|"registers"| node_chat_routes
node_fastapi -->|"registers"| node_concept_routes
node_fastapi -->|"registers"| node_study_routes
node_fastapi -->|"registers"| node_project_routes
node_fastapi -->|"registers"| node_auth_routes
node_document_routes -->|"processes uploads"| node_document_service
node_document_service -->|"vectorizes passages"| node_vector_service
node_document_routes -->|"generates map"| node_concept_service
node_concept_routes -->|"requests concepts"| node_concept_service
node_concept_service -->|"selects passages"| node_vector_service
node_concept_service -->|"prompts model"| node_ollama
node_chat_routes -->|"handles chat"| node_chat_service
node_chat_service -->|"streams response"| node_ollama
node_study_routes -->|"generates study"| node_study_service
node_study_service -->|"generates material"| node_ollama
node_auth_routes -->|"authenticates"| node_auth_service
node_auth_routes -->|"checks fallback"| node_offline_auth
node_auth_service -->|"caches credentials"| node_offline_auth
node_auth_routes -->|"syncs after login"| node_sync_service
node_fastapi -->|"starts sync"| node_sync_service
node_database -->|"uses primary"| node_postgres
node_database -->|"falls back"| node_sqlite
node_database -.->|"provides sessions"| node_models
node_sync_service -->|"opens sessions"| node_database
node_sync_service -->|"copies records"| node_models
node_document_routes -.->|"uses session"| node_database
node_chat_routes -.->|"uses session"| node_database
node_study_routes -.->|"uses session"| node_database
node_project_routes -.->|"uses session"| node_database

click node_app "https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/App.tsx"
click node_workspace "https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/pages/Workspace.tsx"
click node_api_client "https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/services/api.ts"
click node_reviewer_chat "https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/components/ReviewerChat.tsx"
click node_concept_map "https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/components/ConceptMap.tsx"
click node_study_mode "https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/components/StudyMode.tsx"
click node_cover_storage "https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/services/coverStorage.ts"
click node_fastapi "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/main.py"
click node_document_routes "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/routers/documents.py"
click node_chat_routes "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/routers/chat.py"
click node_concept_routes "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/routers/concepts.py"
click node_study_routes "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/routers/study.py"
click node_project_routes "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/routers/projects.py"
click node_document_service "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/services/document_service.py"
click node_vector_service "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/services/vector_service.py"
click node_concept_service "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/services/concept_service.py"
click node_chat_service "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/services/chat_service.py"
click node_study_service "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/services/study_service.py"
click node_auth_routes "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/routers/auth.py"
click node_auth_service "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/auth.py"
click node_offline_auth "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/offline_auth.py"
click node_database "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/database.py"
click node_models "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/models.py"
click node_sync_service "https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/services/sync_service.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_workspace,node_api_client,node_reviewer_chat,node_concept_map,node_study_mode,node_cover_storage toneBlue
class node_fastapi,node_document_routes,node_chat_routes,node_concept_routes,node_study_routes,node_project_routes toneAmber
class node_document_service,node_vector_service,node_concept_service,node_chat_service,node_study_service,node_ollama toneMint
class node_database,node_models,node_sync_service,node_postgres,node_sqlite toneRose
class node_auth_routes,node_auth_service,node_offline_auth,node_user toneIndigo
```

## Components

### Workspace client

- [App shell](https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Workspace](https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/pages/Workspace.tsx): `frontend/src/pages/Workspace.tsx`
- [API client](https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`
- [Reviewer chat](https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/components/ReviewerChat.tsx): `frontend/src/components/ReviewerChat.tsx`
- [Concept map](https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/components/ConceptMap.tsx): `frontend/src/components/ConceptMap.tsx`
- [Study mode](https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/components/StudyMode.tsx): `frontend/src/components/StudyMode.tsx`
- [Cover storage](https://github.com/sand-box-dev/notepad-ai/blob/main/frontend/src/services/coverStorage.ts): `frontend/src/services/coverStorage.ts`

### API and domain workflows

- [FastAPI app](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/main.py): `backend/app/main.py`
- [Document routes](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/routers/documents.py): `backend/app/routers/documents.py`
- [Chat routes](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/routers/chat.py): `backend/app/routers/chat.py`
- [Concept routes](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/routers/concepts.py): `backend/app/routers/concepts.py`
- [Study routes](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/routers/study.py): `backend/app/routers/study.py`
- [Project routes](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/routers/projects.py): `backend/app/routers/projects.py`

### Local AI processing

- [Document processing](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/services/document_service.py): `backend/app/services/document_service.py`
- [Passage vectors](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/services/vector_service.py): `backend/app/services/vector_service.py`
- [Concept extraction](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/services/concept_service.py): `backend/app/services/concept_service.py`
- [Grounded chat](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/services/chat_service.py): `backend/app/services/chat_service.py`
- [Study generation](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/services/study_service.py): `backend/app/services/study_service.py`
- **Ollama model**

### Persistence and sync

- [DB failover](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/database.py): `backend/app/database.py`
- [Domain records](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/models.py): `backend/app/models.py`
- [Cloud sync](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/services/sync_service.py): `backend/app/services/sync_service.py`
- **Supabase Postgres**
- **Offline SQLite**

### Identity

- [Auth routes](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Online auth](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/auth.py): `backend/app/auth.py`
- [Offline credentials](https://github.com/sand-box-dev/notepad-ai/blob/main/backend/app/offline_auth.py): `backend/app/offline_auth.py`

### Other components

- **Learner**

## Connections

- Learner → App shell: uses (evidence: `frontend/src/App.tsx`)
- App shell → Workspace: opens workspace (evidence: `frontend/src/App.tsx`)
- App shell → API client: checks session (evidence: `frontend/src/App.tsx`)
- Workspace → API client: requests data (evidence: `frontend/src/pages/Workspace.tsx`)
- Workspace → Reviewer chat: renders (evidence: `frontend/src/pages/Workspace.tsx`)
- Workspace → Concept map: renders (evidence: `frontend/src/pages/Workspace.tsx`)
- Workspace → Study mode: renders (evidence: `frontend/src/pages/Workspace.tsx`)
- Workspace → Cover storage: removes cover (evidence: `frontend/src/pages/Workspace.tsx`)
- Reviewer chat → API client: streams questions (evidence: `frontend/src/components/ReviewerChat.tsx`)
- Study mode → API client: requests study (evidence: `frontend/src/components/StudyMode.tsx`)
- API client → FastAPI app: HTTP and SSE (evidence: `README.md`)
- FastAPI app → Document routes: registers (evidence: `backend/app/main.py`)
- FastAPI app → Chat routes: registers (evidence: `backend/app/main.py`)
- FastAPI app → Concept routes: registers (evidence: `backend/app/main.py`)
- FastAPI app → Study routes: registers (evidence: `backend/app/main.py`)
- FastAPI app → Project routes: registers (evidence: `backend/app/main.py`)
- FastAPI app → Auth routes: registers (evidence: `backend/app/main.py`)
- Document routes → Document processing: processes uploads (evidence: `backend/app/routers/documents.py`)
- Document processing → Passage vectors: vectorizes passages (evidence: `backend/app/services/document_service.py`)
- Document routes → Concept extraction: generates map (evidence: `backend/app/routers/documents.py`)
- Concept routes → Concept extraction: requests concepts (evidence: `backend/app/routers/concepts.py`)
- Concept extraction → Passage vectors: selects passages (evidence: `backend/app/services/concept_service.py`)
- Concept extraction → Ollama model: prompts model (evidence: `backend/app/services/concept_service.py`)
- Chat routes → Grounded chat: handles chat (evidence: `backend/app/routers/chat.py`)
- Grounded chat → Ollama model: streams response (evidence: `backend/app/services/chat_service.py`)
- Study routes → Study generation: generates study (evidence: `backend/app/routers/study.py`)
- Study generation → Ollama model: generates material (evidence: `backend/app/services/study_service.py`)
- Auth routes → Online auth: authenticates (evidence: `backend/app/routers/auth.py`)
- Auth routes → Offline credentials: checks fallback (evidence: `backend/app/routers/auth.py`)
- Online auth → Offline credentials: caches credentials (evidence: `backend/app/auth.py`)
- Auth routes → Cloud sync: syncs after login (evidence: `backend/app/routers/auth.py`)
- FastAPI app → Cloud sync: starts sync (evidence: `backend/app/main.py`)
- DB failover → Supabase Postgres: uses primary (evidence: `README.md`)
- DB failover → Offline SQLite: falls back (evidence: `README.md`)
- DB failover → Domain records: provides sessions (evidence: `backend/app/models.py`)
- Cloud sync → DB failover: opens sessions (evidence: `backend/app/services/sync_service.py`)
- Cloud sync → Domain records: copies records (evidence: `backend/app/services/sync_service.py`)
- Document routes → DB failover: uses session (evidence: `backend/app/routers/documents.py`)
- Chat routes → DB failover: uses session (evidence: `backend/app/routers/chat.py`)
- Study routes → DB failover: uses session (evidence: `backend/app/routers/study.py`)
- Project routes → DB failover: uses session (evidence: `backend/app/routers/projects.py`)
