How thuhang012/mlops-customer-churn works
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: workflows CI/CD · evaluate.py Evaluate · serve.py API app · train.py Train model
Components 28
Data & DVC
Versioned data boundary and pipeline inputs/outputs
- Raw data · Versioned churn datasets and inference logs stored as non-Git assets
data/raw - Processed data · Intermediate transformed datasets consumed by training and inference
data/processed - DVC lineage · Lockfile and pointer-based reproducible data/artifact lineage
dvc.lock
Training & Registry
Feature engineering, model lifecycle, and tracked artifacts
- Load/validate · Raw data loading and schema/quality validation
src/mlops_project/data - Preprocess · Cleaning and transformation stage before feature construction
src/mlops_project/data/preprocess.py - Feature build · Feature generation and training-ready representations
src/mlops_project/features/build_features.py - Train model · Model fitting and experiment execution
src/mlops_project/models/train.py - Evaluate · Metric computation and model comparison
src/mlops_project/models/evaluate.py - Best model · Chosen model boundary between experimentation and serving
configs/best_model.yaml - Artifacts · Persisted metrics and model artifacts mirrored for reproducibility
artifacts/models - MLflow runs · Run metadata, params, metrics, and registered model records
mlruns_dvc
Serving
API contract and prediction runtime
- API schema · Request/response schemas for prediction and health endpoints
src/mlops_project/api/schema.py - Prediction service · Mocked prediction logic behind the API contract
src/mlops_project/api/service.py - API app · Root, health, and predict endpoints exposed to clients
src/mlops_project/api/serve.py
Monitoring
Drift detection, metrics, dashboards, and alerts
- Drift checks · Data and model drift calculations and operational checks
src/mlops_project/monitoring/drift_calculations.py - Metrics export · Exports monitoring signals for scraping and downstream alerting
src/mlops_project/monitoring/drift_metrics_exporter.py - Prometheus · Scrapes service and monitoring metrics
monitoring/prometheus/prometheus.yml - Grafana · Dashboards for drift and runtime visibility
monitoring/grafana/provisioning/dashboards/json/drift-monitoring.json - Alerting · Alertmanager and drift alert rules
monitoring/alertmanager/alertmanager.yml
Delivery
Containers, Kubernetes, and CI/CD paths
- Container build · Local packaging and runtime validation image
Dockerfile - Kubernetes · API, UI, MLflow, and monitoring deployment manifests
k8s - Kind cluster · Reproducible local Kubernetes environment
deployment/kind-config.yaml - CI/CD · Linting, tests, contract checks, and container smoke validation
.github/workflows
Presentation
Thin UI client over the API
- Streamlit UI · Thin presentation layer that calls the prediction API
streamlit_app/app.py
Quality Gates
Tests and validation scripts that protect subsystem contracts
- Data checks · Raw data expectations and validation coverage
tests/test_data.py - API tests · Service reachability and endpoint contract coverage
tests/test_api.py - Model tests · Model quality and metric assumptions
tests/test_model_quality.py - Monitoring tests · Drift and monitoring logic coverage
tests/test_monitoring.py
Connections 29
- 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