# rta-ai/documind architecture

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

- Interactive diagram: https://gitdiagram.com/rta-ai/documind
- Repository: https://github.com/rta-ai/documind

## Overview

1. **Repository shape**
   - This is a very small, single-app repository: `app.py` contains the full application, with `requirements.txt` for dependencies and no separate backend/frontend split.
   - The architecture is therefore a **monolithic Streamlit app** with an embedded RAG pipeline.

2. **Primary user-facing boundary**
   - The main entry point is the Streamlit UI.
   - Users upload a PDF and then interact with the document through chat-style questions and document-oriented actions like summarization and key extraction.

3. **Document ingestion pipeline**
   - The first backend step is PDF parsing using **PyMuPDF**.
   - The app accepts large PDFs (up to 200 MB per the README), so ingestion is a significant boundary: file upload from the UI, then extraction of text from the PDF into internal document text.

4. **Text preparation and chunking**
   - Extracted text is split into smaller segments using **LangChain’s RecursiveCharacterTextSplitter**.
   - This chunking boundary matters because it separates raw document text from retrieval-ready units that can be embedded and searched efficiently.

5. **Embedding and indexing layer**
   - Chunks are converted into vector embeddings using **`all-MiniLM-L6-v2`** from Hugging Face.
   - Those embeddings are stored in **ChromaDB**, which serves as the vector database for retrieval-augmented generation.
   - This is the core persistence/retrieval subsystem; it turns uploaded PDFs into searchable semantic memory.

6. **Retrieval-augmented generation flow**
   - When the user asks a question, the app retrieves relevant chunks from ChromaDB and sends them as context to the LLM.
   - This is the key data flow: **PDF → chunks → embeddings/vector store → retrieval → LLM answer**.

7. **LLM and response generation**
   - The generation model is served through **Groq API** using **LLaMA 3.3 (`llama-3.3-70b-versatile`)**.
   - The app supports **streaming responses**, so the UI receives partial tokens incrementally rather than waiting for a full completion.

8. **Document-centric capabilities**
   - The app is not only a chatbot; it also supports structured document tasks:
     - full summary
     - 5-point bullet summary
     - key extraction for dates, names, figures, and terms
   - These capabilities likely reuse the same parsed/chunked document data, but route it through different prompt templates or retrieval strategies.

9. **State and interaction model**
   - Because this is Streamlit, application state is likely managed within Streamlit session state rather than an external service.
   - That means the document context, chat history, and retrieved chunks are probably kept per user session inside the app process.

10. **External dependencies and operational boundary**
   - The app depends on a Groq API key loaded from environment configuration.
   - The runtime stack is Python 3.10 with Streamlit 1.32 and the libraries listed in `requirements.txt`.
   - There is no evidence of separate databases, auth service, or job queue; the whole system is a local/in-memory Streamlit app plus external API calls to Groq and Hugging Face model assets.

11. **What an architecture diagram should show**
   - A single Streamlit application box in the center.
   - Inputs from the user: PDF upload and chat queries.
   - Internal pipeline blocks: PDF parsing, chunking, embeddings, ChromaDB retrieval, prompt assembly, Groq LLM generation.
   - Outputs back to the user: streamed answers, summaries, and extracted key facts.

