# manvadariya/askyourdocuments architecture

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

- Interactive diagram: https://gitdiagram.com/manvadariya/askyourdocuments
- Repository: https://github.com/manvadariya/askyourdocuments

## Overview

1. **Overall shape**
   This repo is a notebook-centered document Q&A app. The main application logic appears to live in `AskYourDocuments.ipynb`, while the `templates/` and `static/` folders provide a lightweight web UI around it.

2. **Primary runtime entrypoint**
   `AskYourDocuments.ipynb` is the central orchestration layer. The README says it can initialize the backend, run the app, and optionally auto-start Flask unless `AUTO_START_FLASK=0` is set. That makes the notebook both the development workflow and the application bootstrap.

3. **Bootstrap and execution wrapper**
   `scripts/run_notebook.sh` is the operational entrypoint for local/CI execution. It creates a virtual environment, installs `requirements.txt`, and runs the notebook in a non-blocking mode for validation. This script is the repo’s repeatable setup boundary.

4. **Backend responsibility**
   The backend is Python-based and likely embedded in the notebook rather than split into a separate package. Its role is to accept documents, process them, call LLM/embedding services, and serve responses to the web layer. The repo does not show a conventional `app/` or `src/` layout, so the notebook is the main application container.

5. **Document ingestion and processing path**
   The app is designed to accept PDFs, DOCX, XLSX, PPTX, and images. The processing pipeline likely converts those inputs into text or OCR-derived content, then prepares them for downstream analysis. This is the core “document intelligence” boundary in the system.

6. **Retrieval and chat flow**
   The architecture is consistent with a retrieval-augmented chat system: user asks a question in the UI, the backend uses document-derived context to answer, and the response is returned conversationally. The README explicitly mentions both “chat” and “embeddings,” so there is likely a chunking/indexing step before query-time retrieval.

7. **External model services**
   The system depends on external AI providers rather than local models. `GITHUB_TOKEN` is used for GitHub Models API access for both chat and embeddings, and `HF_TOKEN` is used for Hugging Face vision/OCR model access. `AZURE_LLM_MODEL_NAME` and `HF_VISION_MODEL_ID` are configuration points, not separate subsystems.

8. **Vision/OCR branch**
   Images are a first-class input type, so there is a separate vision/OCR path in addition to text document parsing. That path likely feeds extracted text or structured observations into the same retrieval/chat pipeline as PDFs and office documents.

9. **Web presentation layer**
   The browser-facing UI is built from Jinja-style templates in `templates/chat.html` and `templates/hero-geometric.html`. This suggests a server-rendered Flask UI rather than a SPA. The templates define the main screens: the chat experience and a landing/hero page.

10. **Client-side interaction**
   `static/js/chat.js` and `static/js/documents.js` provide browser-side behavior for chat interactions and document handling. These scripts likely manage upload flow, send user messages to backend endpoints, render responses, and update document state without full page reloads.

11. **Deployment and access**
   `NGROK_AUTHTOKEN` is an optional integration for exposing the local app publicly. That indicates the repo is built for local notebook execution first, with tunnel-based sharing as an auxiliary deployment path rather than a dedicated production deployment stack.

12. **Key architectural boundary for diagrams**
   The most important diagram boundary is: **browser UI → Flask/notebook backend → document parsing + embedding/retrieval + LLM/OCR services → response back to UI**. The notebook and shell script are the execution/control plane, while templates and static JS form the presentation layer.

