# vishwassk15/privatedoc-ai architecture

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

- Interactive diagram: https://gitdiagram.com/vishwassk15/privatedoc-ai
- Repository: https://github.com/vishwassk15/privatedoc-ai

## Overview

PrivateDoc AI is a local-first document intelligence and grounded RAG application. Users upload and inspect documents, then ask questions answered from retrieved page-level evidence with deterministic citations; unknown questions can be refused, and generation remains useful but optional when a local LLM is unavailable. The graph also preserves the dashboard, system diagnostics, and privacy audit capabilities. README statements support the documented pipeline; source excerpts and the index support key API, frontend, persistence, and service relationships. OCR and several subsystem internals were not sampled, so uncertain wiring is omitted.

Main entry points: [`frontend/src/services/api.ts`](https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/services/api.ts) (API Client), [`backend/app/api/documents.py`](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/api/documents.py) (Document API), [`backend/app/main.py`](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/main.py) (FastAPI Application), [`frontend/src/App.tsx`](https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/App.tsx) (Application Shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["User Interface"]
  node_app["Application Shell<br/>[App.tsx]"]
  node_documents_ui["Document Workspace<br/>[Documents.tsx]"]
  node_detail_ui["Evidence Inspector<br/>[DocumentDetail.tsx]"]
  node_ask_ui["Ask AI<br/>[AskAI.tsx]"]
  node_dashboard["Dashboard<br/>[Dashboard.tsx]"]
  node_api_client["API Client<br/>[api.ts]"]
end

subgraph group_api["API and Persistence"]
  node_backend["FastAPI Application<br/>[main.py]"]
  node_document_api["Document API<br/>[documents.py]"]
  node_query_api["Query API<br/>[query.py]"]
  node_system_api["System API<br/>[system.py]"]
  node_sqlite[("SQLite Metadata<br/>[database.py]")]
end

subgraph group_ingestion["Document Ingestion"]
  node_processor["Document Processor"]
  node_ocr["OCR Provider<br/>[ocr.py]"]
  node_chunker["Page Chunker<br/>[chunker.py]"]
  node_embedder["Embedding Provider<br/>[embeddings.py]"]
  node_vector_store[("FAISS Vector Index<br/>[vector_store.py]")]
end

subgraph group_rag["Grounded RAG"]
  node_rag_service["RAG Orchestrator<br/>[rag.py]"]
  node_retriever["Local Retriever<br/>[retriever.py]"]
  node_citations["Citation Builder<br/>[citations.py]"]
  node_llm["Local LLM Provider<br/>[llm.py]"]
end

subgraph group_operations["Status and Privacy"]
  node_system_ui["System Status<br/>[SystemStatus.tsx]"]
  node_privacy_ui["Privacy Audit<br/>[PrivacyStatus.tsx]"]
  node_privacy["Privacy Service<br/>[privacy.py]"]
  node_config["Runtime Configuration<br/>[config.py]"]
end

node_user(("User"))

node_user -->|"uses"| node_app
node_app -->|"renders"| node_documents_ui
node_app -->|"renders"| node_detail_ui
node_app -->|"renders"| node_ask_ui
node_app -->|"renders"| node_dashboard
node_documents_ui -->|"requests data"| node_api_client
node_detail_ui -->|"requests data"| node_api_client
node_ask_ui -->|"submits queries"| node_api_client
node_dashboard -->|"requests data"| node_api_client
node_api_client -->|"calls documents"| node_document_api
node_api_client -->|"calls query"| node_query_api
node_api_client -->|"calls status"| node_system_api
node_backend -->|"registers route"| node_document_api
node_backend -->|"registers route"| node_query_api
node_backend -->|"registers route"| node_system_api
node_document_api -->|"processes uploads"| node_processor
node_document_api -->|"chunks pages"| node_chunker
node_document_api -->|"embeds chunks"| node_embedder
node_document_api -->|"indexes vectors"| node_vector_store
node_document_api -->|"stores metadata"| node_sqlite
node_processor -->|"uses when needed"| node_ocr
node_processor -.->|"chunks extracted text"| node_chunker
node_embedder -->|"indexes embeddings"| node_vector_store
node_vector_store -->|"stores metadata alongside"| node_sqlite
node_query_api -->|"runs query"| node_rag_service
node_rag_service -->|"retrieves evidence"| node_retriever
node_retriever -->|"embeds query"| node_embedder
node_retriever -->|"searches index"| node_vector_store
node_rag_service -->|"builds citations"| node_citations
node_rag_service -->|"generates answer"| node_llm
node_system_ui -->|"requests status"| node_api_client
node_privacy_ui -->|"requests audit"| node_api_client
node_api_client -.->|"uses local API"| node_backend
node_system_api -->|"reports privacy"| node_privacy
node_backend -->|"configures runtime"| node_config
node_backend -->|"initializes store"| node_sqlite

click node_app "https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/App.tsx"
click node_documents_ui "https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/pages/Documents.tsx"
click node_detail_ui "https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/pages/DocumentDetail.tsx"
click node_ask_ui "https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/pages/AskAI.tsx"
click node_dashboard "https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/pages/Dashboard.tsx"
click node_api_client "https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/services/api.ts"
click node_backend "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/main.py"
click node_document_api "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/api/documents.py"
click node_query_api "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/api/query.py"
click node_system_api "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/api/system.py"
click node_sqlite "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/database.py"
click node_processor "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/document_processor.py"
click node_ocr "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/ocr.py"
click node_chunker "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/chunker.py"
click node_embedder "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/embeddings.py"
click node_vector_store "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/vector_store.py"
click node_rag_service "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/rag.py"
click node_retriever "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/retriever.py"
click node_citations "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/citations.py"
click node_llm "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/llm.py"
click node_system_ui "https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/pages/SystemStatus.tsx"
click node_privacy_ui "https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/pages/PrivacyStatus.tsx"
click node_privacy "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/privacy.py"
click node_config "https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/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_ui,node_detail_ui,node_ask_ui,node_dashboard,node_api_client,node_user toneBlue
class node_backend,node_document_api,node_query_api,node_system_api,node_sqlite toneAmber
class node_processor,node_ocr,node_chunker,node_embedder,node_vector_store toneMint
class node_rag_service,node_retriever,node_citations,node_llm toneRose
class node_system_ui,node_privacy_ui,node_privacy,node_config toneIndigo
```

## Components

### User Interface

- [Application Shell](https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Document Workspace](https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/pages/Documents.tsx): `frontend/src/pages/Documents.tsx`
- [Evidence Inspector](https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/pages/DocumentDetail.tsx): `frontend/src/pages/DocumentDetail.tsx`
- [Ask AI](https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/pages/AskAI.tsx): `frontend/src/pages/AskAI.tsx`
- [Dashboard](https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/pages/Dashboard.tsx): `frontend/src/pages/Dashboard.tsx`
- [API Client](https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`

### API and Persistence

- [FastAPI Application](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/main.py): `backend/app/main.py`
- [Document API](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/api/documents.py): `backend/app/api/documents.py`
- [Query API](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/api/query.py): `backend/app/api/query.py`
- [System API](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/api/system.py): `backend/app/api/system.py`
- [SQLite Metadata](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/database.py): `backend/app/database.py`

### Document Ingestion

- [Document Processor](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/document_processor.py): `backend/app/services/document_processor.py`
- [OCR Provider](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/ocr.py): `backend/app/services/ocr.py`
- [Page Chunker](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/chunker.py): `backend/app/services/chunker.py`
- [Embedding Provider](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/embeddings.py): `backend/app/services/embeddings.py`
- [FAISS Vector Index](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/vector_store.py): `backend/app/services/vector_store.py`

### Grounded RAG

- [RAG Orchestrator](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/rag.py): `backend/app/services/rag.py`
- [Local Retriever](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/retriever.py): `backend/app/services/retriever.py`
- [Citation Builder](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/citations.py): `backend/app/services/citations.py`
- [Local LLM Provider](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/llm.py): `backend/app/services/llm.py`

### Status and Privacy

- [System Status](https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/pages/SystemStatus.tsx): `frontend/src/pages/SystemStatus.tsx`
- [Privacy Audit](https://github.com/vishwassk15/privatedoc-ai/blob/main/frontend/src/pages/PrivacyStatus.tsx): `frontend/src/pages/PrivacyStatus.tsx`
- [Privacy Service](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/services/privacy.py): `backend/app/services/privacy.py`
- [Runtime Configuration](https://github.com/vishwassk15/privatedoc-ai/blob/main/backend/app/config.py): `backend/app/config.py`

### Other components

- **User**

## Connections

- User → Application Shell: uses (evidence: `frontend/src/App.tsx`)
- Application Shell → Document Workspace: renders (evidence: `frontend/src/App.tsx`)
- Application Shell → Evidence Inspector: renders (evidence: `frontend/src/App.tsx`)
- Application Shell → Ask AI: renders (evidence: `frontend/src/App.tsx`)
- Application Shell → Dashboard: renders (evidence: `frontend/src/App.tsx`)
- Document Workspace → API Client: requests data (evidence: `frontend/src/pages/Documents.tsx`)
- Evidence Inspector → API Client: requests data (evidence: `frontend/src/pages/DocumentDetail.tsx`)
- Ask AI → API Client: submits queries (evidence: `frontend/src/pages/AskAI.tsx`)
- Dashboard → API Client: requests data (evidence: `frontend/src/pages/Dashboard.tsx`)
- API Client → Document API: calls documents (evidence: `frontend/src/services/api.ts`)
- API Client → Query API: calls query (evidence: `frontend/src/services/api.ts`)
- API Client → System API: calls status (evidence: `frontend/src/services/api.ts`)
- FastAPI Application → Document API: registers route (evidence: `backend/app/main.py`)
- FastAPI Application → Query API: registers route (evidence: `backend/app/main.py`)
- FastAPI Application → System API: registers route (evidence: `backend/app/main.py`)
- Document API → Document Processor: processes uploads (evidence: `backend/app/api/documents.py`)
- Document API → Page Chunker: chunks pages (evidence: `backend/app/api/documents.py`)
- Document API → Embedding Provider: embeds chunks (evidence: `backend/app/api/documents.py`)
- Document API → FAISS Vector Index: indexes vectors (evidence: `backend/app/api/documents.py`)
- Document API → SQLite Metadata: stores metadata (evidence: `backend/app/api/documents.py`)
- Document Processor → OCR Provider: uses when needed (evidence: `backend/app/services/document_processor.py`)
- Document Processor → Page Chunker: chunks extracted text
- Embedding Provider → FAISS Vector Index: indexes embeddings
- FAISS Vector Index → SQLite Metadata: stores metadata alongside
- Query API → RAG Orchestrator: runs query (evidence: `backend/app/api/query.py`)
- RAG Orchestrator → Local Retriever: retrieves evidence (evidence: `backend/app/services/rag.py`)
- Local Retriever → Embedding Provider: embeds query (evidence: `backend/app/services/retriever.py`)
- Local Retriever → FAISS Vector Index: searches index (evidence: `backend/app/services/retriever.py`)
- RAG Orchestrator → Citation Builder: builds citations (evidence: `backend/app/services/rag.py`)
- RAG Orchestrator → Local LLM Provider: generates answer (evidence: `backend/app/services/rag.py`)
- System Status → API Client: requests status (evidence: `frontend/src/pages/SystemStatus.tsx`)
- Privacy Audit → API Client: requests audit (evidence: `frontend/src/pages/PrivacyStatus.tsx`)
- API Client → FastAPI Application: uses local API
- System API → Privacy Service: reports privacy (evidence: `backend/app/api/system.py`)
- FastAPI Application → Runtime Configuration: configures runtime (evidence: `backend/app/main.py`)
- FastAPI Application → SQLite Metadata: initializes store (evidence: `backend/app/main.py`)