Main entry points: [`app.py`](https://github.com/rta-ai/documind/blob/main/app.py) (RAG Flow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Streamlit App"]
  node_ui["Chat UI<br/>streamlit interface<br/>[app.py]"]
  node_state(("Session State<br/>[app.py]"))
  node_upload["PDF Upload<br/>ingest entry<br/>[app.py]"]
  node_parse["PDF Parse<br/>text extraction<br/>[app.py]"]
  node_chunk["Text Chunking<br/>splitter<br/>[app.py]"]
  node_embed["Embeddings<br/>vector encoding<br/>[app.py]"]
  node_store[("ChromaDB<br/>vector store<br/>[app.py]")]
  node_retrieve["Retriever<br/>context lookup<br/>[app.py]"]
  node_prompts["Prompt Assembler<br/>prompt routing<br/>[app.py]"]
  node_ragflow{{"RAG Flow<br/>orchestration<br/>[app.py]"}}
  node_summary["Summaries<br/>document action<br/>[app.py]"]
  node_extract["Key Extraction<br/>document action<br/>[app.py]"]
end

subgraph group_external["External Services"]
  node_groq["Groq LLM<br/>hosted generation"]
  node_hf["Hugging Face Model<br/>embedding model"]
end

node_ui -->|"upload PDF"| node_upload
node_ui -->|"ask / act"| node_ragflow
node_upload -->|"file text"| node_parse
node_parse -->|"document text"| node_chunk
node_chunk -->|"chunks"| node_embed
node_embed -->|"model load"| node_hf
node_embed -->|"vectors"| node_store
node_store -->|"search index"| node_retrieve
node_state -->|"context"| node_ragflow
node_ragflow -->|"find context"| node_retrieve
node_ragflow -->|"assemble prompt"| node_prompts
node_prompts -->|"generate"| node_groq
node_groq -->|"stream answer"| node_ui
node_ragflow -->|"summary task"| node_summary
node_ragflow -->|"extraction task"| node_extract
node_summary -->|"summarize"| node_groq
node_extract -->|"extract facts"| node_groq
node_ui -->|"save state"| node_state

click node_ui "https://github.com/rta-ai/documind/blob/main/app.py"
click node_state "https://github.com/rta-ai/documind/blob/main/app.py"
click node_upload "https://github.com/rta-ai/documind/blob/main/app.py"
click node_parse "https://github.com/rta-ai/documind/blob/main/app.py"
click node_chunk "https://github.com/rta-ai/documind/blob/main/app.py"
click node_embed "https://github.com/rta-ai/documind/blob/main/app.py"
click node_store "https://github.com/rta-ai/documind/blob/main/app.py"
click node_retrieve "https://github.com/rta-ai/documind/blob/main/app.py"
click node_prompts "https://github.com/rta-ai/documind/blob/main/app.py"
click node_ragflow "https://github.com/rta-ai/documind/blob/main/app.py"
click node_summary "https://github.com/rta-ai/documind/blob/main/app.py"
click node_extract "https://github.com/rta-ai/documind/blob/main/app.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_ui,node_state,node_upload,node_parse,node_chunk,node_embed,node_store,node_retrieve,node_prompts,node_ragflow,node_summary,node_extract toneBlue
class node_groq,node_hf toneAmber
```

## Components

### Streamlit App

Monolithic Python application that handles upload, RAG, and document actions.

- [Chat UI](https://github.com/rta-ai/documind/blob/main/app.py): streamlit interface · Main user-facing Streamlit screen for upload, questions, and document actions. · `app.py`
- [Session State](https://github.com/rta-ai/documind/blob/main/app.py): per-session state · Holds document context, chat history, and interaction state inside the Streamlit process. · `app.py`
- [PDF Upload](https://github.com/rta-ai/documind/blob/main/app.py): ingest entry · Accepts large PDF files from the user and starts the document pipeline. · `app.py`
- [PDF Parse](https://github.com/rta-ai/documind/blob/main/app.py): text extraction · Extracts text from uploaded PDFs using PyMuPDF. · `app.py`
- [Text Chunking](https://github.com/rta-ai/documind/blob/main/app.py): splitter · Splits extracted text into retrieval-friendly chunks with RecursiveCharacterTextSplitter. · `app.py`
- [Embeddings](https://github.com/rta-ai/documind/blob/main/app.py): vector encoding · Converts chunks into semantic vectors using all-MiniLM-L6-v2. · `app.py`
- [ChromaDB](https://github.com/rta-ai/documind/blob/main/app.py): vector store · Stores embeddings and chunk metadata for semantic retrieval. · `app.py`
- [Retriever](https://github.com/rta-ai/documind/blob/main/app.py): context lookup · Finds relevant chunks from ChromaDB for questions and document tasks. · `app.py`
- [Prompt Assembler](https://github.com/rta-ai/documind/blob/main/app.py): prompt routing · Builds task-specific prompts for chat, summaries, and key extraction. · `app.py`
- [RAG Flow](https://github.com/rta-ai/documind/blob/main/app.py): orchestration · Connects document context, retrieval results, and generation into one answer path. · `app.py`
- [Summaries](https://github.com/rta-ai/documind/blob/main/app.py): document action · Produces full and 5-point summaries from the uploaded document context. · `app.py`
- [Key Extraction](https://github.com/rta-ai/documind/blob/main/app.py): document action · Extracts dates, names, figures, and key terms from the document. · `app.py`

### External Services

Third-party model and library-backed services used by the app.

- **Groq LLM**: hosted generation · Generates streamed responses through the Groq API using LLaMA 3.3.
- **Hugging Face Model**: embedding model · Provides the all-MiniLM-L6-v2 embedding model asset used by the app.

## Connections

- Chat UI → PDF Upload: upload PDF · User sends a document into the app.
- Chat UI → RAG Flow: ask / act · User submits chat questions or document-oriented actions.
- PDF Upload → PDF Parse: file text · Uploaded PDF is parsed into raw text.
- PDF Parse → Text Chunking: document text · Extracted text is prepared for splitting.
- Text Chunking → Embeddings: chunks · Chunks are encoded into vectors.
- Embeddings → Hugging Face Model: model load · Embedding generation depends on the Hugging Face model asset.
- Embeddings → ChromaDB: vectors · Embeddings and chunk metadata are indexed in ChromaDB.
- ChromaDB → Retriever: search index · Retriever queries the vector store for relevant context.
- Session State → RAG Flow: context · Session state supplies document and chat context to orchestration.
- RAG Flow → Retriever: find context · RAG flow fetches relevant chunks for the current task.
- RAG Flow → Prompt Assembler: assemble prompt · Task inputs are converted into generation-ready prompts.
- Prompt Assembler → Groq LLM: generate · Prompt is sent to the hosted LLM for completion.
- Groq LLM → Chat UI: stream answer · Partial tokens stream back to the user interface.
- RAG Flow → Summaries: summary task · Summary mode reuses the same document pipeline with a different prompt.
- RAG Flow → Key Extraction: extraction task · Key extraction mode reuses document context with structured prompts.
- Summaries → Groq LLM: summarize · Summaries are generated through the same Groq LLM path.
- Key Extraction → Groq LLM: extract facts · Structured facts are generated through the same Groq LLM path.
- Chat UI → Session State: save state · User interactions update per-session state.
