# anuragthippani1/docflow-rag architecture

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

- Interactive diagram: https://gitdiagram.com/anuragthippani1/docflow-rag
- Repository: https://github.com/anuragthippani1/docflow-rag

## Overview

DocFlow is a document-grounded supply-chain intelligence product. Users upload PDFs, then ask questions and receive cited answers, evidence checks, domain risk assessments, and a combined recommendation. The graph shows the documented API/UI and sampled ingestion and evidence flows; several backend routes and frontend behaviors are documented in the README but their implementation excerpts were not provided, so those links are cited to the README.

Main entry points: [`app/main.py`](https://github.com/anuragthippani1/docflow-rag/blob/main/app/main.py) (FastAPI routes), [`app/agent_router.py`](https://github.com/anuragthippani1/docflow-rag/blob/main/app/agent_router.py) (Agent dispatch), [`app/ingest.py`](https://github.com/anuragthippani1/docflow-rag/blob/main/app/ingest.py) (PDF processing), [`app/evidence/pipeline.py`](https://github.com/anuragthippani1/docflow-rag/blob/main/app/evidence/pipeline.py) (Evidence preparation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Document ingestion"]
  node_upload["PDF processing<br/>[ingest.py]"]
  node_entity["Entity extraction"]
end

subgraph group_answer["Evidence-grounded answers"]
  node_query["Conversational retrieval<br/>[rag_chat.py]"]
  node_retrieval["Hybrid retrieval<br/>[hybrid.py]"]
  node_rerank["Result reranking<br/>[rerank.py]"]
  node_evidence["Evidence preparation<br/>[pipeline.py]"]
  node_verify["Evidence verification"]
  node_answergen["Answer generation<br/>[rag_chat.py]"]
end

subgraph group_risk["Supply-chain analysis"]
  node_agents["Agent dispatch<br/>[agent_router.py]"]
  node_supplier["Supplier risk<br/>[supplier_agent.py]"]
  node_inventory["Inventory risk<br/>[inventory_agent.py]"]
  node_logistics["Logistics risk<br/>[logistics_agent.py]"]
  node_externalrisk["External risk"]
  node_decision["Final decision<br/>[decision_agent.py]"]
end

subgraph group_experience["API and user experience"]
  node_webui["Web interface<br/>[chat.js]"]
  node_dashboard["Session dashboard<br/>[dashboard.js]"]
  node_api["FastAPI routes<br/>[main.py]"]
  node_status["Health and stats<br/>[status.py]"]
end

subgraph group_state["Persistence and operations"]
  node_vectors[("FAISS index<br/>[ingest.py]")]
  node_graphstore[("Knowledge graph<br/>[graph.py]")]
  node_conversations[("Conversation history<br/>[conversations.py]")]
end

node_user(("User"))
node_riskdata["External risk data"]
node_openrouter["OpenRouter models"]

node_user -->|"asks or uploads"| node_webui
node_webui -->|"calls API"| node_api
node_api -->|"processes uploads"| node_upload
node_upload -->|"indexes chunks"| node_vectors
node_upload -->|"extracts entities"| node_entity
node_upload -->|"upserts extraction"| node_graphstore
node_api -->|"prepares query turn"| node_evidence
node_evidence -->|"retrieves evidence"| node_query
node_query -->|"builds retriever"| node_retrieval
node_retrieval -.->|"may rerank"| node_rerank
node_evidence -->|"verifies pack"| node_verify
node_verify -->|"checks evidence"| node_openrouter
node_api -->|"generates answer"| node_answergen
node_answergen -->|"generates response"| node_openrouter
node_api -->|"stores messages"| node_conversations
node_api -->|"dispatches analysis"| node_agents
node_agents -->|"runs assessment"| node_supplier
node_agents -->|"runs assessment"| node_inventory
node_agents -->|"runs assessment"| node_logistics
node_agents -->|"runs assessment"| node_externalrisk
node_api -.->|"fetches risk context"| node_riskdata
node_externalrisk -.->|"uses context"| node_riskdata
node_agents -->|"combines assessments"| node_decision
node_api -->|"serves status"| node_status
node_api -->|"returns query stats"| node_dashboard

click node_webui "https://github.com/anuragthippani1/docflow-rag/blob/main/frontend/js/chat.js"
click node_dashboard "https://github.com/anuragthippani1/docflow-rag/blob/main/frontend/js/dashboard.js"
click node_api "https://github.com/anuragthippani1/docflow-rag/blob/main/app/main.py"
click node_upload "https://github.com/anuragthippani1/docflow-rag/blob/main/app/ingest.py"
click node_vectors "https://github.com/anuragthippani1/docflow-rag/blob/main/app/ingest.py"
click node_entity "https://github.com/anuragthippani1/docflow-rag/blob/main/app/entity_extractor.py"
click node_graphstore "https://github.com/anuragthippani1/docflow-rag/blob/main/app/graph.py"
click node_query "https://github.com/anuragthippani1/docflow-rag/blob/main/app/rag_chat.py"
click node_retrieval "https://github.com/anuragthippani1/docflow-rag/blob/main/app/retrievers/hybrid.py"
click node_rerank "https://github.com/anuragthippani1/docflow-rag/blob/main/app/retrievers/rerank.py"
click node_evidence "https://github.com/anuragthippani1/docflow-rag/blob/main/app/evidence/pipeline.py"
click node_verify "https://github.com/anuragthippani1/docflow-rag/blob/main/app/evidence/verify_openrouter.py"
click node_answergen "https://github.com/anuragthippani1/docflow-rag/blob/main/app/rag_chat.py"
click node_conversations "https://github.com/anuragthippani1/docflow-rag/blob/main/app/conversations.py"
click node_agents "https://github.com/anuragthippani1/docflow-rag/blob/main/app/agent_router.py"
click node_supplier "https://github.com/anuragthippani1/docflow-rag/blob/main/app/agents/supplier_agent.py"
click node_inventory "https://github.com/anuragthippani1/docflow-rag/blob/main/app/agents/inventory_agent.py"
click node_logistics "https://github.com/anuragthippani1/docflow-rag/blob/main/app/agents/logistics_agent.py"
click node_externalrisk "https://github.com/anuragthippani1/docflow-rag/blob/main/app/agents/external_risk_agent.py"
click node_decision "https://github.com/anuragthippani1/docflow-rag/blob/main/app/agents/decision_agent.py"
click node_status "https://github.com/anuragthippani1/docflow-rag/blob/main/app/status.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_upload,node_entity,node_user toneBlue
class node_query,node_retrieval,node_rerank,node_evidence,node_verify,node_answergen toneAmber
class node_agents,node_supplier,node_inventory,node_logistics,node_externalrisk,node_decision,node_openrouter toneMint
class node_webui,node_dashboard,node_api,node_status toneRose
class node_vectors,node_graphstore,node_conversations,node_riskdata toneIndigo
```

## Components

### Document ingestion

- [PDF processing](https://github.com/anuragthippani1/docflow-rag/blob/main/app/ingest.py): `app/ingest.py`
- [Entity extraction](https://github.com/anuragthippani1/docflow-rag/blob/main/app/entity_extractor.py): `app/entity_extractor.py`

### Evidence-grounded answers

- [Conversational retrieval](https://github.com/anuragthippani1/docflow-rag/blob/main/app/rag_chat.py): `app/rag_chat.py`
- [Hybrid retrieval](https://github.com/anuragthippani1/docflow-rag/blob/main/app/retrievers/hybrid.py): `app/retrievers/hybrid.py`
- [Result reranking](https://github.com/anuragthippani1/docflow-rag/blob/main/app/retrievers/rerank.py): `app/retrievers/rerank.py`
- [Evidence preparation](https://github.com/anuragthippani1/docflow-rag/blob/main/app/evidence/pipeline.py): `app/evidence/pipeline.py`
- [Evidence verification](https://github.com/anuragthippani1/docflow-rag/blob/main/app/evidence/verify_openrouter.py): `app/evidence/verify_openrouter.py`
- [Answer generation](https://github.com/anuragthippani1/docflow-rag/blob/main/app/rag_chat.py): `app/rag_chat.py`

### Supply-chain analysis

- [Agent dispatch](https://github.com/anuragthippani1/docflow-rag/blob/main/app/agent_router.py): `app/agent_router.py`
- [Supplier risk](https://github.com/anuragthippani1/docflow-rag/blob/main/app/agents/supplier_agent.py): `app/agents/supplier_agent.py`
- [Inventory risk](https://github.com/anuragthippani1/docflow-rag/blob/main/app/agents/inventory_agent.py): `app/agents/inventory_agent.py`
- [Logistics risk](https://github.com/anuragthippani1/docflow-rag/blob/main/app/agents/logistics_agent.py): `app/agents/logistics_agent.py`
- [External risk](https://github.com/anuragthippani1/docflow-rag/blob/main/app/agents/external_risk_agent.py): `app/agents/external_risk_agent.py`
- [Final decision](https://github.com/anuragthippani1/docflow-rag/blob/main/app/agents/decision_agent.py): `app/agents/decision_agent.py`

### API and user experience

- [Web interface](https://github.com/anuragthippani1/docflow-rag/blob/main/frontend/js/chat.js): `frontend/js/chat.js`
- [Session dashboard](https://github.com/anuragthippani1/docflow-rag/blob/main/frontend/js/dashboard.js): `frontend/js/dashboard.js`
- [FastAPI routes](https://github.com/anuragthippani1/docflow-rag/blob/main/app/main.py): `app/main.py`
- [Health and stats](https://github.com/anuragthippani1/docflow-rag/blob/main/app/status.py): `app/status.py`

### Persistence and operations

- [FAISS index](https://github.com/anuragthippani1/docflow-rag/blob/main/app/ingest.py): `app/ingest.py`
- [Knowledge graph](https://github.com/anuragthippani1/docflow-rag/blob/main/app/graph.py): `app/graph.py`
- [Conversation history](https://github.com/anuragthippani1/docflow-rag/blob/main/app/conversations.py): `app/conversations.py`

### Other components

- **User**
- **External risk data**
- **OpenRouter models**

## Connections

- User → Web interface: asks or uploads
- Web interface → FastAPI routes: calls API
- FastAPI routes → PDF processing: processes uploads (evidence: `app/main.py`)
- PDF processing → FAISS index: indexes chunks (evidence: `app/ingest.py`)
- PDF processing → Entity extraction: extracts entities (evidence: `app/ingest.py`)
- PDF processing → Knowledge graph: upserts extraction (evidence: `app/ingest.py`)
- FastAPI routes → Evidence preparation: prepares query turn (evidence: `app/main.py`)
- Evidence preparation → Conversational retrieval: retrieves evidence (evidence: `app/evidence/pipeline.py`)
- Conversational retrieval → Hybrid retrieval: builds retriever (evidence: `app/rag_chat.py`)
- Hybrid retrieval → Result reranking: may rerank (evidence: `app/retrievers/hybrid.py`)
- Evidence preparation → Evidence verification: verifies pack (evidence: `app/evidence/pipeline.py`)
- Evidence verification → OpenRouter models: checks evidence (evidence: `app/evidence/verify_openrouter.py`)
- FastAPI routes → Answer generation: generates answer (evidence: `app/main.py`)
- Answer generation → OpenRouter models: generates response
- FastAPI routes → Conversation history: stores messages (evidence: `app/main.py`)
- FastAPI routes → Agent dispatch: dispatches analysis (evidence: `app/main.py`)
- Agent dispatch → Supplier risk: runs assessment (evidence: `app/agent_router.py`)
- Agent dispatch → Inventory risk: runs assessment (evidence: `app/agent_router.py`)
- Agent dispatch → Logistics risk: runs assessment (evidence: `app/agent_router.py`)
- Agent dispatch → External risk: runs assessment (evidence: `app/agent_router.py`)
- FastAPI routes → External risk data: fetches risk context
- External risk → External risk data: uses context
- Agent dispatch → Final decision: combines assessments
- FastAPI routes → Health and stats: serves status (evidence: `app/main.py`)
- FastAPI routes → Session dashboard: returns query stats