Main entry points: [`AskYourDocuments.ipynb`](https://github.com/manvadariya/askyourdocuments/blob/main/AskYourDocuments.ipynb) (Notebook app), [`templates/chat.html`](https://github.com/manvadariya/askyourdocuments/blob/main/templates/chat.html) (Chat page), [`static/js/documents.js`](https://github.com/manvadariya/askyourdocuments/blob/main/static/js/documents.js) (Docs client), [`static/js/chat.js`](https://github.com/manvadariya/askyourdocuments/blob/main/static/js/chat.js) (Chat client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime & bootstrap"]
  node_n1["Notebook app<br/>notebook orchestrator"]
  node_n2["Run script<br/>shell entrypoint<br/>[run_notebook.sh]"]
end

subgraph group_ui["Web UI"]
  node_n3["Chat page<br/>template<br/>[chat.html]"]
  node_n4["Hero page<br/>template"]
  node_n5["Chat client<br/>browser script<br/>[chat.js]"]
  node_n6["Docs client<br/>browser script<br/>[documents.js]"]
end

subgraph group_core["Document Q&A core"]
  node_n7["Document flow<br/>ingestion pipeline"]
  node_n8["Text parse<br/>document extraction"]
  node_n9["Vision OCR<br/>image understanding"]
  node_n10["Chunk index<br/>embedding prep"]
  node_n11["Retriever<br/>query retrieval"]
  node_n12["Answer engine<br/>chat orchestration"]
end

subgraph group_services["External services"]
  node_n13(("GitHub Models<br/>LLM/embeddings API"))
  node_n14(("Hugging Face<br/>vision/OCR API"))
  node_n15(("Azure model name<br/>config"))
  node_n16(("Ngrok<br/>tunnel config"))
end

node_n2 -->|"executes"| node_n1
node_n1 -->|"renders"| node_n3
node_n1 -->|"renders"| node_n4
node_n3 -->|"uses"| node_n5
node_n3 -->|"uses"| node_n6
node_n6 -->|"uploads"| node_n7
node_n7 -->|"extracts"| node_n8
node_n7 -->|"ocr path"| node_n9
node_n8 -->|"indexes"| node_n10
node_n9 -->|"indexes"| node_n10
node_n10 -->|"retrieves"| node_n11
node_n11 -->|"supplies context"| node_n12
node_n12 -->|"calls"| node_n13
node_n9 -->|"calls"| node_n14
node_n1 -->|"configures"| node_n15
node_n1 -.->|"optional share"| node_n16
node_n5 -->|"requests"| node_n1
node_n6 -->|"requests"| node_n1

click node_n1 "https://github.com/manvadariya/askyourdocuments/blob/main/AskYourDocuments.ipynb"
click node_n2 "https://github.com/manvadariya/askyourdocuments/blob/main/scripts/run_notebook.sh"
click node_n3 "https://github.com/manvadariya/askyourdocuments/blob/main/templates/chat.html"
click node_n4 "https://github.com/manvadariya/askyourdocuments/blob/main/templates/hero-geometric.html"
click node_n5 "https://github.com/manvadariya/askyourdocuments/blob/main/static/js/chat.js"
click node_n6 "https://github.com/manvadariya/askyourdocuments/blob/main/static/js/documents.js"

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_n1,node_n2 toneBlue
class node_n3,node_n4,node_n5,node_n6 toneAmber
class node_n7,node_n8,node_n9,node_n10,node_n11,node_n12 toneMint
class node_n13,node_n14,node_n15,node_n16 toneRose
```

## Components

### Runtime & bootstrap

Notebook-driven application entry and repeatable local execution.

- [Notebook app](https://github.com/manvadariya/askyourdocuments/blob/main/AskYourDocuments.ipynb): notebook orchestrator · Central application container and primary bootstrap for the document Q&A system. · `AskYourDocuments.ipynb`
- [Run script](https://github.com/manvadariya/askyourdocuments/blob/main/scripts/run_notebook.sh): shell entrypoint · Repeatable local/CI wrapper that creates the environment and runs the notebook. · `scripts/run_notebook.sh`

### Web UI

Server-rendered pages and browser-side interactions.

- [Chat page](https://github.com/manvadariya/askyourdocuments/blob/main/templates/chat.html): template · Main server-rendered chat interface. · `templates/chat.html`
- [Hero page](https://github.com/manvadariya/askyourdocuments/blob/main/templates/hero-geometric.html): template · Landing or introduction screen for the app. · `templates/hero-geometric.html`
- [Chat client](https://github.com/manvadariya/askyourdocuments/blob/main/static/js/chat.js): browser script · Client-side chat behavior and message rendering. · `static/js/chat.js`
- [Docs client](https://github.com/manvadariya/askyourdocuments/blob/main/static/js/documents.js): browser script · Client-side document upload and state handling. · `static/js/documents.js`

### Document Q&A core

Document ingestion, retrieval, and answer generation flow.

- **Document flow**: ingestion pipeline · Accepts PDFs, DOCX, XLSX, PPTX, and images and turns them into usable content.
- **Text parse**: document extraction · Extracts text and structured content from office and PDF documents.
- **Vision OCR**: image understanding · Processes images through vision or OCR models before retrieval.
- **Chunk index**: embedding prep · Splits document content and prepares it for retrieval.
- **Retriever**: query retrieval · Selects relevant document context for a user question.
- **Answer engine**: chat orchestration · Combines retrieved context with chat prompting to generate answers.

### External services

Model and tunnel integrations configured through environment variables.

- **GitHub Models**: LLM/embeddings API · External provider for chat and embedding calls via token-based access.
- **Hugging Face**: vision/OCR API · External provider for vision and OCR model access.
- **Azure model name**: config · Model selection setting used by the notebook backend.
- **Ngrok**: tunnel config · Optional public exposure path for a locally running app.

## Connections

- Run script → Notebook app: executes · Runs the notebook in a repeatable environment.
- Notebook app → Chat page: renders · Serves the chat UI through the backend.
- Notebook app → Hero page: renders · Serves the landing page template.
- Chat page → Chat client: uses · Chat page behavior is driven by the browser script.
- Chat page → Docs client: uses · Document interactions are driven by the browser script.
- Docs client → Document flow: uploads · Client-side document handling feeds the ingestion flow.
- Document flow → Text parse: extracts · Text documents are parsed into usable content.
- Document flow → Vision OCR: ocr path · Image inputs take the vision/OCR branch.
- Text parse → Chunk index: indexes · Parsed text is chunked and prepared for retrieval.
- Vision OCR → Chunk index: indexes · OCR output is also prepared for retrieval.
- Chunk index → Retriever: retrieves · Indexed content is queried at question time.
- Retriever → Answer engine: supplies context · Retrieved passages feed the answer generator.
- Answer engine → GitHub Models: calls · LLM and embedding requests go to GitHub Models.
- Vision OCR → Hugging Face: calls · Vision and OCR processing uses Hugging Face models.
- Notebook app → Azure model name: configures · Notebook selects the configured LLM model name.
- Notebook app → Ngrok: optional share · Local app can be exposed through an ngrok tunnel.
- Chat client → Notebook app: requests · Chat UI sends questions to the backend endpoints.
- Docs client → Notebook app: requests · Document UI sends upload and management actions to the backend.
