# namwebd/ml-freight-invoice architecture

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

- Interactive diagram: https://gitdiagram.com/namwebd/ml-freight-invoice
- Repository: https://github.com/namwebd/ml-freight-invoice

## Overview

The Vendor Invoice Intelligence Portal is a Streamlit decision-support application with two user workflows: estimate freight cost from quantity and invoice dollars, or flag an invoice for manual approval. The app dispatches submitted inputs to separate inference modules and presents the prediction. The repository also contains offline training and data-preparation code for both prediction domains. The freight training flow is visible in source; invoice training and inference internals are not fully sampled, so those connections are omitted or marked unverified.

Main entry points: [`app.py`](https://github.com/namwebd/ml-freight-invoice/blob/main/app.py) (Streamlit portal), [`freight_cost_prediction/train.py`](https://github.com/namwebd/ml-freight-invoice/blob/main/freight_cost_prediction/train.py) (Freight training), [`invoice_flagging/train.py`](https://github.com/namwebd/ml-freight-invoice/blob/main/invoice_flagging/train.py) (Invoice model training), [`inference/predict_freight.py`](https://github.com/namwebd/ml-freight-invoice/blob/main/inference/predict_freight.py) (Freight inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_portal["User portal"]
  node_portal_app["Streamlit portal<br/>[app.py]"]
end

subgraph group_freight["Freight prediction"]
  node_freight_infer["Freight inference<br/>[predict_freight.py]"]
  node_freight_model["Freight model"]
end

subgraph group_invoice["Invoice risk"]
  node_invoice_infer["Invoice flag inference"]
  node_invoice_model["Invoice flag model"]
end

subgraph group_training["Model preparation"]
  node_freight_prep["Freight data preparation"]
  node_freight_train["Freight training<br/>[train.py]"]
  node_freight_eval["Regression training and evaluation"]
  node_invoice_prep["Invoice data preparation"]
  node_invoice_train["Invoice model training<br/>[train.py]"]
  node_invoice_eval["Classifier training and evaluation"]
  node_scaler["Feature scaler<br/>[scaler.pkl]"]
end

node_user(("Finance / operations user"))
node_sqlite[("SQLite invoice data")]

node_user -->|"enters inputs"| node_portal_app
node_portal_app -->|"requests estimate"| node_freight_infer
node_freight_infer -->|"returns estimate"| node_portal_app
node_portal_app -->|"requests risk check"| node_invoice_infer
node_invoice_infer -->|"returns flag"| node_portal_app
node_freight_infer -->|"loads model"| node_freight_model
node_freight_train -->|"loads and prepares data"| node_freight_prep
node_freight_train -->|"trains and evaluates"| node_freight_eval
node_freight_prep -->|"reads invoices"| node_sqlite
node_freight_train -->|"saves selected model"| node_freight_model
node_invoice_prep -->|"queries invoice and purchase data"| node_sqlite
node_invoice_prep -->|"saves fitted scaler"| node_scaler
node_invoice_train -.->|"uses preparation"| node_invoice_prep
node_invoice_train -.->|"uses classifier evaluation"| node_invoice_eval
node_invoice_train -.->|"produces model"| node_invoice_model
node_invoice_infer -.->|"loads model"| node_invoice_model

click node_portal_app "https://github.com/namwebd/ml-freight-invoice/blob/main/app.py"
click node_freight_infer "https://github.com/namwebd/ml-freight-invoice/blob/main/inference/predict_freight.py"
click node_freight_model "https://github.com/namwebd/ml-freight-invoice/blob/main/models/predict_freight_model.pkl"
click node_invoice_infer "https://github.com/namwebd/ml-freight-invoice/blob/main/inference/predict_invoice_flag.py"
click node_invoice_model "https://github.com/namwebd/ml-freight-invoice/blob/main/models/predict_flag_invoice.pkl"
click node_freight_prep "https://github.com/namwebd/ml-freight-invoice/blob/main/freight_cost_prediction/data_preprocessing.py"
click node_freight_train "https://github.com/namwebd/ml-freight-invoice/blob/main/freight_cost_prediction/train.py"
click node_freight_eval "https://github.com/namwebd/ml-freight-invoice/blob/main/freight_cost_prediction/model_evaluation.py"
click node_invoice_prep "https://github.com/namwebd/ml-freight-invoice/blob/main/invoice_flagging/data_preprocessing.py"
click node_invoice_train "https://github.com/namwebd/ml-freight-invoice/blob/main/invoice_flagging/train.py"
click node_invoice_eval "https://github.com/namwebd/ml-freight-invoice/blob/main/invoice_flagging/modelling_evaluation.py"
click node_scaler "https://github.com/namwebd/ml-freight-invoice/blob/main/models/scaler.pkl"

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_portal_app,node_user toneBlue
class node_freight_infer,node_freight_model,node_sqlite toneAmber
class node_invoice_infer,node_invoice_model toneMint
class node_freight_prep,node_freight_train,node_freight_eval,node_invoice_prep,node_invoice_train,node_invoice_eval,node_scaler toneRose
```

## Components

### User portal

- [Streamlit portal](https://github.com/namwebd/ml-freight-invoice/blob/main/app.py): `app.py`

### Freight prediction

- [Freight inference](https://github.com/namwebd/ml-freight-invoice/blob/main/inference/predict_freight.py): `inference/predict_freight.py`
- [Freight model](https://github.com/namwebd/ml-freight-invoice/blob/main/models/predict_freight_model.pkl): `models/predict_freight_model.pkl`

### Invoice risk

- [Invoice flag inference](https://github.com/namwebd/ml-freight-invoice/blob/main/inference/predict_invoice_flag.py): `inference/predict_invoice_flag.py`
- [Invoice flag model](https://github.com/namwebd/ml-freight-invoice/blob/main/models/predict_flag_invoice.pkl): `models/predict_flag_invoice.pkl`

### Model preparation

- [Freight data preparation](https://github.com/namwebd/ml-freight-invoice/blob/main/freight_cost_prediction/data_preprocessing.py): `freight_cost_prediction/data_preprocessing.py`
- [Freight training](https://github.com/namwebd/ml-freight-invoice/blob/main/freight_cost_prediction/train.py): `freight_cost_prediction/train.py`
- [Regression training and evaluation](https://github.com/namwebd/ml-freight-invoice/blob/main/freight_cost_prediction/model_evaluation.py): `freight_cost_prediction/model_evaluation.py`
- [Invoice data preparation](https://github.com/namwebd/ml-freight-invoice/blob/main/invoice_flagging/data_preprocessing.py): `invoice_flagging/data_preprocessing.py`
- [Invoice model training](https://github.com/namwebd/ml-freight-invoice/blob/main/invoice_flagging/train.py): `invoice_flagging/train.py`
- [Classifier training and evaluation](https://github.com/namwebd/ml-freight-invoice/blob/main/invoice_flagging/modelling_evaluation.py): `invoice_flagging/modelling_evaluation.py`
- [Feature scaler](https://github.com/namwebd/ml-freight-invoice/blob/main/models/scaler.pkl): `models/scaler.pkl`

### Other components

- **Finance / operations user**
- **SQLite invoice data**

## Connections

- Finance / operations user → Streamlit portal: enters inputs (evidence: `app.py`)
- Streamlit portal → Freight inference: requests estimate (evidence: `app.py`)
- Freight inference → Streamlit portal: returns estimate (evidence: `app.py`)
- Streamlit portal → Invoice flag inference: requests risk check (evidence: `app.py`)
- Invoice flag inference → Streamlit portal: returns flag (evidence: `app.py`)
- Freight inference → Freight model: loads model (evidence: `inference/predict_freight.py`)
- Freight training → Freight data preparation: loads and prepares data (evidence: `freight_cost_prediction/train.py`)
- Freight training → Regression training and evaluation: trains and evaluates (evidence: `freight_cost_prediction/train.py`)
- Freight data preparation → SQLite invoice data: reads invoices (evidence: `freight_cost_prediction/data_preprocessing.py`)
- Freight training → Freight model: saves selected model (evidence: `freight_cost_prediction/train.py`)
- Invoice data preparation → SQLite invoice data: queries invoice and purchase data (evidence: `invoice_flagging/data_preprocessing.py`)
- Invoice data preparation → Feature scaler: saves fitted scaler (evidence: `invoice_flagging/data_preprocessing.py`)
- Invoice model training → Invoice data preparation: uses preparation
- Invoice model training → Classifier training and evaluation: uses classifier evaluation
- Invoice model training → Invoice flag model: produces model
- Invoice flag inference → Invoice flag model: loads model
