# biki989/invoice_flagging_prediction architecture

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

- Interactive diagram: https://gitdiagram.com/biki989/invoice_flagging_prediction
- Repository: https://github.com/biki989/invoice_flagging_prediction

## Overview

This application serves two procurement workflows: estimate freight from invoice dollars, and flag suspicious invoices using both sanity rules and a trained classifier. The browser dashboard sends requests to Flask, which loads saved models and returns results. Separate training pipelines prepare SQLite data, fit and evaluate models, and save artifacts; standalone inference scripts provide another way to run predictions. The README documents the database and broader training details, but the database file is absent from the supplied tree, and some training behavior is therefore represented from documentation rather than sampled source.

Main entry points: [`static/script.js`](https://github.com/biki989/invoice_flagging_prediction/blob/main/static/script.js) (Form Requests), [`app.py`](https://github.com/biki989/invoice_flagging_prediction/blob/main/app.py) (Invoice Endpoint), [`invoice_flagging/train.py`](https://github.com/biki989/invoice_flagging_prediction/blob/main/invoice_flagging/train.py) (Flag Training), [`Freight_cost_prediction/train.py`](https://github.com/biki989/invoice_flagging_prediction/blob/main/Freight_cost_prediction/train.py) (Freight Training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Dashboard"]
  node_dashboard["Web Dashboard<br/>[index.html]"]
  node_browser_logic["Form Requests<br/>[script.js]"]
  node_result_view["Prediction Results<br/>[script.js]"]
end

subgraph group_serving["Flask Serving"]
  node_freight_api["Freight Endpoint<br/>[app.py]"]
  node_invoice_api["Invoice Endpoint<br/>[app.py]"]
  node_rule_check["Sanity Rules<br/>[app.py]"]
end

subgraph group_freight["Freight Pipeline"]
  node_freight_inference["Freight Inference<br/>[predict_freight.py]"]
  node_freight_train["Freight Training<br/>[train.py]"]
  node_freight_data["Freight Preparation"]
  node_freight_eval["Regressor Evaluation"]
end

subgraph group_invoice["Invoice Pipeline"]
  node_invoice_inference["Flag Inference"]
  node_invoice_train["Flag Training<br/>[train.py]"]
  node_invoice_data["Invoice Preparation"]
  node_invoice_eval["Classifier Evaluation"]
end

subgraph group_artifacts["Model Artifacts"]
  node_freight_model["Freight Model"]
  node_invoice_model["Flag Classifier"]
  node_feature_scaler["Feature Scaler<br/>[scaler.pkl]"]
end

node_team(("Procurement User"))
node_inventory_db[("Inventory SQLite Data")]

node_team -->|"uses"| node_dashboard
node_dashboard -->|"loads"| node_browser_logic
node_browser_logic -->|"posts freight"| node_freight_api
node_browser_logic -->|"posts invoice"| node_invoice_api
node_freight_api -->|"predicts with"| node_freight_model
node_invoice_api -->|"checks inputs"| node_rule_check
node_invoice_api -->|"scales features"| node_feature_scaler
node_invoice_api -->|"predicts with"| node_invoice_model
node_freight_api -->|"returns estimate"| node_browser_logic
node_invoice_api -->|"returns flag"| node_browser_logic
node_browser_logic -->|"renders result"| node_result_view
node_freight_inference -->|"loads model"| node_freight_model
node_invoice_inference -->|"loads model"| node_invoice_model
node_invoice_inference -->|"loads scaler"| node_feature_scaler
node_freight_train -->|"loads and prepares"| node_freight_data
node_freight_train -->|"trains and evaluates"| node_freight_eval
node_freight_data -->|"reads invoices"| node_inventory_db
node_freight_train -->|"saves best model"| node_freight_model
node_invoice_train -->|"prepares features"| node_invoice_data
node_invoice_train -->|"trains and evaluates"| node_invoice_eval
node_invoice_data -->|"joins invoice and PO data"| node_inventory_db
node_invoice_train -->|"saves scaler"| node_feature_scaler
node_invoice_train -->|"saves classifier"| node_invoice_model

click node_dashboard "https://github.com/biki989/invoice_flagging_prediction/blob/main/templates/index.html"
click node_browser_logic "https://github.com/biki989/invoice_flagging_prediction/blob/main/static/script.js"
click node_freight_api "https://github.com/biki989/invoice_flagging_prediction/blob/main/app.py"
click node_invoice_api "https://github.com/biki989/invoice_flagging_prediction/blob/main/app.py"
click node_rule_check "https://github.com/biki989/invoice_flagging_prediction/blob/main/app.py"
click node_freight_model "https://github.com/biki989/invoice_flagging_prediction/blob/main/models/predict_freight_model.pkl"
click node_invoice_model "https://github.com/biki989/invoice_flagging_prediction/blob/main/models/predict_flag_invoice.pkl"
click node_feature_scaler "https://github.com/biki989/invoice_flagging_prediction/blob/main/models/scaler.pkl"
click node_freight_inference "https://github.com/biki989/invoice_flagging_prediction/blob/main/inference/predict_freight.py"
click node_invoice_inference "https://github.com/biki989/invoice_flagging_prediction/blob/main/inference/predict_invoice_flag.py"
click node_freight_train "https://github.com/biki989/invoice_flagging_prediction/blob/main/Freight_cost_prediction/train.py"
click node_freight_data "https://github.com/biki989/invoice_flagging_prediction/blob/main/Freight_cost_prediction/data_preprocessing.py"
click node_freight_eval "https://github.com/biki989/invoice_flagging_prediction/blob/main/Freight_cost_prediction/model_evaluation.py"
click node_invoice_train "https://github.com/biki989/invoice_flagging_prediction/blob/main/invoice_flagging/train.py"
click node_invoice_data "https://github.com/biki989/invoice_flagging_prediction/blob/main/invoice_flagging/data_preprocessing.py"
click node_invoice_eval "https://github.com/biki989/invoice_flagging_prediction/blob/main/invoice_flagging/modeling_evaluation.py"
click node_result_view "https://github.com/biki989/invoice_flagging_prediction/blob/main/static/script.js"

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_dashboard,node_browser_logic,node_result_view,node_team toneBlue
class node_freight_api,node_invoice_api,node_rule_check,node_inventory_db toneAmber
class node_freight_inference,node_freight_train,node_freight_data,node_freight_eval toneMint
class node_invoice_inference,node_invoice_train,node_invoice_data,node_invoice_eval toneRose
class node_freight_model,node_invoice_model,node_feature_scaler toneIndigo
```

## Components

### Dashboard

- [Web Dashboard](https://github.com/biki989/invoice_flagging_prediction/blob/main/templates/index.html): `templates/index.html`
- [Form Requests](https://github.com/biki989/invoice_flagging_prediction/blob/main/static/script.js): `static/script.js`
- [Prediction Results](https://github.com/biki989/invoice_flagging_prediction/blob/main/static/script.js): `static/script.js`

### Flask Serving

- [Freight Endpoint](https://github.com/biki989/invoice_flagging_prediction/blob/main/app.py): `app.py`
- [Invoice Endpoint](https://github.com/biki989/invoice_flagging_prediction/blob/main/app.py): `app.py`
- [Sanity Rules](https://github.com/biki989/invoice_flagging_prediction/blob/main/app.py): `app.py`

### Freight Pipeline

- [Freight Inference](https://github.com/biki989/invoice_flagging_prediction/blob/main/inference/predict_freight.py): `inference/predict_freight.py`
- [Freight Training](https://github.com/biki989/invoice_flagging_prediction/blob/main/Freight_cost_prediction/train.py): `Freight_cost_prediction/train.py`
- [Freight Preparation](https://github.com/biki989/invoice_flagging_prediction/blob/main/Freight_cost_prediction/data_preprocessing.py): `Freight_cost_prediction/data_preprocessing.py`
- [Regressor Evaluation](https://github.com/biki989/invoice_flagging_prediction/blob/main/Freight_cost_prediction/model_evaluation.py): `Freight_cost_prediction/model_evaluation.py`

### Invoice Pipeline

- [Flag Inference](https://github.com/biki989/invoice_flagging_prediction/blob/main/inference/predict_invoice_flag.py): `inference/predict_invoice_flag.py`
- [Flag Training](https://github.com/biki989/invoice_flagging_prediction/blob/main/invoice_flagging/train.py): `invoice_flagging/train.py`
- [Invoice Preparation](https://github.com/biki989/invoice_flagging_prediction/blob/main/invoice_flagging/data_preprocessing.py): `invoice_flagging/data_preprocessing.py`
- [Classifier Evaluation](https://github.com/biki989/invoice_flagging_prediction/blob/main/invoice_flagging/modeling_evaluation.py): `invoice_flagging/modeling_evaluation.py`

### Model Artifacts

- [Freight Model](https://github.com/biki989/invoice_flagging_prediction/blob/main/models/predict_freight_model.pkl): `models/predict_freight_model.pkl`
- [Flag Classifier](https://github.com/biki989/invoice_flagging_prediction/blob/main/models/predict_flag_invoice.pkl): `models/predict_flag_invoice.pkl`
- [Feature Scaler](https://github.com/biki989/invoice_flagging_prediction/blob/main/models/scaler.pkl): `models/scaler.pkl`

### Other components

- **Procurement User**
- **Inventory SQLite Data**

## Connections

- Procurement User → Web Dashboard: uses
- Web Dashboard → Form Requests: loads
- Form Requests → Freight Endpoint: posts freight
- Form Requests → Invoice Endpoint: posts invoice
- Freight Endpoint → Freight Model: predicts with
- Invoice Endpoint → Sanity Rules: checks inputs
- Invoice Endpoint → Feature Scaler: scales features
- Invoice Endpoint → Flag Classifier: predicts with
- Freight Endpoint → Form Requests: returns estimate
- Invoice Endpoint → Form Requests: returns flag
- Form Requests → Prediction Results: renders result
- Freight Inference → Freight Model: loads model
- Flag Inference → Flag Classifier: loads model
- Flag Inference → Feature Scaler: loads scaler
- Freight Training → Freight Preparation: loads and prepares
- Freight Training → Regressor Evaluation: trains and evaluates
- Freight Preparation → Inventory SQLite Data: reads invoices
- Freight Training → Freight Model: saves best model
- Flag Training → Invoice Preparation: prepares features
- Flag Training → Classifier Evaluation: trains and evaluates
- Invoice Preparation → Inventory SQLite Data: joins invoice and PO data
- Flag Training → Feature Scaler: saves scaler
- Flag Training → Flag Classifier: saves classifier
