# muthukamalan/customer-churn-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/muthukamalan/customer-churn-prediction
- Repository: https://github.com/muthukamalan/customer-churn-prediction

## Overview

#### Purpose and Entry Points
Local, end-to-end MLOps project for telecom churn classification: prepare Excel source data, ingest/version it, train and tune scikit-learn models, track artifacts, and serve predictions. Primary executable entry points are `scripts/prep_db_ingestion.py`, `src/train/train.py`, `src/hparams/hparams.py`, and `src/inference/app.py`.

#### Data Preparation and Versioning
Raw telecom Excel exports are expected under `data/raw/`. The preparation script transforms them into a database-ingestible processed dataset; PostgreSQL subsequently hosts the `mlchurn.customer_churn` table. DVC tracks the dataset imported from that table, separating reproducible data state from source code.
- `scripts/prep_db_ingestion.py`
- `customer_churn.csv.dvc`
- `data/raw/.gitkeep`

#### Configuration-Driven ML Execution
Hydra composes runtime configuration for data, paths, model selection, training, and MLflow settings. The default training composition is rooted in `configs/train.yaml`; model-specific YAML files select one of logistic regression, decision tree, gradient boosting, k-nearest neighbors, or random forest. This boundary lets commands override model and run settings without modifying Python.
- `configs/train.yaml`
- `configs/config.yaml`
- `configs/model/default.yaml`

#### Feature Engineering and Training
Training loads the versioned churn data, applies shared feature transformation, fits the selected scikit-learn estimator, and records the run. Feature preparation is isolated from orchestration so training and inference can preserve compatible input expectations.
- `src/featureeng/feateng.py`
- `src/train/train.py`
- `configs/data/default.yaml`

#### Hyperparameter Optimization
A dedicated Hydra multirun/Optuna workflow searches model parameters, optimizing F1 score according to the README. Search spaces are model-specific and independent of ordinary training configuration; results are expected to be tracked as MLflow experiments and used to select a later training run.
- `src/hparams/hparams.py`
- `configs/hparams/decision_tree_hparam.yaml`
- `configs/hparams/random_forest_hparam.yaml`

#### Experiment, Artifact, and Service Infrastructure
Docker Compose provides local service discovery and infrastructure: PostgreSQL for operational data and MLflow metadata, MLflow for run/model tracking, and MinIO/S3-compatible object storage for artifacts and model weights. Container initialization and service wiring are defined outside application modules.
- `compose.local.yaml`
- `postgres/init-db.sh`
- `postgres/servers.json`

#### Model Serving and Observability
The inference boundary is a FastAPI application that reads MLflow/MinIO connection settings from environment variables, loads a named model, exposes health checks, and accepts prediction payloads. Prometheus scrapes container metrics; Grafana visualizes Prometheus and PostgreSQL data. The inference image is separately buildable, enabling deployment apart from training.
- `src/inference/app.py`
- `src/inference/Dockerfile`
- `prometheus/prometheus.yaml`
- `grafana/connections.md`

