# thuhang012/mlops-customer-churn architecture

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

- Interactive diagram: https://gitdiagram.com/thuhang012/mlops-customer-churn
- Repository: https://github.com/thuhang012/mlops-customer-churn

## Overview

1. This repository is an end-to-end MLOps learning project for churn prediction, but it is still split into clear layers: data/versioning, feature and model pipeline, serving, monitoring, and delivery/infrastructure. The current API is explicitly a Sprint 1 mock, so the architecture should be read as “contract-first” with placeholders in some runtime pieces.

2. The data boundary is handled with DVC. Versioned inputs live under `data/raw/`, intermediate outputs under `data/processed/`, and tracked artifacts are mirrored in `artifacts/` and `mlruns_dvc/`. The repo is set up to treat large datasets and model outputs as non-Git assets, with `.dvc` pointers and a DVC lockfile defining reproducible lineage.

3. The core pipeline code lives in `src/mlops_project/data`, `features`, and `models`. The intended flow is: load and validate raw churn data, preprocess it, build features, train a model, then evaluate it and produce metrics/artifacts. Supporting scripts in `scripts/validation/` and `scripts/training/` add quality gates and model-registration steps around that pipeline.

4. Model lifecycle management appears to be centered on MLflow-style run tracking, with persisted run metadata under `mlruns_dvc/`. The presence of `configs/best_model.yaml` and `artifacts/models/` suggests a “best model selection” boundary between experimentation/training and the serving layer.

5. The serving subsystem is `src/mlops_project/api/`, organized into schema, service, and app entrypoint files. The runtime contract is intentionally small: a root endpoint, `/health`, and `/predict`. In the current stage, prediction is mocked, which keeps the API stable while the training pipeline matures.

6. There is a separate UI consumer in `streamlit_app/app.py`. Architecturally, this is a thin client over the API rather than a second business-logic service, so it belongs on the edge of the system diagram as a presentation layer that calls the prediction API.

7. Monitoring is a distinct subsystem, not just logging. `src/mlops_project/monitoring/` contains drift calculations, checks, and a metrics exporter, while `monitoring/prometheus`, `monitoring/grafana`, and `monitoring/alertmanager` define the observability stack. That indicates a pipeline from model/data drift detection to metrics scraping, dashboards, and alerting.

8. Deployment is split between local containerization and Kubernetes. `Dockerfile` and `docker-compose.yml` support local packaging and runtime validation, while `k8s/` contains separate API and UI deployments/services plus manifests for MLflow and monitoring integration. `deployment/kind-config.yaml` shows the cluster is designed to run locally with kind for reproducible demos and testing.

9. CI/CD is handled in GitHub Actions, with separate workflows for CI, CD, contract testing, and scheduled monitoring. The CI path runs linting and pytest; the CD scaffold builds and smoke-tests a Docker image locally instead of pushing to a registry; the scheduled workflow implies periodic drift/monitoring checks.

10. Tests are used as architectural contracts. `tests/test_api.py` checks service reachability, `tests/test_data.py` validates raw data expectations, `tests/test_model_quality.py` protects model-related assumptions, and `tests/test_monitoring.py` exercises monitoring logic. This keeps the repo boundary-driven: each subsystem has a small, explicit test surface.

11. For a diagram, the main flow is: versioned raw data in DVC → validation/preprocessing/feature generation → training/evaluation/registration → model artifact and metrics storage → FastAPI serving → Streamlit UI and external clients → monitoring stack consumes runtime and drift metrics → alerts/dashboards feed operational feedback. The repo also includes notebooks for exploration, but they are non-production and sit outside the operational path.

