# vaibhav2824/veridoc architecture

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

- Interactive diagram: https://gitdiagram.com/vaibhav2824/veridoc
- Repository: https://github.com/vaibhav2824/veridoc

## Overview

VeriDoc accepts invoice and bank-statement documents through a web UI, API, or MCP tools; classifies and extracts fields; verifies invoice values with confidence and page locations; and abstains uncertain fields for human review. The API also stores jobs and review state and can use past invoices as retrieval exemplars. The graph follows documented workflow and visible imports/calls; unsampled subsystems are included where the README documents them, with evidence limits reflected in the edges.

Main entry points: [`services/api/extractor.py`](https://github.com/vaibhav2824/veridoc/blob/main/services/api/extractor.py) (Invoice and statement extraction), [`services/api/main.py`](https://github.com/vaibhav2824/veridoc/blob/main/services/api/main.py) (FastAPI endpoints), [`services/api/graph.py`](https://github.com/vaibhav2824/veridoc/blob/main/services/api/graph.py) (Pipeline orchestration), [`services/api/nodes/router.py`](https://github.com/vaibhav2824/veridoc/blob/main/services/api/nodes/router.py) (Document router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_web["Web UI"]
  node_api_client["Web API client<br/>[api.ts]"]
  node_mcp["MCP tools<br/>[server.py]"]
end

subgraph group_workflow["Document workflow"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_ingest["Document ingestion<br/>[ingest.py]"]
  node_graph["Pipeline orchestration<br/>[graph.py]"]
  node_router["Document router<br/>[router.py]"]
  node_router_schema["Document type schema<br/>[router.py]"]
  node_review["Human review queue<br/>[review_queue.py]"]
end

subgraph group_trust["Extraction and trust"]
  node_extractor["Invoice and statement extraction<br/>[extractor.py]"]
  node_invoice_schema["Invoice schema<br/>[invoice.py]"]
  node_statement_schema["Statement schema<br/>[bank_statement.py]"]
  node_verifier["Field verification<br/>[verifier.py]"]
  node_gate["Confidence gate<br/>[gate.py]"]
  node_verified["Verified results"]
end

subgraph group_state["State and retrieval"]
  node_db[("Jobs and audit store<br/>[db.py]")]
  node_rag["Invoice exemplars<br/>[retrieval.py]"]
end

subgraph group_integrations["Models and tools"]
  node_vlm["Vision-language clients"]
  node_model_service["Gemini or Groq"]
end

node_user(("Document user"))

node_user -->|"uploads document"| node_web
node_web -->|"uses API"| node_api_client
node_api_client -->|"calls endpoints"| node_api
node_api -->|"runs pipeline"| node_graph
node_api -->|"stores job state"| node_db
node_api -->|"serves and resolves"| node_review
node_graph -->|"loads pages"| node_ingest
node_graph -->|"classifies document"| node_router
node_router -->|"returns classification"| node_router_schema
node_router -->|"uses fallback"| node_vlm
node_graph -->|"dispatches extraction"| node_extractor
node_extractor -->|"requests structured fields"| node_vlm
node_extractor -->|"extracts invoice"| node_invoice_schema
node_extractor -->|"extracts statement"| node_statement_schema
node_extractor -->|"verifies invoice fields"| node_verifier
node_extractor -->|"applies threshold"| node_gate
node_gate -->|"produces confidence results"| node_verified
node_api -->|"queues uncertain fields"| node_review
node_extractor -->|"retrieves exemplars"| node_rag
node_extractor -->|"stores confident examples"| node_rag
node_rag -->|"uses pgvector store"| node_db
node_mcp -->|"runs document pipeline"| node_graph
node_mcp -->|"runs direct extraction"| node_extractor
node_vlm -.->|"calls provider"| node_model_service

click node_web "https://github.com/vaibhav2824/veridoc/tree/main/web/app"
click node_api_client "https://github.com/vaibhav2824/veridoc/blob/main/web/lib/api.ts"
click node_api "https://github.com/vaibhav2824/veridoc/blob/main/services/api/main.py"
click node_ingest "https://github.com/vaibhav2824/veridoc/blob/main/services/api/ingest.py"
click node_graph "https://github.com/vaibhav2824/veridoc/blob/main/services/api/graph.py"
click node_router "https://github.com/vaibhav2824/veridoc/blob/main/services/api/nodes/router.py"
click node_router_schema "https://github.com/vaibhav2824/veridoc/blob/main/services/api/models/router.py"
click node_extractor "https://github.com/vaibhav2824/veridoc/blob/main/services/api/extractor.py"
click node_vlm "https://github.com/vaibhav2824/veridoc/tree/main/services/api/clients"
click node_invoice_schema "https://github.com/vaibhav2824/veridoc/blob/main/services/api/models/invoice.py"
click node_statement_schema "https://github.com/vaibhav2824/veridoc/blob/main/services/api/models/bank_statement.py"
click node_verifier "https://github.com/vaibhav2824/veridoc/blob/main/services/api/nodes/verifier.py"
click node_gate "https://github.com/vaibhav2824/veridoc/blob/main/services/api/nodes/gate.py"
click node_verified "https://github.com/vaibhav2824/veridoc/blob/main/services/api/models/verified_invoice.py"
click node_review "https://github.com/vaibhav2824/veridoc/blob/main/services/api/models/review_queue.py"
click node_db "https://github.com/vaibhav2824/veridoc/blob/main/services/api/db.py"
click node_rag "https://github.com/vaibhav2824/veridoc/blob/main/services/api/rag/retrieval.py"
click node_mcp "https://github.com/vaibhav2824/veridoc/blob/main/services/mcp/server.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_api_client,node_mcp,node_user toneBlue
class node_api,node_ingest,node_graph,node_router,node_router_schema,node_review toneAmber
class node_extractor,node_invoice_schema,node_statement_schema,node_verifier,node_gate,node_verified toneMint
class node_db,node_rag toneRose
class node_vlm,node_model_service toneIndigo
```

## Components

### User interfaces

- [Web UI](https://github.com/vaibhav2824/veridoc/tree/main/web/app): `web/app`
- [Web API client](https://github.com/vaibhav2824/veridoc/blob/main/web/lib/api.ts): `web/lib/api.ts`
- [MCP tools](https://github.com/vaibhav2824/veridoc/blob/main/services/mcp/server.py): `services/mcp/server.py`

### Document workflow

- [FastAPI endpoints](https://github.com/vaibhav2824/veridoc/blob/main/services/api/main.py): `services/api/main.py`
- [Document ingestion](https://github.com/vaibhav2824/veridoc/blob/main/services/api/ingest.py): `services/api/ingest.py`
- [Pipeline orchestration](https://github.com/vaibhav2824/veridoc/blob/main/services/api/graph.py): `services/api/graph.py`
- [Document router](https://github.com/vaibhav2824/veridoc/blob/main/services/api/nodes/router.py): `services/api/nodes/router.py`
- [Document type schema](https://github.com/vaibhav2824/veridoc/blob/main/services/api/models/router.py): `services/api/models/router.py`
- [Human review queue](https://github.com/vaibhav2824/veridoc/blob/main/services/api/models/review_queue.py): `services/api/models/review_queue.py`

### Extraction and trust

- [Invoice and statement extraction](https://github.com/vaibhav2824/veridoc/blob/main/services/api/extractor.py): `services/api/extractor.py`
- [Invoice schema](https://github.com/vaibhav2824/veridoc/blob/main/services/api/models/invoice.py): `services/api/models/invoice.py`
- [Statement schema](https://github.com/vaibhav2824/veridoc/blob/main/services/api/models/bank_statement.py): `services/api/models/bank_statement.py`
- [Field verification](https://github.com/vaibhav2824/veridoc/blob/main/services/api/nodes/verifier.py): `services/api/nodes/verifier.py`
- [Confidence gate](https://github.com/vaibhav2824/veridoc/blob/main/services/api/nodes/gate.py): `services/api/nodes/gate.py`
- [Verified results](https://github.com/vaibhav2824/veridoc/blob/main/services/api/models/verified_invoice.py): `services/api/models/verified_invoice.py`

### State and retrieval

- [Jobs and audit store](https://github.com/vaibhav2824/veridoc/blob/main/services/api/db.py): `services/api/db.py`
- [Invoice exemplars](https://github.com/vaibhav2824/veridoc/blob/main/services/api/rag/retrieval.py): `services/api/rag/retrieval.py`

### Models and tools

- [Vision-language clients](https://github.com/vaibhav2824/veridoc/tree/main/services/api/clients): `services/api/clients`
- **Gemini or Groq**

### Other components

- **Document user**

## Connections

- Document user → Web UI: uploads document (evidence: `README.md`)
- Web UI → Web API client: uses API (evidence: `README.md`)
- Web API client → FastAPI endpoints: calls endpoints (evidence: `README.md`)
- FastAPI endpoints → Pipeline orchestration: runs pipeline (evidence: `services/api/main.py`)
- FastAPI endpoints → Jobs and audit store: stores job state (evidence: `services/api/main.py`)
- FastAPI endpoints → Human review queue: serves and resolves (evidence: `services/api/main.py`)
- Pipeline orchestration → Document ingestion: loads pages (evidence: `services/api/graph.py`)
- Pipeline orchestration → Document router: classifies document (evidence: `README.md`)
- Document router → Document type schema: returns classification (evidence: `services/api/nodes/router.py`)
- Document router → Vision-language clients: uses fallback (evidence: `services/api/nodes/router.py`)
- Pipeline orchestration → Invoice and statement extraction: dispatches extraction (evidence: `README.md`)
- Invoice and statement extraction → Vision-language clients: requests structured fields (evidence: `services/api/extractor.py`)
- Invoice and statement extraction → Invoice schema: extracts invoice (evidence: `services/api/extractor.py`)
- Invoice and statement extraction → Statement schema: extracts statement (evidence: `services/api/extractor.py`)
- Invoice and statement extraction → Field verification: verifies invoice fields (evidence: `services/api/extractor.py`)
- Invoice and statement extraction → Confidence gate: applies threshold (evidence: `services/api/extractor.py`)
- Confidence gate → Verified results: produces confidence results (evidence: `README.md`)
- FastAPI endpoints → Human review queue: queues uncertain fields (evidence: `README.md`)
- Invoice and statement extraction → Invoice exemplars: retrieves exemplars (evidence: `services/api/extractor.py`)
- Invoice and statement extraction → Invoice exemplars: stores confident examples (evidence: `services/api/extractor.py`)
- Invoice exemplars → Jobs and audit store: uses pgvector store (evidence: `README.md`)
- MCP tools → Pipeline orchestration: runs document pipeline (evidence: `services/mcp/server.py`)
- MCP tools → Invoice and statement extraction: runs direct extraction (evidence: `services/mcp/server.py`)
- Vision-language clients → Gemini or Groq: calls provider (evidence: `README.md`)
