# gayitrijarajapu/documind-ai-backend architecture

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

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

## Overview

DocuMind is a FastAPI document-understanding API for a React UI. Its main workflow accepts PDFs, extracts and chunks page text, builds a searchable vector index, and stores document metadata; users can then request grounded answers with citations, summaries, and structured fields. Separate API branches list/manage documents, expose dashboard counts, and retrieve chat history. The graph follows calls shown in sampled files and README capabilities; unsampled formatter and configuration details are represented only where supported.

Main entry points: [`app/models/document.py`](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/models/document.py) (Document records), [`app/api/documents.py`](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/api/documents.py) (Document endpoints), [`app/main.py`](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/main.py) (FastAPI app), [`app/services/document_processor.py`](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/services/document_processor.py) (PDF and indexing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_app["FastAPI app<br/>[main.py]"]
  node_documents_api["Document endpoints<br/>[documents.py]"]
  node_chat_api["Chat endpoints<br/>[chat.py]"]
  node_dashboard_api["Dashboard stats<br/>[dashboard.py]"]
  node_schemas["API schemas<br/>[document.py]"]
  node_formatters["UI formatting<br/>[formatters.py]"]
end

subgraph group_processing["Document Processing"]
  node_processor["PDF and indexing"]
end

subgraph group_ai["AI Features"]
  node_document_ai["Summary and extraction<br/>[document_ai.py]"]
  node_qa["Question answering<br/>[qa.py]"]
  node_gemini["Gemini service<br/>[gemini.py]"]
end

subgraph group_persistence["Persistence"]
  node_document_model[("Document records<br/>[document.py]")]
  node_db_session["Database sessions<br/>[session.py]"]
  node_settings["Runtime settings<br/>[config.py]"]
end

node_frontend(("React UI"))
node_database[("SQL database")]
node_vector_index[("FAISS index files")]
node_gemini_api{{"Google Gemini"}}

node_frontend -->|"calls API"| node_app
node_app -->|"routes"| node_documents_api
node_app -->|"routes"| node_chat_api
node_app -->|"routes"| node_dashboard_api
node_documents_api -->|"processes PDF"| node_processor
node_documents_api -->|"requests summary"| node_document_ai
node_documents_api -->|"formats response"| node_formatters
node_documents_api -->|"reads and writes"| node_document_model
node_chat_api -->|"answers question"| node_qa
node_chat_api -->|"reads history"| node_document_model
node_dashboard_api -->|"counts records"| node_document_model
node_processor -->|"writes and searches"| node_vector_index
node_processor -->|"stores chunks"| node_document_model
node_document_ai -->|"fallback summaries"| node_processor
node_document_ai -->|"requests AI output"| node_gemini
node_document_ai -->|"loads and updates"| node_document_model
node_qa -->|"retrieves chunks"| node_processor
node_qa -->|"requests answer"| node_gemini
node_qa -->|"stores messages"| node_document_model
node_gemini -->|"invokes model"| node_gemini_api
node_db_session -->|"loads database URL"| node_settings
node_db_session -->|"connects"| node_database
node_document_model -->|"declares ORM base"| node_db_session
node_app -->|"creates tables"| node_db_session
node_settings -.->|"configures index directory"| node_vector_index
node_documents_api -->|"validates responses"| node_schemas
node_chat_api -->|"validates requests"| node_schemas

click node_app "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/main.py"
click node_documents_api "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/api/documents.py"
click node_chat_api "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/api/chat.py"
click node_dashboard_api "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/api/dashboard.py"
click node_schemas "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/schemas/document.py"
click node_processor "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/services/document_processor.py"
click node_document_ai "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/services/document_ai.py"
click node_qa "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/services/qa.py"
click node_gemini "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/services/gemini.py"
click node_formatters "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/services/formatters.py"
click node_document_model "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/models/document.py"
click node_db_session "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/db/session.py"
click node_settings "https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/core/config.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_documents_api,node_chat_api,node_dashboard_api,node_schemas,node_formatters,node_frontend toneBlue
class node_processor,node_database,node_vector_index toneAmber
class node_document_ai,node_qa,node_gemini toneMint
class node_document_model,node_db_session,node_settings toneRose
class node_gemini_api toneIndigo
```

## Components

### HTTP API

- [FastAPI app](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/main.py): `app/main.py`
- [Document endpoints](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/api/documents.py): `app/api/documents.py`
- [Chat endpoints](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/api/chat.py): `app/api/chat.py`
- [Dashboard stats](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/api/dashboard.py): `app/api/dashboard.py`
- [API schemas](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/schemas/document.py): `app/schemas/document.py`
- [UI formatting](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/services/formatters.py): `app/services/formatters.py`

### Document Processing

- [PDF and indexing](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/services/document_processor.py): `app/services/document_processor.py`

### AI Features

- [Summary and extraction](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/services/document_ai.py): `app/services/document_ai.py`
- [Question answering](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/services/qa.py): `app/services/qa.py`
- [Gemini service](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/services/gemini.py): `app/services/gemini.py`

### Persistence

- [Document records](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/models/document.py): `app/models/document.py`
- [Database sessions](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/db/session.py): `app/db/session.py`
- [Runtime settings](https://github.com/gayitrijarajapu/documind-ai-backend/blob/main/app/core/config.py): `app/core/config.py`

### Other components

- **React UI**
- **SQL database**
- **FAISS index files**
- **Google Gemini**

## Connections

- React UI → FastAPI app: calls API (evidence: `README.md`)
- FastAPI app → Document endpoints: routes (evidence: `app/main.py`)
- FastAPI app → Chat endpoints: routes (evidence: `app/main.py`)
- FastAPI app → Dashboard stats: routes (evidence: `app/main.py`)
- Document endpoints → PDF and indexing: processes PDF (evidence: `app/api/documents.py`)
- Document endpoints → Summary and extraction: requests summary (evidence: `app/api/documents.py`)
- Document endpoints → UI formatting: formats response (evidence: `app/api/documents.py`)
- Document endpoints → Document records: reads and writes (evidence: `app/api/documents.py`)
- Chat endpoints → Question answering: answers question (evidence: `app/api/chat.py`)
- Chat endpoints → Document records: reads history (evidence: `app/api/chat.py`)
- Dashboard stats → Document records: counts records (evidence: `app/api/dashboard.py`)
- PDF and indexing → FAISS index files: writes and searches (evidence: `app/services/document_processor.py`)
- PDF and indexing → Document records: stores chunks (evidence: `app/services/document_processor.py`)
- Summary and extraction → PDF and indexing: fallback summaries (evidence: `app/services/document_ai.py`)
- Summary and extraction → Gemini service: requests AI output (evidence: `app/services/document_ai.py`)
- Summary and extraction → Document records: loads and updates (evidence: `app/services/document_ai.py`)
- Question answering → PDF and indexing: retrieves chunks (evidence: `app/services/qa.py`)
- Question answering → Gemini service: requests answer (evidence: `app/services/qa.py`)
- Question answering → Document records: stores messages (evidence: `app/services/qa.py`)
- Gemini service → Google Gemini: invokes model (evidence: `app/services/gemini.py`)
- Database sessions → Runtime settings: loads database URL (evidence: `app/db/session.py`)
- Database sessions → SQL database: connects (evidence: `app/db/session.py`)
- Document records → Database sessions: declares ORM base (evidence: `app/models/document.py`)
- FastAPI app → Database sessions: creates tables (evidence: `app/main.py`)
- Runtime settings → FAISS index files: configures index directory (evidence: `app/core/config.py`)
- Document endpoints → API schemas: validates responses (evidence: `app/api/documents.py`)
- Chat endpoints → API schemas: validates requests (evidence: `app/api/chat.py`)