Main entry points: [`.github/workflows`](https://github.com/thuhang012/mlops-customer-churn/blob/main/.github/workflows) (CI/CD), [`src/mlops_project/models/evaluate.py`](https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/models/evaluate.py) (Evaluate), [`src/mlops_project/api/serve.py`](https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/api/serve.py) (API app), [`src/mlops_project/models/train.py`](https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/models/train.py) (Train model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_data["Data & DVC"]
  node_n_raw_data[("Raw data<br/>DVC inputs")]
  node_n_processed_data[("Processed data<br/>DVC outputs")]
  node_n_dvc_lineage["DVC lineage<br/>versioning<br/>[dvc.lock]"]
end

subgraph group_grp_ml["Training & Registry"]
  node_n_load_validate["Load/validate<br/>data prep"]
  node_n_preprocess["Preprocess<br/>feature prep<br/>[preprocess.py]"]
  node_n_features["Feature build<br/>features<br/>[build_features.py]"]
  node_n_train["Train model<br/>training<br/>[train.py]"]
  node_n_eval["Evaluate<br/>evaluation<br/>[evaluate.py]"]
  node_n_best_model["Best model<br/>selection<br/>[best_model.yaml]"]
  node_n_artifacts[("Artifacts<br/>model outputs")]
  node_n_mlruns[("MLflow runs<br/>tracking")]
end

subgraph group_grp_serve["Serving"]
  node_n_api_schema["API schema<br/>contract<br/>[schema.py]"]
  node_n_api_service["Prediction service<br/>[service.py]"]
  node_n_api_app["API app<br/>fastapi entrypoint<br/>[serve.py]"]
end

subgraph group_grp_obs["Monitoring"]
  node_n_drift["Drift checks<br/>monitoring logic"]
  node_n_exporter["Metrics export"]
  node_n_prometheus[("Prometheus<br/>scraping<br/>[prometheus.yml]")]
  node_n_grafana["Grafana<br/>dashboarding"]
  node_n_alerts["Alerting<br/>alerts<br/>[alertmanager.yml]"]
end

subgraph group_grp_delivery["Delivery"]
  node_n_docker["Container build<br/>docker"]
  node_n_k8s["Kubernetes<br/>manifests"]
  node_n_kind["Kind cluster<br/>local cluster<br/>[kind-config.yaml]"]
  node_n_ci["CI/CD<br/>workflows<br/>[workflows]"]
end

subgraph group_grp_client["Presentation"]
  node_n_ui["Streamlit UI<br/>client<br/>[app.py]"]
end

subgraph group_grp_quality["Quality Gates"]
  node_n_data_tests["Data checks<br/>tests<br/>[test_data.py]"]
  node_n_api_tests["API tests<br/>[test_api.py]"]
  node_n_model_tests["Model tests"]
  node_n_monitor_tests["Monitoring tests<br/>[test_monitoring.py]"]
end

node_n_raw_data -->|"input"| node_n_load_validate
node_n_load_validate -->|"writes"| node_n_processed_data
node_n_processed_data -->|"input"| node_n_preprocess
node_n_preprocess -->|"features"| node_n_features
node_n_features -->|"train"| node_n_train
node_n_train -->|"score"| node_n_eval
node_n_eval -->|"select"| node_n_best_model
node_n_eval -->|"persist"| node_n_artifacts
node_n_train -->|"track"| node_n_mlruns
node_n_mlruns -->|"registry"| node_n_best_model
node_n_best_model -->|"load model"| node_n_api_service
node_n_api_schema -->|"contract"| node_n_api_app
node_n_api_service -->|"serve"| node_n_api_app
node_n_api_app -->|"predict api"| node_n_ui
node_n_api_app -->|"runtime data"| node_n_drift
node_n_drift -->|"export"| node_n_exporter
node_n_exporter -->|"scrape"| node_n_prometheus
node_n_prometheus -->|"visualize"| node_n_grafana
node_n_prometheus -->|"rule eval"| node_n_alerts
node_n_docker -->|"deploy"| node_n_k8s
node_n_kind -->|"local run"| node_n_k8s
node_n_ci -->|"build/test"| node_n_docker
node_n_ci -->|"contracts"| node_n_api_tests
node_n_ci -->|"quality"| node_n_data_tests
node_n_ci -->|"quality"| node_n_model_tests
node_n_ci -->|"quality"| node_n_monitor_tests
node_n_data_tests -->|"guards"| node_n_load_validate
node_n_model_tests -->|"guards"| node_n_eval
node_n_monitor_tests -->|"guards"| node_n_drift

click node_n_raw_data "https://github.com/thuhang012/mlops-customer-churn/tree/main/data/raw"
click node_n_processed_data "https://github.com/thuhang012/mlops-customer-churn/tree/main/data/processed"
click node_n_dvc_lineage "https://github.com/thuhang012/mlops-customer-churn/blob/main/dvc.lock"
click node_n_load_validate "https://github.com/thuhang012/mlops-customer-churn/tree/main/src/mlops_project/data"
click node_n_preprocess "https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/data/preprocess.py"
click node_n_features "https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/features/build_features.py"
click node_n_train "https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/models/train.py"
click node_n_eval "https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/models/evaluate.py"
click node_n_best_model "https://github.com/thuhang012/mlops-customer-churn/blob/main/configs/best_model.yaml"
click node_n_artifacts "https://github.com/thuhang012/mlops-customer-churn/tree/main/artifacts/models"
click node_n_mlruns "https://github.com/thuhang012/mlops-customer-churn/tree/main/mlruns_dvc"
click node_n_api_schema "https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/api/schema.py"
click node_n_api_service "https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/api/service.py"
click node_n_api_app "https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/api/serve.py"
click node_n_ui "https://github.com/thuhang012/mlops-customer-churn/blob/main/streamlit_app/app.py"
click node_n_drift "https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/monitoring/drift_calculations.py"
click node_n_exporter "https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/monitoring/drift_metrics_exporter.py"
click node_n_prometheus "https://github.com/thuhang012/mlops-customer-churn/blob/main/monitoring/prometheus/prometheus.yml"
click node_n_grafana "https://github.com/thuhang012/mlops-customer-churn/blob/main/monitoring/grafana/provisioning/dashboards/json/drift-monitoring.json"
click node_n_alerts "https://github.com/thuhang012/mlops-customer-churn/blob/main/monitoring/alertmanager/alertmanager.yml"
click node_n_docker "https://github.com/thuhang012/mlops-customer-churn/tree/main/Dockerfile"
click node_n_k8s "https://github.com/thuhang012/mlops-customer-churn/tree/main/k8s"
click node_n_kind "https://github.com/thuhang012/mlops-customer-churn/blob/main/deployment/kind-config.yaml"
click node_n_ci "https://github.com/thuhang012/mlops-customer-churn/blob/main/.github/workflows"
click node_n_data_tests "https://github.com/thuhang012/mlops-customer-churn/blob/main/tests/test_data.py"
click node_n_api_tests "https://github.com/thuhang012/mlops-customer-churn/blob/main/tests/test_api.py"
click node_n_model_tests "https://github.com/thuhang012/mlops-customer-churn/blob/main/tests/test_model_quality.py"
click node_n_monitor_tests "https://github.com/thuhang012/mlops-customer-churn/blob/main/tests/test_monitoring.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_n_raw_data,node_n_processed_data,node_n_dvc_lineage,node_n_data_tests,node_n_api_tests,node_n_model_tests,node_n_monitor_tests toneBlue
class node_n_load_validate,node_n_preprocess,node_n_features,node_n_train,node_n_eval,node_n_best_model,node_n_artifacts,node_n_mlruns toneAmber
class node_n_api_schema,node_n_api_service,node_n_api_app toneMint
class node_n_drift,node_n_exporter,node_n_prometheus,node_n_grafana,node_n_alerts toneRose
class node_n_docker,node_n_k8s,node_n_kind,node_n_ci toneIndigo
class node_n_ui toneTeal
```

## Components

### Data & DVC

Versioned data boundary and pipeline inputs/outputs

- [Raw data](https://github.com/thuhang012/mlops-customer-churn/tree/main/data/raw): DVC inputs · Versioned churn datasets and inference logs stored as non-Git assets · `data/raw`
- [Processed data](https://github.com/thuhang012/mlops-customer-churn/tree/main/data/processed): DVC outputs · Intermediate transformed datasets consumed by training and inference · `data/processed`
- [DVC lineage](https://github.com/thuhang012/mlops-customer-churn/blob/main/dvc.lock): versioning · Lockfile and pointer-based reproducible data/artifact lineage · `dvc.lock`

### Training & Registry

Feature engineering, model lifecycle, and tracked artifacts

- [Load/validate](https://github.com/thuhang012/mlops-customer-churn/tree/main/src/mlops_project/data): data prep · Raw data loading and schema/quality validation · `src/mlops_project/data`
- [Preprocess](https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/data/preprocess.py): feature prep · Cleaning and transformation stage before feature construction · `src/mlops_project/data/preprocess.py`
- [Feature build](https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/features/build_features.py): features · Feature generation and training-ready representations · `src/mlops_project/features/build_features.py`
- [Train model](https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/models/train.py): training · Model fitting and experiment execution · `src/mlops_project/models/train.py`
- [Evaluate](https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/models/evaluate.py): evaluation · Metric computation and model comparison · `src/mlops_project/models/evaluate.py`
- [Best model](https://github.com/thuhang012/mlops-customer-churn/blob/main/configs/best_model.yaml): selection · Chosen model boundary between experimentation and serving · `configs/best_model.yaml`
- [Artifacts](https://github.com/thuhang012/mlops-customer-churn/tree/main/artifacts/models): model outputs · Persisted metrics and model artifacts mirrored for reproducibility · `artifacts/models`
- [MLflow runs](https://github.com/thuhang012/mlops-customer-churn/tree/main/mlruns_dvc): tracking · Run metadata, params, metrics, and registered model records · `mlruns_dvc`

### Serving

API contract and prediction runtime

- [API schema](https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/api/schema.py): contract · Request/response schemas for prediction and health endpoints · `src/mlops_project/api/schema.py`
- [Prediction service](https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/api/service.py): service · Mocked prediction logic behind the API contract · `src/mlops_project/api/service.py`
- [API app](https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/api/serve.py): fastapi entrypoint · Root, health, and predict endpoints exposed to clients · `src/mlops_project/api/serve.py`

### Monitoring

Drift detection, metrics, dashboards, and alerts

- [Drift checks](https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/monitoring/drift_calculations.py): monitoring logic · Data and model drift calculations and operational checks · `src/mlops_project/monitoring/drift_calculations.py`
- [Metrics export](https://github.com/thuhang012/mlops-customer-churn/blob/main/src/mlops_project/monitoring/drift_metrics_exporter.py): metrics exporter · Exports monitoring signals for scraping and downstream alerting · `src/mlops_project/monitoring/drift_metrics_exporter.py`
- [Prometheus](https://github.com/thuhang012/mlops-customer-churn/blob/main/monitoring/prometheus/prometheus.yml): scraping · Scrapes service and monitoring metrics · `monitoring/prometheus/prometheus.yml`
- [Grafana](https://github.com/thuhang012/mlops-customer-churn/blob/main/monitoring/grafana/provisioning/dashboards/json/drift-monitoring.json): dashboarding · Dashboards for drift and runtime visibility · `monitoring/grafana/provisioning/dashboards/json/drift-monitoring.json`
- [Alerting](https://github.com/thuhang012/mlops-customer-churn/blob/main/monitoring/alertmanager/alertmanager.yml): alerts · Alertmanager and drift alert rules · `monitoring/alertmanager/alertmanager.yml`

### Delivery

Containers, Kubernetes, and CI/CD paths

- [Container build](https://github.com/thuhang012/mlops-customer-churn/tree/main/Dockerfile): docker · Local packaging and runtime validation image · `Dockerfile`
- [Kubernetes](https://github.com/thuhang012/mlops-customer-churn/tree/main/k8s): manifests · API, UI, MLflow, and monitoring deployment manifests · `k8s`
- [Kind cluster](https://github.com/thuhang012/mlops-customer-churn/blob/main/deployment/kind-config.yaml): local cluster · Reproducible local Kubernetes environment · `deployment/kind-config.yaml`
- [CI/CD](https://github.com/thuhang012/mlops-customer-churn/blob/main/.github/workflows): workflows · Linting, tests, contract checks, and container smoke validation · `.github/workflows`

### Presentation

Thin UI client over the API

- [Streamlit UI](https://github.com/thuhang012/mlops-customer-churn/blob/main/streamlit_app/app.py): client · Thin presentation layer that calls the prediction API · `streamlit_app/app.py`

### Quality Gates

Tests and validation scripts that protect subsystem contracts

- [Data checks](https://github.com/thuhang012/mlops-customer-churn/blob/main/tests/test_data.py): tests · Raw data expectations and validation coverage · `tests/test_data.py`
- [API tests](https://github.com/thuhang012/mlops-customer-churn/blob/main/tests/test_api.py): tests · Service reachability and endpoint contract coverage · `tests/test_api.py`
- [Model tests](https://github.com/thuhang012/mlops-customer-churn/blob/main/tests/test_model_quality.py): tests · Model quality and metric assumptions · `tests/test_model_quality.py`
- [Monitoring tests](https://github.com/thuhang012/mlops-customer-churn/blob/main/tests/test_monitoring.py): tests · Drift and monitoring logic coverage · `tests/test_monitoring.py`

## Connections

- Raw data → Load/validate: input · Versioned raw data feeds validation and loading
- Load/validate → Processed data: writes · Validated data is transformed into processed datasets
- Processed data → Preprocess: input · Processed/raw inputs flow into preprocessing
- Preprocess → Feature build: features · Preprocessing feeds feature construction
- Feature build → Train model: train · Feature sets are used for model fitting
- Train model → Evaluate: score · Trained model is evaluated against holdout metrics
- Evaluate → Best model: select · Evaluation determines the best model boundary
- Evaluate → Artifacts: persist · Metrics and artifacts are written for reuse
- Train model → MLflow runs: track · Training run parameters and metrics are tracked
- MLflow runs → Best model: registry · Tracked runs support model selection and registration
- Best model → Prediction service: load model · Serving layer consumes the selected model contract
- API schema → API app: contract · Schemas define the request and response boundary
- Prediction service → API app: serve · Service logic powers the API endpoints
- API app → Streamlit UI: predict api · Streamlit UI calls the prediction endpoint
- API app → Drift checks: runtime data · Serving/runtime signals feed drift analysis
- Drift checks → Metrics export: export · Computed drift metrics are exposed for scraping
- Metrics export → Prometheus: scrape · Prometheus collects monitoring metrics
- Prometheus → Grafana: visualize · Dashboards read scraped metrics
- Prometheus → Alerting: rule eval · Alert rules fire from Prometheus data
- Container build → Kubernetes: deploy · Container image is targeted by Kubernetes manifests
- Kind cluster → Kubernetes: local run · Kind enables reproducible local cluster demos
- CI/CD → Container build: build/test · CI validates containerization and smoke checks
- CI/CD → API tests: contracts · CI runs API contract tests
- CI/CD → Data checks: quality · CI runs data validation tests
- CI/CD → Model tests: quality · CI runs model quality checks
- CI/CD → Monitoring tests: quality · CI runs monitoring tests
- Data checks → Load/validate: guards · Data tests protect the ingestion boundary
- Model tests → Evaluate: guards · Model tests protect the evaluation boundary
- Monitoring tests → Drift checks: guards · Monitoring tests protect drift logic
