# abdelkaderbenhmida/mlops-spec-detailed architecture

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

- Interactive diagram: https://gitdiagram.com/abdelkaderbenhmida/mlops-spec-detailed
- Repository: https://github.com/abdelkaderbenhmida/mlops-spec-detailed

## Overview

Anvil is an air-gapped predictive-maintenance platform: model data is preprocessed, trained, evaluated and registered, then loaded by an inference API that returns equipment-failure risk. The repository also includes infrastructure provisioning, configuration, orchestration and monitoring. The README describes OPC-UA ingestion and a TimescaleDB telemetry store, but those components are absent from the supplied tree; they are therefore not represented as implemented nodes. Deployment and monitoring links rely on README documentation where source wiring was not sampled.

Main entry points: [`api/main.py`](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/main.py) (API application), [`api/app/routers/predict.py`](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/routers/predict.py) (Prediction endpoint), [`ml/training/preprocess.py`](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/training/preprocess.py) (Preprocessing), [`ml/training/train.py`](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/training/train.py) (Model training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_provision["Infrastructure and deployment"]
  node_terraform["VM provisioning<br/>[main.tf]"]
  node_ansible["Host configuration<br/>[site.yml]"]
  node_kubernetes["Kubernetes cluster<br/>[namespace.yml]"]
  node_training_images["Training image"]
end

subgraph group_ml["Model lifecycle"]
  node_raw_data["Maintenance data<br/>[maintenance.csv]"]
  node_preprocessing["Preprocessing<br/>[preprocess.py]"]
  node_training["Model training<br/>[train.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
  node_mlflow["MLflow registry<br/>[main.yml]"]
  node_drift["Drift detection<br/>[drift_detector.py]"]
  node_retraining["Retraining trigger"]
end

subgraph group_serving["Inference service"]
  node_api_entry["API application<br/>[main.py]"]
  node_predict["Prediction endpoint<br/>[predict.py]"]
  node_health["Health endpoints<br/>[health.py]"]
  node_model_loader["Model loader<br/>[model_loader.py]"]
  node_schemas["Request schemas<br/>[schemas.py]"]
  node_prediction_db[("Prediction log store<br/>[db.py]")]
end

subgraph group_ops["Operations and monitoring"]
  node_metrics["Prometheus metrics<br/>[metrics.py]"]
  node_prometheus["Prometheus<br/>[prometheus.yml]"]
  node_grafana["Grafana dashboards"]
  node_jenkins["Offline CI/CD"]
end

node_plant(("Plant operators"))
node_sensor(("Plant telemetry"))

node_plant -->|"requests predictions"| node_api_entry
node_sensor -.->|"supplies training data"| node_raw_data
node_terraform -.->|"provisions hosts for"| node_ansible
node_ansible -->|"configures cluster"| node_kubernetes
node_training_images -->|"packages training"| node_training
node_raw_data -->|"loads data"| node_preprocessing
node_preprocessing -->|"prepares splits"| node_training
node_training -->|"registers model"| node_mlflow
node_training -->|"evaluates candidate"| node_evaluation
node_evaluation -->|"checks registered model"| node_mlflow
node_preprocessing -->|"prepares evaluation data"| node_evaluation
node_drift -->|"loads feature config"| node_preprocessing
node_drift -->|"writes drift report for"| node_retraining
node_api_entry -->|"initializes database"| node_prediction_db
node_api_entry -->|"loads model at startup"| node_model_loader
node_api_entry -->|"registers router"| node_predict
node_api_entry -->|"registers router"| node_health
node_api_entry -.->|"exposes metrics"| node_metrics
node_model_loader -->|"loads registry model"| node_mlflow
node_predict -->|"gets loaded model"| node_model_loader
node_predict -->|"validates request"| node_schemas
node_predict -->|"logs prediction"| node_prediction_db
node_predict -->|"transforms input"| node_preprocessing
node_health -->|"checks connectivity"| node_prediction_db
node_health -->|"checks model status"| node_model_loader
node_kubernetes -->|"hosts inference API"| node_api_entry
node_prometheus -->|"scrapes API metrics"| node_api_entry
node_grafana -->|"visualizes metrics"| node_prometheus
node_jenkins -->|"runs training pipeline"| node_training
node_jenkins -->|"deploys application"| node_kubernetes

click node_terraform "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/terraform/main.tf"
click node_ansible "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ansible/site.yml"
click node_kubernetes "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/kubernetes/namespace.yml"
click node_training_images "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/docker/training/Dockerfile"
click node_raw_data "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/data/raw/maintenance.csv"
click node_preprocessing "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/training/preprocess.py"
click node_training "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/training/train.py"
click node_evaluation "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/evaluation/evaluate.py"
click node_mlflow "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ansible/roles/mlflow/tasks/main.yml"
click node_drift "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/monitoring/drift_detector.py"
click node_retraining "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/monitoring/retraining_trigger.py"
click node_api_entry "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/main.py"
click node_predict "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/routers/predict.py"
click node_health "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/routers/health.py"
click node_model_loader "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/model_loader.py"
click node_schemas "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/schemas.py"
click node_prediction_db "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/db.py"
click node_metrics "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/metrics.py"
click node_prometheus "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/monitoring/prometheus/prometheus.yml"
click node_grafana "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/monitoring/grafana/dashboards/model-performance.json"
click node_jenkins "https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/cicd/Jenkinsfile"

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_terraform,node_ansible,node_kubernetes,node_training_images toneBlue
class node_raw_data,node_preprocessing,node_training,node_evaluation,node_mlflow,node_drift,node_retraining toneAmber
class node_api_entry,node_predict,node_health,node_model_loader,node_schemas,node_prediction_db toneMint
class node_metrics,node_prometheus,node_grafana,node_jenkins toneRose
class node_plant,node_sensor toneIndigo
```

## Components

### Infrastructure and deployment

- [VM provisioning](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/terraform/main.tf): `terraform/main.tf`
- [Host configuration](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ansible/site.yml): `ansible/site.yml`
- [Kubernetes cluster](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/kubernetes/namespace.yml): `kubernetes/namespace.yml`
- [Training image](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/docker/training/Dockerfile): `docker/training/Dockerfile`

### Model lifecycle

- [Maintenance data](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/data/raw/maintenance.csv): `ml/data/raw/maintenance.csv`
- [Preprocessing](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/training/preprocess.py): `ml/training/preprocess.py`
- [Model training](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/training/train.py): `ml/training/train.py`
- [Model evaluation](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/evaluation/evaluate.py): `ml/evaluation/evaluate.py`
- [MLflow registry](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ansible/roles/mlflow/tasks/main.yml): `ansible/roles/mlflow/tasks/main.yml`
- [Drift detection](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/monitoring/drift_detector.py): `ml/monitoring/drift_detector.py`
- [Retraining trigger](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/ml/monitoring/retraining_trigger.py): `ml/monitoring/retraining_trigger.py`

### Inference service

- [API application](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/main.py): `api/main.py`
- [Prediction endpoint](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/routers/predict.py): `api/app/routers/predict.py`
- [Health endpoints](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/routers/health.py): `api/app/routers/health.py`
- [Model loader](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/model_loader.py): `api/app/model_loader.py`
- [Request schemas](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/schemas.py): `api/app/schemas.py`
- [Prediction log store](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/db.py): `api/app/db.py`

### Operations and monitoring

- [Prometheus metrics](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/api/app/metrics.py): `api/app/metrics.py`
- [Prometheus](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/monitoring/prometheus/prometheus.yml): `monitoring/prometheus/prometheus.yml`
- [Grafana dashboards](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/monitoring/grafana/dashboards/model-performance.json): `monitoring/grafana/dashboards/model-performance.json`
- [Offline CI/CD](https://github.com/abdelkaderbenhmida/mlops-spec-detailed/blob/main/cicd/Jenkinsfile): `cicd/Jenkinsfile`

### Other components

- **Plant operators**
- **Plant telemetry**

## Connections

- Plant operators → API application: requests predictions (evidence: `README.md`)
- Plant telemetry → Maintenance data: supplies training data
- VM provisioning → Host configuration: provisions hosts for
- Host configuration → Kubernetes cluster: configures cluster (evidence: `README.md`)
- Training image → Model training: packages training (evidence: `README.md`)
- Maintenance data → Preprocessing: loads data (evidence: `ml/training/preprocess.py`)
- Preprocessing → Model training: prepares splits (evidence: `ml/training/train.py`)
- Model training → MLflow registry: registers model (evidence: `ml/training/train.py`)
- Model training → Model evaluation: evaluates candidate (evidence: `README.md`)
- Model evaluation → MLflow registry: checks registered model (evidence: `ml/evaluation/evaluate.py`)
- Preprocessing → Model evaluation: prepares evaluation data (evidence: `ml/evaluation/evaluate.py`)
- Drift detection → Preprocessing: loads feature config (evidence: `ml/monitoring/drift_detector.py`)
- Drift detection → Retraining trigger: writes drift report for (evidence: `ml/monitoring/drift_detector.py`)
- API application → Prediction log store: initializes database (evidence: `api/main.py`)
- API application → Model loader: loads model at startup (evidence: `api/main.py`)
- API application → Prediction endpoint: registers router (evidence: `api/main.py`)
- API application → Health endpoints: registers router (evidence: `api/main.py`)
- API application → Prometheus metrics: exposes metrics
- Model loader → MLflow registry: loads registry model (evidence: `api/app/model_loader.py`)
- Prediction endpoint → Model loader: gets loaded model (evidence: `api/app/routers/predict.py`)
- Prediction endpoint → Request schemas: validates request (evidence: `api/app/routers/predict.py`)
- Prediction endpoint → Prediction log store: logs prediction (evidence: `api/app/routers/predict.py`)
- Prediction endpoint → Preprocessing: transforms input (evidence: `api/app/routers/predict.py`)
- Health endpoints → Prediction log store: checks connectivity (evidence: `api/app/routers/health.py`)
- Health endpoints → Model loader: checks model status (evidence: `api/app/routers/health.py`)
- Kubernetes cluster → API application: hosts inference API (evidence: `README.md`)
- Prometheus → API application: scrapes API metrics (evidence: `README.md`)
- Grafana dashboards → Prometheus: visualizes metrics (evidence: `README.md`)
- Offline CI/CD → Model training: runs training pipeline (evidence: `README.md`)
- Offline CI/CD → Kubernetes cluster: deploys application (evidence: `README.md`)
