# yousra-khallou/achatclair architecture

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

- Interactive diagram: https://gitdiagram.com/yousra-khallou/achatclair
- Repository: https://github.com/yousra-khallou/achatclair

## Overview

AchatClair ingests purchase orders, goods receipts, and invoices, routes each document to native or multimodal extraction, normalizes the results, and applies deterministic three-way matching before persisting an auditable result. The Streamlit interface supports review and human validation; benchmark comparison and pipeline metrics provide evaluation and operational visibility. The README documents the major capabilities, while some subsystem links rely on its architecture description or SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`scripts/pipeline_orchestrator.py`](https://github.com/yousra-khallou/achatclair/blob/main/scripts/pipeline_orchestrator.py) (Ingestion orchestrator), [`scripts/run_pipeline.py`](https://github.com/yousra-khallou/achatclair/blob/main/scripts/run_pipeline.py) (Persistence and reconciliation runner), [`achatclair/reconciliation/engine.py`](https://github.com/yousra-khallou/achatclair/blob/main/achatclair/reconciliation/engine.py) (Three-way matching engine), [`scripts/vlm/extractor.py`](https://github.com/yousra-khallou/achatclair/blob/main/scripts/vlm/extractor.py) (VLM extractor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Ingestion and extraction"]
  node_orchestrator["Ingestion orchestrator"]
  node_detector["Document nature detector<br/>[detector.py]"]
  node_native["Native text extractor"]
  node_vlm["VLM extractor<br/>[extractor.py]"]
  node_converter["PDF rasterizer<br/>[converter.py]"]
  node_vlm_schema["VLM output schemas<br/>[schemas.py]"]
end

subgraph group_domain["Domain and matching"]
  node_common["Shared domain types<br/>[common.py]"]
  node_document["Purchase document models<br/>[document.py]"]
  node_dossier["Purchase dossier model<br/>[dossier.py]"]
  node_recon_models["Reconciliation result models<br/>[reconciliation.py]"]
  node_engine["Three-way matching engine<br/>[engine.py]"]
end

subgraph group_data["Persistence and evaluation"]
  node_run_pipeline["Persistence and reconciliation runner<br/>[run_pipeline.py]"]
  node_db["Production database helpers<br/>[db.py]"]
  node_postgres[("PostgreSQL production and benchmark data")]
  node_bench_load["Ground-truth loader<br/>[load_bench.py]"]
  node_benchmark["Production benchmark comparison"]
  node_llm_common["Extraction evaluation utilities<br/>[common.py]"]
  node_llm_schema["Extraction evaluation schema<br/>[schema.py]"]
end

subgraph group_operations["Review and operations"]
  node_ui["Human review interface<br/>[app.py]"]
  node_notifications["Email notifications"]
  node_airflow["MinIO-triggered pipeline"]
  node_minio_logic["MinIO event logic<br/>[minio_logic.py]"]
  node_metrics["Pipeline metrics store<br/>[metrics_store.py]"]
end

node_operator(("Pipeline operator"))
node_raw_docs["Raw purchase documents"]
node_minio[("MinIO object storage")]

node_operator -->|"runs"| node_orchestrator
node_raw_docs -->|"lands in"| node_minio
node_minio -->|"supplies files"| node_orchestrator
node_orchestrator -->|"classifies"| node_detector
node_orchestrator -->|"routes text to"| node_native
node_orchestrator -->|"routes scans to"| node_vlm
node_vlm -->|"uses rasterizer"| node_converter
node_vlm -->|"uses schemas"| node_vlm_schema
node_orchestrator -->|"persists dossier via"| node_run_pipeline
node_orchestrator -->|"runs matching"| node_engine
node_run_pipeline -->|"invokes"| node_engine
node_run_pipeline -->|"stores records via"| node_db
node_run_pipeline -->|"writes results"| node_postgres
node_db -->|"writes production data"| node_postgres
node_engine -->|"evaluates"| node_dossier
node_document -->|"uses shared types"| node_common
node_dossier -->|"groups documents"| node_document
node_dossier -->|"holds expected results"| node_recon_models
node_recon_models -->|"uses rule types"| node_common
node_bench_load -->|"loads ground truth"| node_postgres
node_benchmark -->|"compares schemas"| node_postgres
node_llm_schema -->|"uses utilities"| node_llm_common
node_ui -->|"reads and updates"| node_postgres
node_ui -->|"rechecks corrections"| node_engine
node_airflow -->|"dispatches to"| node_minio_logic
node_airflow -->|"records run metrics"| node_metrics
node_orchestrator -->|"uses notifications"| node_notifications

click node_orchestrator "https://github.com/yousra-khallou/achatclair/blob/main/scripts/pipeline_orchestrator.py"
click node_detector "https://github.com/yousra-khallou/achatclair/blob/main/scripts/vlm/detector.py"
click node_native "https://github.com/yousra-khallou/achatclair/blob/main/scripts/LLM/native_extractor.py"
click node_vlm "https://github.com/yousra-khallou/achatclair/blob/main/scripts/vlm/extractor.py"
click node_converter "https://github.com/yousra-khallou/achatclair/blob/main/scripts/vlm/converter.py"
click node_vlm_schema "https://github.com/yousra-khallou/achatclair/blob/main/scripts/vlm/schemas.py"
click node_common "https://github.com/yousra-khallou/achatclair/blob/main/achatclair/models/common.py"
click node_document "https://github.com/yousra-khallou/achatclair/blob/main/achatclair/models/document.py"
click node_dossier "https://github.com/yousra-khallou/achatclair/blob/main/achatclair/models/dossier.py"
click node_recon_models "https://github.com/yousra-khallou/achatclair/blob/main/achatclair/models/reconciliation.py"
click node_engine "https://github.com/yousra-khallou/achatclair/blob/main/achatclair/reconciliation/engine.py"
click node_run_pipeline "https://github.com/yousra-khallou/achatclair/blob/main/scripts/run_pipeline.py"
click node_db "https://github.com/yousra-khallou/achatclair/blob/main/scripts/db.py"
click node_bench_load "https://github.com/yousra-khallou/achatclair/blob/main/scripts/load_bench.py"
click node_benchmark "https://github.com/yousra-khallou/achatclair/blob/main/scripts/compare_bench_prod.py"
click node_llm_common "https://github.com/yousra-khallou/achatclair/blob/main/scripts/LLM/common.py"
click node_llm_schema "https://github.com/yousra-khallou/achatclair/blob/main/scripts/LLM/schema.py"
click node_ui "https://github.com/yousra-khallou/achatclair/blob/main/ui/app.py"
click node_notifications "https://github.com/yousra-khallou/achatclair/blob/main/scripts/email_notifications.py"
click node_airflow "https://github.com/yousra-khallou/achatclair/blob/main/airflow/dags/achatclair_minio_trigger.py"
click node_minio_logic "https://github.com/yousra-khallou/achatclair/blob/main/airflow/dags/minio_logic.py"
click node_metrics "https://github.com/yousra-khallou/achatclair/blob/main/airflow/dags/metrics_store.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_orchestrator,node_detector,node_native,node_vlm,node_converter,node_vlm_schema toneBlue
class node_common,node_document,node_dossier,node_recon_models,node_engine,node_minio toneAmber
class node_run_pipeline,node_db,node_postgres,node_bench_load,node_benchmark,node_llm_common,node_llm_schema toneMint
class node_ui,node_notifications,node_airflow,node_minio_logic,node_metrics toneRose
class node_operator,node_raw_docs toneIndigo
```

## Components

### Ingestion and extraction

- [Ingestion orchestrator](https://github.com/yousra-khallou/achatclair/blob/main/scripts/pipeline_orchestrator.py): `scripts/pipeline_orchestrator.py`
- [Document nature detector](https://github.com/yousra-khallou/achatclair/blob/main/scripts/vlm/detector.py): `scripts/vlm/detector.py`
- [Native text extractor](https://github.com/yousra-khallou/achatclair/blob/main/scripts/LLM/native_extractor.py): `scripts/LLM/native_extractor.py`
- [VLM extractor](https://github.com/yousra-khallou/achatclair/blob/main/scripts/vlm/extractor.py): `scripts/vlm/extractor.py`
- [PDF rasterizer](https://github.com/yousra-khallou/achatclair/blob/main/scripts/vlm/converter.py): `scripts/vlm/converter.py`
- [VLM output schemas](https://github.com/yousra-khallou/achatclair/blob/main/scripts/vlm/schemas.py): `scripts/vlm/schemas.py`

### Domain and matching

- [Shared domain types](https://github.com/yousra-khallou/achatclair/blob/main/achatclair/models/common.py): `achatclair/models/common.py`
- [Purchase document models](https://github.com/yousra-khallou/achatclair/blob/main/achatclair/models/document.py): `achatclair/models/document.py`
- [Purchase dossier model](https://github.com/yousra-khallou/achatclair/blob/main/achatclair/models/dossier.py): `achatclair/models/dossier.py`
- [Reconciliation result models](https://github.com/yousra-khallou/achatclair/blob/main/achatclair/models/reconciliation.py): `achatclair/models/reconciliation.py`
- [Three-way matching engine](https://github.com/yousra-khallou/achatclair/blob/main/achatclair/reconciliation/engine.py): `achatclair/reconciliation/engine.py`

### Persistence and evaluation

- [Persistence and reconciliation runner](https://github.com/yousra-khallou/achatclair/blob/main/scripts/run_pipeline.py): `scripts/run_pipeline.py`
- [Production database helpers](https://github.com/yousra-khallou/achatclair/blob/main/scripts/db.py): `scripts/db.py`
- **PostgreSQL production and benchmark data**
- [Ground-truth loader](https://github.com/yousra-khallou/achatclair/blob/main/scripts/load_bench.py): `scripts/load_bench.py`
- [Production benchmark comparison](https://github.com/yousra-khallou/achatclair/blob/main/scripts/compare_bench_prod.py): `scripts/compare_bench_prod.py`
- [Extraction evaluation utilities](https://github.com/yousra-khallou/achatclair/blob/main/scripts/LLM/common.py): `scripts/LLM/common.py`
- [Extraction evaluation schema](https://github.com/yousra-khallou/achatclair/blob/main/scripts/LLM/schema.py): `scripts/LLM/schema.py`

### Review and operations

- [Human review interface](https://github.com/yousra-khallou/achatclair/blob/main/ui/app.py): `ui/app.py`
- [Email notifications](https://github.com/yousra-khallou/achatclair/blob/main/scripts/email_notifications.py): `scripts/email_notifications.py`
- [MinIO-triggered pipeline](https://github.com/yousra-khallou/achatclair/blob/main/airflow/dags/achatclair_minio_trigger.py): `airflow/dags/achatclair_minio_trigger.py`
- [MinIO event logic](https://github.com/yousra-khallou/achatclair/blob/main/airflow/dags/minio_logic.py): `airflow/dags/minio_logic.py`
- [Pipeline metrics store](https://github.com/yousra-khallou/achatclair/blob/main/airflow/dags/metrics_store.py): `airflow/dags/metrics_store.py`

### Other components

- **Pipeline operator**
- **Raw purchase documents**
- **MinIO object storage**

## Connections

- Pipeline operator → Ingestion orchestrator: runs (evidence: `scripts/pipeline_orchestrator.py`)
- Raw purchase documents → MinIO object storage: lands in
- MinIO object storage → Ingestion orchestrator: supplies files
- Ingestion orchestrator → Document nature detector: classifies (evidence: `scripts/pipeline_orchestrator.py`)
- Ingestion orchestrator → Native text extractor: routes text to (evidence: `scripts/pipeline_orchestrator.py`)
- Ingestion orchestrator → VLM extractor: routes scans to (evidence: `scripts/pipeline_orchestrator.py`)
- VLM extractor → PDF rasterizer: uses rasterizer (evidence: `scripts/vlm/extractor.py`)
- VLM extractor → VLM output schemas: uses schemas (evidence: `scripts/vlm/extractor.py`)
- Ingestion orchestrator → Persistence and reconciliation runner: persists dossier via (evidence: `scripts/pipeline_orchestrator.py`)
- Ingestion orchestrator → Three-way matching engine: runs matching (evidence: `scripts/pipeline_orchestrator.py`)
- Persistence and reconciliation runner → Three-way matching engine: invokes (evidence: `scripts/run_pipeline.py`)
- Persistence and reconciliation runner → Production database helpers: stores records via (evidence: `scripts/run_pipeline.py`)
- Persistence and reconciliation runner → PostgreSQL production and benchmark data: writes results
- Production database helpers → PostgreSQL production and benchmark data: writes production data (evidence: `scripts/db.py`)
- Three-way matching engine → Purchase dossier model: evaluates (evidence: `achatclair/reconciliation/engine.py`)
- Purchase document models → Shared domain types: uses shared types (evidence: `achatclair/models/document.py`)
- Purchase dossier model → Purchase document models: groups documents (evidence: `achatclair/models/dossier.py`)
- Purchase dossier model → Reconciliation result models: holds expected results (evidence: `achatclair/models/dossier.py`)
- Reconciliation result models → Shared domain types: uses rule types (evidence: `achatclair/models/reconciliation.py`)
- Ground-truth loader → PostgreSQL production and benchmark data: loads ground truth (evidence: `scripts/load_bench.py`)
- Production benchmark comparison → PostgreSQL production and benchmark data: compares schemas
- Extraction evaluation schema → Extraction evaluation utilities: uses utilities (evidence: `scripts/LLM/schema.py`)
- Human review interface → PostgreSQL production and benchmark data: reads and updates
- Human review interface → Three-way matching engine: rechecks corrections (evidence: `ui/app.py`)
- MinIO-triggered pipeline → MinIO event logic: dispatches to (evidence: `airflow/dags/achatclair_minio_trigger.py`)
- MinIO-triggered pipeline → Pipeline metrics store: records run metrics (evidence: `airflow/dags/achatclair_minio_trigger.py`)
- Ingestion orchestrator → Email notifications: uses notifications (evidence: `scripts/pipeline_orchestrator.py`)