Main entry points: [`compose.local.yaml`](https://github.com/muthukamalan/customer-churn-prediction/blob/main/compose.local.yaml) (Local Compose stack), [`src/train/train.py`](https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/train/train.py) (Model training), [`src/hparams/hparams.py`](https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/hparams/hparams.py) (Optuna hyperparameter search), [`src/featureeng/feateng.py`](https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/featureeng/feateng.py) (Feature transformation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data pipeline"]
  node_raw_excel["Raw Excel exports<br/>source data<br/>[.gitkeep]"]
  node_prep["Preparation job<br/>Python script"]
  node_postgres[("PostgreSQL churn table<br/>operational database")]
  node_dvc_data["Versioned churn dataset<br/>DVC artifact"]
end

subgraph group_ml["ML workflow"]
  node_hydra_train["Training configuration<br/>Hydra composition<br/>[train.yaml]"]
  node_model_config["Model selection config<br/>Hydra model config<br/>[default.yaml]"]
  node_features["Feature transformation<br/>shared ML module<br/>[feateng.py]"]
  node_training["Model training<br/>training entry point<br/>[train.py]"]
  node_tuning["Optuna hyperparameter search<br/>optimization entry point<br/>[hparams.py]"]
  node_search_config["Hyperparameter search spaces<br/>Hydra hparam config"]
end

subgraph group_platform["Local platform"]
  node_compose{{"Local Compose stack<br/>container orchestration<br/>[compose.local.yaml]"}}
  node_db_init["Database initialization<br/>container init script<br/>[init-db.sh]"]
  node_mlflow[("MLflow tracking<br/>experiment registry")]
  node_minio[("MinIO artifact storage<br/>S3-compatible storage")]
end

subgraph group_serving["Serving &amp; observability"]
  node_inference["Prediction API<br/>FastAPI application<br/>[app.py]"]
  node_inference_image["Inference container image<br/>Docker build"]
  node_prometheus["Prometheus<br/>metrics collector<br/>[prometheus.yaml]"]
  node_grafana["Grafana dashboards<br/>observability UI<br/>[connections.md]"]
end

node_raw_excel -->|"prepare"| node_prep
node_prep -->|"ingest"| node_postgres
node_db_init -->|"initialize"| node_postgres
node_postgres -->|"import and version"| node_dvc_data
node_hydra_train -->|"selects"| node_model_config
node_hydra_train -->|"configures"| node_training
node_dvc_data -->|"load"| node_training
node_features -->|"transform"| node_training
node_search_config -->|"defines search"| node_tuning
node_dvc_data -->|"evaluate data"| node_tuning
node_features -->|"transform"| node_tuning
node_tuning -->|"track trials"| node_mlflow
node_training -->|"track run and model"| node_mlflow
node_mlflow -->|"store artifacts"| node_minio
node_mlflow -->|"load named model"| node_inference
node_features -.->|"compatible inputs"| node_inference
node_inference_image -->|"packages"| node_inference
node_compose -->|"runs"| node_postgres
node_compose -->|"runs"| node_mlflow
node_compose -->|"runs"| node_minio
node_compose -->|"runs"| node_prometheus
node_compose -->|"runs"| node_grafana
node_prometheus -->|"metrics source"| node_grafana
node_postgres -->|"data source"| node_grafana

click node_raw_excel "https://github.com/muthukamalan/customer-churn-prediction/blob/main/data/raw/.gitkeep"
click node_prep "https://github.com/muthukamalan/customer-churn-prediction/blob/main/scripts/prep_db_ingestion.py"
click node_dvc_data "https://github.com/muthukamalan/customer-churn-prediction/blob/main/customer_churn.csv.dvc"
click node_hydra_train "https://github.com/muthukamalan/customer-churn-prediction/blob/main/configs/train.yaml"
click node_model_config "https://github.com/muthukamalan/customer-churn-prediction/blob/main/configs/model/default.yaml"
click node_features "https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/featureeng/feateng.py"
click node_training "https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/train/train.py"
click node_tuning "https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/hparams/hparams.py"
click node_search_config "https://github.com/muthukamalan/customer-churn-prediction/blob/main/configs/hparams/decision_tree_hparam.yaml"
click node_compose "https://github.com/muthukamalan/customer-churn-prediction/blob/main/compose.local.yaml"
click node_db_init "https://github.com/muthukamalan/customer-churn-prediction/blob/main/postgres/init-db.sh"
click node_inference "https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/inference/app.py"
click node_inference_image "https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/inference/Dockerfile"
click node_prometheus "https://github.com/muthukamalan/customer-churn-prediction/blob/main/prometheus/prometheus.yaml"
click node_grafana "https://github.com/muthukamalan/customer-churn-prediction/blob/main/grafana/connections.md"

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_raw_excel,node_prep,node_postgres,node_dvc_data toneBlue
class node_hydra_train,node_model_config,node_features,node_training,node_tuning,node_search_config toneAmber
class node_compose,node_db_init,node_mlflow,node_minio toneMint
class node_inference,node_inference_image,node_prometheus,node_grafana toneRose
```

## Components

### Data pipeline

- [Raw Excel exports](https://github.com/muthukamalan/customer-churn-prediction/blob/main/data/raw/.gitkeep): source data · `data/raw/.gitkeep`
- [Preparation job](https://github.com/muthukamalan/customer-churn-prediction/blob/main/scripts/prep_db_ingestion.py): Python script · Transforms source exports into ingestible churn data. · `scripts/prep_db_ingestion.py`
- **PostgreSQL churn table**: operational database · Hosts mlchurn.customer_churn.
- [Versioned churn dataset](https://github.com/muthukamalan/customer-churn-prediction/blob/main/customer_churn.csv.dvc): DVC artifact · Reproducible dataset state imported from PostgreSQL. · `customer_churn.csv.dvc`

### ML workflow

- [Training configuration](https://github.com/muthukamalan/customer-churn-prediction/blob/main/configs/train.yaml): Hydra composition · Composes data, paths, model, training, and MLflow settings. · `configs/train.yaml`
- [Model selection config](https://github.com/muthukamalan/customer-churn-prediction/blob/main/configs/model/default.yaml): Hydra model config · Selects a scikit-learn estimator. · `configs/model/default.yaml`
- [Feature transformation](https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/featureeng/feateng.py): shared ML module · Keeps training and prediction input expectations compatible. · `src/featureeng/feateng.py`
- [Model training](https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/train/train.py): training entry point · Fits the configured estimator and records a run. · `src/train/train.py`
- [Optuna hyperparameter search](https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/hparams/hparams.py): optimization entry point · Hydra multirun optimizes F1 with model-specific search spaces. · `src/hparams/hparams.py`
- [Hyperparameter search spaces](https://github.com/muthukamalan/customer-churn-prediction/blob/main/configs/hparams/decision_tree_hparam.yaml): Hydra hparam config · `configs/hparams/decision_tree_hparam.yaml`

### Local platform

- [Local Compose stack](https://github.com/muthukamalan/customer-churn-prediction/blob/main/compose.local.yaml): container orchestration · Wires PostgreSQL, MLflow, MinIO, and monitoring services. · `compose.local.yaml`
- [Database initialization](https://github.com/muthukamalan/customer-churn-prediction/blob/main/postgres/init-db.sh): container init script · `postgres/init-db.sh`
- **MLflow tracking**: experiment registry · Stores run metadata and registered model references.
- **MinIO artifact storage**: S3-compatible storage · Stores MLflow artifacts and model weights.

### Serving & observability

- [Prediction API](https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/inference/app.py): FastAPI application · Loads a named tracked model and serves health and prediction endpoints. · `src/inference/app.py`
- [Inference container image](https://github.com/muthukamalan/customer-churn-prediction/blob/main/src/inference/Dockerfile): Docker build · Separately deployable serving image. · `src/inference/Dockerfile`
- [Prometheus](https://github.com/muthukamalan/customer-churn-prediction/blob/main/prometheus/prometheus.yaml): metrics collector · Scrapes container metrics. · `prometheus/prometheus.yaml`
- [Grafana dashboards](https://github.com/muthukamalan/customer-churn-prediction/blob/main/grafana/connections.md): observability UI · Visualizes Prometheus and PostgreSQL data. · `grafana/connections.md`

## Connections

- Raw Excel exports → Preparation job: prepare
- Preparation job → PostgreSQL churn table: ingest
- Database initialization → PostgreSQL churn table: initialize
- PostgreSQL churn table → Versioned churn dataset: import and version
- Training configuration → Model selection config: selects
- Training configuration → Model training: configures
- Versioned churn dataset → Model training: load
- Feature transformation → Model training: transform
- Hyperparameter search spaces → Optuna hyperparameter search: defines search
- Versioned churn dataset → Optuna hyperparameter search: evaluate data
- Feature transformation → Optuna hyperparameter search: transform
- Optuna hyperparameter search → MLflow tracking: track trials
- Model training → MLflow tracking: track run and model
- MLflow tracking → MinIO artifact storage: store artifacts
- MLflow tracking → Prediction API: load named model
- Feature transformation → Prediction API: compatible inputs
- Inference container image → Prediction API: packages
- Local Compose stack → PostgreSQL churn table: runs
- Local Compose stack → MLflow tracking: runs
- Local Compose stack → MinIO artifact storage: runs
- Local Compose stack → Prometheus: runs
- Local Compose stack → Grafana dashboards: runs
- Prometheus → Grafana dashboards: metrics source
- PostgreSQL churn table → Grafana dashboards: data source
