# bhavikadlecha/enterprise-invoice-extractor architecture

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

- Interactive diagram: https://gitdiagram.com/bhavikadlecha/enterprise-invoice-extractor
- Repository: https://github.com/bhavikadlecha/enterprise-invoice-extractor

## Overview

This is an invoice-processing product for Accounts Payable: users upload PDF/image invoices, receive schema-validated extraction, and get semantic purchase-order matching for review. The Streamlit UI drives a FastAPI service; that service also supports ZIP batch jobs, PO creation, and operational metrics. Vision preprocessing, LLM extraction with validation retries, PO retrieval, and SQLite tracking form the internal processing layers. Some API-to-worker orchestration details are omitted from the excerpts, so those links are marked unverified rather than inferred as direct calls.

Main entry points: [`app/main.py`](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/main.py) (FastAPI API), [`app/extractor.py`](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/extractor.py) (Invoice Extractor), [`app/batch/processor.py`](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/batch/processor.py) (Batch Processor), [`frontend/streamlit_app.py`](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/frontend/streamlit_app.py) (Streamlit UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User Experience"]
  node_streamlit["Streamlit UI<br/>[streamlit_app.py]"]
end

subgraph group_service["Invoice Service"]
  node_api["FastAPI API<br/>[main.py]"]
  node_fileprep["File Preparation<br/>[vision.py]"]
  node_extractor["Invoice Extractor<br/>[extractor.py]"]
  node_schema["Invoice Validation<br/>[schemas.py]"]
  node_batch["Batch Processor<br/>[processor.py]"]
  node_jobs[("Batch Job State<br/>[processor.py]")]
end

subgraph group_matching["PO Matching"]
  node_matcher["PO Matcher<br/>[matcher.py]"]
  node_po_store[("PO Vector Store<br/>[po_store.py]")]
  node_po_catalog["PO Catalog<br/>[main.py]"]
end

subgraph group_operations["Operations"]
  node_metrics["Metrics Tracker<br/>[tracker.py]"]
  node_metrics_db[("Metrics SQLite<br/>[tracker.py]")]
  node_settings["Runtime Settings<br/>[config.py]"]
end

node_accountant(("Accountant"))
node_llm{{"Vision LLM"}}

node_accountant -->|"uploads invoice"| node_streamlit
node_streamlit -->|"submits and polls"| node_api
node_api -.->|"prepares upload"| node_fileprep
node_fileprep -->|"encodes image"| node_extractor
node_api -->|"requests extraction"| node_extractor
node_extractor -->|"validates output"| node_schema
node_extractor -->|"extracts fields"| node_llm
node_extractor -->|"records usage"| node_metrics
node_api -->|"requests PO match"| node_matcher
node_matcher -->|"searches candidates"| node_po_store
node_api -->|"adds purchase order"| node_po_catalog
node_po_catalog -->|"stores PO"| node_po_store
node_api -.->|"starts batch job"| node_batch
node_batch -->|"converts files"| node_fileprep
node_batch -->|"extracts invoices"| node_extractor
node_batch -->|"matches invoices"| node_matcher
node_batch -->|"updates job state"| node_jobs
node_api -.->|"reads job status"| node_jobs
node_api -->|"requests summaries"| node_metrics
node_streamlit -->|"loads metrics"| node_api
node_metrics -->|"reads and writes"| node_metrics_db

click node_streamlit "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/frontend/streamlit_app.py"
click node_api "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/main.py"
click node_fileprep "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/vision.py"
click node_extractor "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/extractor.py"
click node_schema "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/schemas.py"
click node_batch "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/batch/processor.py"
click node_jobs "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/batch/processor.py"
click node_matcher "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/rag/matcher.py"
click node_po_store "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/rag/po_store.py"
click node_po_catalog "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/main.py"
click node_metrics "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/observability/tracker.py"
click node_metrics_db "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/observability/tracker.py"
click node_settings "https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/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_streamlit toneBlue
class node_api,node_fileprep,node_extractor,node_schema,node_batch,node_jobs toneAmber
class node_matcher,node_po_store,node_po_catalog toneMint
class node_metrics,node_metrics_db,node_settings toneRose
class node_accountant,node_llm toneIndigo
```

## Components

### User Experience

- [Streamlit UI](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/frontend/streamlit_app.py): `frontend/streamlit_app.py`

### Invoice Service

- [FastAPI API](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/main.py): `app/main.py`
- [File Preparation](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/vision.py): `app/vision.py`
- [Invoice Extractor](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/extractor.py): `app/extractor.py`
- [Invoice Validation](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/schemas.py): `app/schemas.py`
- [Batch Processor](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/batch/processor.py): `app/batch/processor.py`
- [Batch Job State](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/batch/processor.py): `app/batch/processor.py`

### PO Matching

- [PO Matcher](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/rag/matcher.py): `app/rag/matcher.py`
- [PO Vector Store](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/rag/po_store.py): `app/rag/po_store.py`
- [PO Catalog](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/main.py): `app/main.py`

### Operations

- [Metrics Tracker](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/observability/tracker.py): `app/observability/tracker.py`
- [Metrics SQLite](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/observability/tracker.py): `app/observability/tracker.py`
- [Runtime Settings](https://github.com/bhavikadlecha/enterprise-invoice-extractor/blob/master/app/config.py): `app/config.py`

### Other components

- **Accountant**
- **Vision LLM**

## Connections

- Accountant → Streamlit UI: uploads invoice (evidence: `README.md`)
- Streamlit UI → FastAPI API: submits and polls (evidence: `frontend/streamlit_app.py`)
- FastAPI API → File Preparation: prepares upload (evidence: `app/main.py`)
- File Preparation → Invoice Extractor: encodes image (evidence: `app/batch/processor.py`)
- FastAPI API → Invoice Extractor: requests extraction (evidence: `README.md`)
- Invoice Extractor → Invoice Validation: validates output (evidence: `app/extractor.py`)
- Invoice Extractor → Vision LLM: extracts fields (evidence: `README.md`)
- Invoice Extractor → Metrics Tracker: records usage (evidence: `app/extractor.py`)
- FastAPI API → PO Matcher: requests PO match (evidence: `README.md`)
- PO Matcher → PO Vector Store: searches candidates (evidence: `app/rag/matcher.py`)
- FastAPI API → PO Catalog: adds purchase order (evidence: `app/main.py`)
- PO Catalog → PO Vector Store: stores PO (evidence: `app/main.py`)
- FastAPI API → Batch Processor: starts batch job (evidence: `app/main.py`)
- Batch Processor → File Preparation: converts files (evidence: `app/batch/processor.py`)
- Batch Processor → Invoice Extractor: extracts invoices (evidence: `app/batch/processor.py`)
- Batch Processor → PO Matcher: matches invoices (evidence: `app/batch/processor.py`)
- Batch Processor → Batch Job State: updates job state (evidence: `app/batch/processor.py`)
- FastAPI API → Batch Job State: reads job status (evidence: `app/main.py`)
- FastAPI API → Metrics Tracker: requests summaries (evidence: `app/main.py`)
- Streamlit UI → FastAPI API: loads metrics (evidence: `frontend/streamlit_app.py`)
- Metrics Tracker → Metrics SQLite: reads and writes (evidence: `app/observability/tracker.py`)
