# sainath-777/documind-enterprise architecture

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

- Interactive diagram: https://gitdiagram.com/sainath-777/documind-enterprise
- Repository: https://github.com/sainath-777/documind-enterprise

## Overview

DocuMind is a multi-tenant document intelligence platform. Users authenticate, upload PDFs for background indexing, then ask questions and receive cited answers through either standard responses or SSE streaming. The main query handler owns retrieval, generation, logging, and quota updates; retrieval combines semantic and keyword results before reranking. The frontend also exposes document, usage, audit, and team workflows. The README documents major integrations and capabilities not fully visible in sampled source; their links are shown only where documented, while unsampled endpoint wiring is not expanded.

Main entry points: [`documind/app/api/v1/endpoints/query_stream.py`](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/query_stream.py) (Streaming endpoint), [`documind/app/api/v1/endpoints/query.py`](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/query.py) (Query endpoint), [`documind/app/api/v1/router.py`](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/router.py) (API router), [`documind/app/services/ingestion/ingestor.py`](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/ingestion/ingestor.py) (Ingestion coordinator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_web["Dashboard and chat"]
  node_clientapi["API client<br/>[api-client.ts]"]
end

subgraph group_api["API and identity"]
  node_app["FastAPI app<br/>[main.py]"]
  node_router["API router<br/>[router.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_authservice["Tenant registration<br/>[auth_service.py]"]
  node_documents["Document endpoints<br/>[documents.py]"]
  node_quotas["Quota and rate limits"]
  node_audit["Audit endpoints<br/>[audit.py]"]
  node_admin["Admin endpoints<br/>[admin.py]"]
end

subgraph group_ingestion["Document ingestion"]
  node_ingestor["Ingestion coordinator<br/>[ingestor.py]"]
  node_pdf["PDF extraction<br/>[pdf_processor.py]"]
  node_chunker["Text chunking<br/>[chunker.py]"]
  node_embedder["Embedding generation<br/>[embedder.py]"]
  node_uploader["Vector indexing<br/>[uploader.py]"]
end

subgraph group_rag["Query and retrieval"]
  node_query["Query endpoint<br/>[query.py]"]
  node_streamquery["Streaming endpoint<br/>[query_stream.py]"]
  node_cache["Semantic cache<br/>[semantic_cache.py]"]
  node_semantic["Semantic search<br/>[semantic_search.py]"]
  node_bm25["BM25 search<br/>[bm25_search.py]"]
  node_fusion["Rank fusion<br/>[hybrid_fusion.py]"]
  node_reranker["Chunk reranking<br/>[reranker.py]"]
  node_prompt["Prompt builder<br/>[prompt_builder.py]"]
  node_generator["Answer generation<br/>[llm_client.py]"]
  node_streamgen["Streaming generation"]
  node_judge["Answer judge<br/>[judge.py]"]
end

subgraph group_state["Data and integrations"]
  node_postgres[("PostgreSQL<br/>[database.py]")]
  node_pinecone[("Pinecone vectors")]
  node_gemini{{"Gemini"}}
  node_cohere{{"Cohere reranking"}}
  node_groq{{"Groq judge model"}}
end

node_user(("Organization user"))

node_user -->|"uses"| node_web
node_web -->|"requests data"| node_clientapi
node_clientapi -->|"HTTP and SSE"| node_app
node_app -->|"mounts routes"| node_router
node_router -->|"dispatches"| node_auth
node_router -->|"dispatches"| node_documents
node_router -->|"dispatches"| node_query
node_router -->|"dispatches"| node_streamquery
node_router -->|"dispatches"| node_audit
node_router -->|"dispatches"| node_admin
node_auth -->|"registers tenant"| node_authservice
node_authservice -->|"writes tenant data"| node_postgres
node_documents -->|"stores metadata"| node_postgres
node_documents -->|"starts ingestion"| node_ingestor
node_ingestor -->|"updates status and chunks"| node_postgres
node_ingestor -->|"extracts text"| node_pdf
node_ingestor -->|"creates chunks"| node_chunker
node_ingestor -->|"embeds chunks"| node_embedder
node_ingestor -->|"indexes chunks"| node_uploader
node_uploader -->|"upserts vectors"| node_pinecone
node_clientapi -->|"submits query"| node_query
node_query -->|"checks and updates"| node_quotas
node_streamquery -->|"checks and updates"| node_quotas
node_query -->|"loads tenant and logs"| node_postgres
node_streamquery -->|"loads tenant and logs"| node_postgres
node_query -->|"checks and populates"| node_cache
node_streamquery -->|"checks and populates"| node_cache
node_query -->|"embeds query"| node_embedder
node_streamquery -->|"embeds query"| node_embedder
node_query -->|"requests candidates"| node_semantic
node_streamquery -->|"requests candidates"| node_semantic
node_query -->|"requests candidates"| node_bm25
node_streamquery -->|"requests candidates"| node_bm25
node_semantic -->|"searches vectors"| node_pinecone
node_bm25 -->|"searches text"| node_postgres
node_query -->|"fuses results"| node_fusion
node_streamquery -->|"fuses results"| node_fusion
node_query -->|"reranks candidates"| node_reranker
node_streamquery -->|"reranks candidates"| node_reranker
node_reranker -.->|"scores relevance"| node_cohere
node_query -->|"builds prompt"| node_prompt
node_streamquery -->|"builds prompt"| node_prompt
node_query -->|"generates answer"| node_generator
node_streamquery -->|"streams answer"| node_streamgen
node_generator -->|"generates text"| node_gemini
node_streamgen -->|"streams tokens"| node_gemini
node_streamquery -->|"schedules evaluation"| node_judge
node_judge -.->|"evaluates answer"| node_groq

click node_web "https://github.com/sainath-777/documind-enterprise/tree/main/frontend/src/app"
click node_clientapi "https://github.com/sainath-777/documind-enterprise/blob/main/frontend/src/lib/api-client.ts"
click node_app "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/main.py"
click node_router "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/router.py"
click node_auth "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/auth.py"
click node_authservice "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/auth_service.py"
click node_documents "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/documents.py"
click node_query "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/query.py"
click node_streamquery "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/query_stream.py"
click node_ingestor "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/ingestion/ingestor.py"
click node_pdf "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/ingestion/pdf_processor.py"
click node_chunker "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/ingestion/chunker.py"
click node_embedder "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/ingestion/embedder.py"
click node_uploader "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/ingestion/uploader.py"
click node_cache "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/cache/semantic_cache.py"
click node_semantic "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/retrieval/semantic_search.py"
click node_bm25 "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/retrieval/bm25_search.py"
click node_fusion "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/retrieval/hybrid_fusion.py"
click node_reranker "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/retrieval/reranker.py"
click node_prompt "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/generation/prompt_builder.py"
click node_generator "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/generation/llm_client.py"
click node_streamgen "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/generation/llm_client_stream.py"
click node_judge "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/generation/judge.py"
click node_quotas "https://github.com/sainath-777/documind-enterprise/tree/main/documind/app/services/quotas"
click node_audit "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/audit.py"
click node_admin "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/admin.py"
click node_postgres "https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/models/database.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_web,node_clientapi,node_user toneBlue
class node_app,node_router,node_auth,node_authservice,node_documents,node_quotas,node_audit,node_admin toneAmber
class node_ingestor,node_pdf,node_chunker,node_embedder,node_uploader toneMint
class node_query,node_streamquery,node_cache,node_semantic,node_bm25,node_fusion,node_reranker,node_prompt,node_generator,node_streamgen,node_judge toneRose
class node_postgres,node_pinecone,node_gemini,node_cohere,node_groq toneIndigo
```

## Components

### Web client

- [Dashboard and chat](https://github.com/sainath-777/documind-enterprise/tree/main/frontend/src/app): `frontend/src/app`
- [API client](https://github.com/sainath-777/documind-enterprise/blob/main/frontend/src/lib/api-client.ts): `frontend/src/lib/api-client.ts`

### API and identity

- [FastAPI app](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/main.py): `documind/app/main.py`
- [API router](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/router.py): `documind/app/api/v1/router.py`
- [Authentication](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/auth.py): `documind/app/api/v1/endpoints/auth.py`
- [Tenant registration](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/auth_service.py): `documind/app/services/auth_service.py`
- [Document endpoints](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/documents.py): `documind/app/api/v1/endpoints/documents.py`
- [Quota and rate limits](https://github.com/sainath-777/documind-enterprise/tree/main/documind/app/services/quotas): `documind/app/services/quotas`
- [Audit endpoints](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/audit.py): `documind/app/api/v1/endpoints/audit.py`
- [Admin endpoints](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/admin.py): `documind/app/api/v1/endpoints/admin.py`

### Document ingestion

- [Ingestion coordinator](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/ingestion/ingestor.py): `documind/app/services/ingestion/ingestor.py`
- [PDF extraction](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/ingestion/pdf_processor.py): `documind/app/services/ingestion/pdf_processor.py`
- [Text chunking](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/ingestion/chunker.py): `documind/app/services/ingestion/chunker.py`
- [Embedding generation](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/ingestion/embedder.py): `documind/app/services/ingestion/embedder.py`
- [Vector indexing](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/ingestion/uploader.py): `documind/app/services/ingestion/uploader.py`

### Query and retrieval

- [Query endpoint](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/query.py): `documind/app/api/v1/endpoints/query.py`
- [Streaming endpoint](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/api/v1/endpoints/query_stream.py): `documind/app/api/v1/endpoints/query_stream.py`
- [Semantic cache](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/cache/semantic_cache.py): `documind/app/services/cache/semantic_cache.py`
- [Semantic search](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/retrieval/semantic_search.py): `documind/app/services/retrieval/semantic_search.py`
- [BM25 search](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/retrieval/bm25_search.py): `documind/app/services/retrieval/bm25_search.py`
- [Rank fusion](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/retrieval/hybrid_fusion.py): `documind/app/services/retrieval/hybrid_fusion.py`
- [Chunk reranking](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/retrieval/reranker.py): `documind/app/services/retrieval/reranker.py`
- [Prompt builder](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/generation/prompt_builder.py): `documind/app/services/generation/prompt_builder.py`
- [Answer generation](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/generation/llm_client.py): `documind/app/services/generation/llm_client.py`
- [Streaming generation](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/generation/llm_client_stream.py): `documind/app/services/generation/llm_client_stream.py`
- [Answer judge](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/services/generation/judge.py): `documind/app/services/generation/judge.py`

### Data and integrations

- [PostgreSQL](https://github.com/sainath-777/documind-enterprise/blob/main/documind/app/models/database.py): `documind/app/models/database.py`
- **Pinecone vectors**
- **Gemini**
- **Cohere reranking**
- **Groq judge model**

### Other components

- **Organization user**

## Connections

- Organization user → Dashboard and chat: uses
- Dashboard and chat → API client: requests data
- API client → FastAPI app: HTTP and SSE
- FastAPI app → API router: mounts routes
- API router → Authentication: dispatches
- API router → Document endpoints: dispatches
- API router → Query endpoint: dispatches
- API router → Streaming endpoint: dispatches
- API router → Audit endpoints: dispatches
- API router → Admin endpoints: dispatches
- Authentication → Tenant registration: registers tenant
- Tenant registration → PostgreSQL: writes tenant data
- Document endpoints → PostgreSQL: stores metadata
- Document endpoints → Ingestion coordinator: starts ingestion
- Ingestion coordinator → PostgreSQL: updates status and chunks
- Ingestion coordinator → PDF extraction: extracts text
- Ingestion coordinator → Text chunking: creates chunks
- Ingestion coordinator → Embedding generation: embeds chunks
- Ingestion coordinator → Vector indexing: indexes chunks
- Vector indexing → Pinecone vectors: upserts vectors
- API client → Query endpoint: submits query
- Query endpoint → Quota and rate limits: checks and updates
- Streaming endpoint → Quota and rate limits: checks and updates
- Query endpoint → PostgreSQL: loads tenant and logs
- Streaming endpoint → PostgreSQL: loads tenant and logs
- Query endpoint → Semantic cache: checks and populates
- Streaming endpoint → Semantic cache: checks and populates
- Query endpoint → Embedding generation: embeds query
- Streaming endpoint → Embedding generation: embeds query
- Query endpoint → Semantic search: requests candidates
- Streaming endpoint → Semantic search: requests candidates
- Query endpoint → BM25 search: requests candidates
- Streaming endpoint → BM25 search: requests candidates
- Semantic search → Pinecone vectors: searches vectors
- BM25 search → PostgreSQL: searches text
- Query endpoint → Rank fusion: fuses results
- Streaming endpoint → Rank fusion: fuses results
- Query endpoint → Chunk reranking: reranks candidates
- Streaming endpoint → Chunk reranking: reranks candidates
- Chunk reranking → Cohere reranking: scores relevance
- Query endpoint → Prompt builder: builds prompt
- Streaming endpoint → Prompt builder: builds prompt
- Query endpoint → Answer generation: generates answer
- Streaming endpoint → Streaming generation: streams answer
- Answer generation → Gemini: generates text
- Streaming generation → Gemini: streams tokens
- Streaming endpoint → Answer judge: schedules evaluation
- Answer judge → Groq judge model: evaluates answer
