# singhamit55/smartdoc-ai architecture

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

- Interactive diagram: https://gitdiagram.com/singhamit55/smartdoc-ai
- Repository: https://github.com/singhamit55/smartdoc-ai

## Overview

SmartDoc AI is a multi-tenant PDF chat application. Users authenticate with Google, upload PDFs for indexing, then ask questions and receive streamed answers grounded in retrieved document passages, with a documented DuckDuckGo fallback. The FastAPI entry point owns these workflows and scopes resources by user. The graph includes the documented chat-history and document-management capabilities. Some endpoint internals and frontend wiring were excerpted only partially; edges are limited to relationships visible in those excerpts or explicitly documented in the README.

Main entry points: [`main.py`](https://github.com/singhamit55/smartdoc-ai/blob/main/main.py) (FastAPI workflows), [`frontend/script.js`](https://github.com/singhamit55/smartdoc-ai/blob/main/frontend/script.js) (Chat and documents UI), [`Backend/vectorstore.py`](https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/vectorstore.py) (Tenant vector store), [`Backend/memory.py`](https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/memory.py) (SQLite application data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interface"]
  node_webui["Chat and documents UI<br/>[script.js]"]
  node_frontend_pages["Application pages"]
end

subgraph group_api["API and identity"]
  node_api["FastAPI workflows<br/>[main.py]"]
  node_google["Google OAuth"]
end

subgraph group_ingest["Document ingestion"]
  node_pdf["PDF extraction<br/>[pdf_loader.py]"]
  node_chunk["Text chunking<br/>[chunker.py]"]
  node_embed["Embedding generation<br/>[embeddings.py]"]
  node_vector[("Tenant vector store<br/>[vectorstore.py]")]
end

subgraph group_rag["Retrieval and answers"]
  node_retrieval["Semantic retriever<br/>[retriever.py]"]
  node_qa["QA prompt and citations<br/>[chat.py]"]
  node_llm["Language model<br/>[llm.py]"]
  node_websearch["DuckDuckGo search"]
end

subgraph group_state["Tenant state"]
  node_history["Conversation memory<br/>[memory.py]"]
  node_sqlite[("SQLite application data<br/>[memory.py]")]
  node_docfiles[("Tenant PDF files<br/>[main.py]")]
end

node_user(("User"))

node_user -->|"uses"| node_webui
node_webui -->|"calls API"| node_api
node_api -->|"verifies tokens"| node_google
node_api -->|"registers users"| node_sqlite
node_api -->|"extracts PDF"| node_pdf
node_api -->|"chunks text"| node_chunk
node_api -->|"creates embeddings"| node_embed
node_api -->|"indexes documents"| node_vector
node_api -->|"stores PDFs"| node_docfiles
node_api -->|"retrieves context"| node_retrieval
node_api -->|"loads history"| node_history
node_api -->|"formats prompt"| node_qa
node_api -->|"streams answer"| node_llm
node_api -->|"searches fallback"| node_websearch
node_api -->|"stores conversations"| node_sqlite
node_webui -.->|"renders"| node_frontend_pages
node_api -->|"removes document chunks"| node_vector
node_api -->|"lists and deletes"| node_docfiles
node_api -->|"lists chat records"| node_sqlite
node_retrieval -.->|"searches vectors"| node_vector

click node_webui "https://github.com/singhamit55/smartdoc-ai/blob/main/frontend/script.js"
click node_frontend_pages "https://github.com/singhamit55/smartdoc-ai/tree/main/frontend"
click node_api "https://github.com/singhamit55/smartdoc-ai/blob/main/main.py"
click node_pdf "https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/pdf_loader.py"
click node_chunk "https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/chunker.py"
click node_embed "https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/embeddings.py"
click node_vector "https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/vectorstore.py"
click node_retrieval "https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/retriever.py"
click node_qa "https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/chat.py"
click node_llm "https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/llm.py"
click node_history "https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/memory.py"
click node_sqlite "https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/memory.py"
click node_docfiles "https://github.com/singhamit55/smartdoc-ai/blob/main/main.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_webui,node_frontend_pages,node_user toneBlue
class node_api,node_google toneAmber
class node_pdf,node_chunk,node_embed,node_vector toneMint
class node_retrieval,node_qa,node_llm,node_websearch toneRose
class node_history,node_sqlite,node_docfiles toneIndigo
```

## Components

### User interface

- [Chat and documents UI](https://github.com/singhamit55/smartdoc-ai/blob/main/frontend/script.js): `frontend/script.js`
- [Application pages](https://github.com/singhamit55/smartdoc-ai/tree/main/frontend): `frontend`

### API and identity

- [FastAPI workflows](https://github.com/singhamit55/smartdoc-ai/blob/main/main.py): `main.py`
- **Google OAuth**

### Document ingestion

- [PDF extraction](https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/pdf_loader.py): `Backend/pdf_loader.py`
- [Text chunking](https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/chunker.py): `Backend/chunker.py`
- [Embedding generation](https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/embeddings.py): `Backend/embeddings.py`
- [Tenant vector store](https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/vectorstore.py): `Backend/vectorstore.py`

### Retrieval and answers

- [Semantic retriever](https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/retriever.py): `Backend/retriever.py`
- [QA prompt and citations](https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/chat.py): `Backend/chat.py`
- [Language model](https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/llm.py): `Backend/llm.py`
- **DuckDuckGo search**

### Tenant state

- [Conversation memory](https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/memory.py): `Backend/memory.py`
- [SQLite application data](https://github.com/singhamit55/smartdoc-ai/blob/main/Backend/memory.py): `Backend/memory.py`
- [Tenant PDF files](https://github.com/singhamit55/smartdoc-ai/blob/main/main.py): `main.py`

### Other components

- **User**

## Connections

- User → Chat and documents UI: uses (evidence: `README.md`)
- Chat and documents UI → FastAPI workflows: calls API (evidence: `frontend/script.js`)
- FastAPI workflows → Google OAuth: verifies tokens (evidence: `main.py`)
- FastAPI workflows → SQLite application data: registers users (evidence: `main.py`)
- FastAPI workflows → PDF extraction: extracts PDF (evidence: `README.md`)
- FastAPI workflows → Text chunking: chunks text (evidence: `main.py`)
- FastAPI workflows → Embedding generation: creates embeddings (evidence: `main.py`)
- FastAPI workflows → Tenant vector store: indexes documents (evidence: `main.py`)
- FastAPI workflows → Tenant PDF files: stores PDFs (evidence: `main.py`)
- FastAPI workflows → Semantic retriever: retrieves context (evidence: `main.py`)
- FastAPI workflows → Conversation memory: loads history (evidence: `main.py`)
- FastAPI workflows → QA prompt and citations: formats prompt (evidence: `main.py`)
- FastAPI workflows → Language model: streams answer (evidence: `main.py`)
- FastAPI workflows → DuckDuckGo search: searches fallback (evidence: `main.py`)
- FastAPI workflows → SQLite application data: stores conversations (evidence: `main.py`)
- Chat and documents UI → Application pages: renders (evidence: `README.md`)
- FastAPI workflows → Tenant vector store: removes document chunks (evidence: `main.py`)
- FastAPI workflows → Tenant PDF files: lists and deletes (evidence: `main.py`)
- FastAPI workflows → SQLite application data: lists chat records (evidence: `main.py`)
- Semantic retriever → Tenant vector store: searches vectors (evidence: `README.md`)
