# maxim-karmanov/binary_classification architecture

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

- Interactive diagram: https://gitdiagram.com/maxim-karmanov/binary_classification
- Repository: https://github.com/maxim-karmanov/binary_classification

## Overview

#### Purpose and entry points
This is a reproducible binary-classification system for bank-marketing response prediction. It supports DVC-managed training, batch/offline prediction, and containerized online inference with monitoring.

Primary entry points:
- DVC orchestration: `dvc.yaml`, dispatched through `src/pipeline.py`
- Inference API: `main.py`
- Async API load generator: `scripts/predict_async.py`
- Service stack: `docker-compose.yml`

#### Data and reproducibility boundary
Raw Kaggle-style `train.csv` and `test.csv` are copied into versioned pipeline working data, transformed, split, and consumed by training. DVC tracks stage dependencies, outputs, and parameter changes; artifacts can be pushed to an S3-compatible MinIO remote.

Core paths:
- `dvc.yaml`
- `params.yaml`
- `src/data/io.py`
- `src/data/stage.py`
- `scripts/setup_dvc_remote.ps1`

#### Feature engineering contract
Feature processing is centralized so training and API inference use equivalent transformations on raw records. It normalizes prior-contact semantics, derives categorical/binary/numeric features, and removes the original `pdays` field. This creates the schema contract between data preparation, model fitting, and `/predict`.

Core paths:
- `src/features/stage.py`
- `src/pipeline.py`
- `main.py`

#### Training and model selection
The training stage selects enabled model families and preprocessing paths from parameters. sklearn candidates use `ColumnTransformer`-style numeric/categorical pipelines; boosting models use native categorical handling. Hyperparameter search uses stratified CV and ROC-AUC, with LightGBM currently the enabled production candidate.

Core paths:
- `src/train/model.py`
- `src/pipeline.py`
- `params.yaml`

#### Evaluation and artifact promotion
Evaluation compares trained candidates, writes metrics and leaderboard/search outputs, generates batch predictions, and promotes the selected estimator plus metadata as deployable artifacts. The API startup boundary is the persisted joblib model and associated metadata, rather than live training code or DVC internals.

Core paths:
- `src/evaluate/stage.py`
- `src/report/search.py`
- `src/pipeline.py`

#### Online inference and load flow
`main.py` runs a FastAPI/Uvicorn batch prediction service. At startup it loads the promoted model; `POST /predict` receives raw client rows, reapplies feature engineering, and returns `id`, class prediction, and score. The async client reads test/inference data, batches concurrent requests, schedules them across a duration, and persists API responses for comparison or offline drift analysis.

Core paths:
- `main.py`
- `scripts/predict_async.py`
- `tests/test_api.py`

#### Runtime infrastructure and observability
Docker Compose provisions the API, MinIO artifact remote, Prometheus, Loki/Promtail, and Grafana. The API exposes Prometheus request, latency, and prediction-class metrics. Promtail filters API container logs to Loki; Grafana is provisioned with both data sources and a prediction-service dashboard.

Core paths:
- `docker-compose.yml`
- `observability/prometheus.yml`
- `observability/promtail.yml`
- `observability/grafana/dashboards/prediction-api.json`

#### Analysis boundary
EDA is notebook-based and separate from runtime dependencies. Evidently is available for offline comparison of reference/training-derived data against inference inputs and API outputs, but is not yet a scripted or DVC-managed pipeline stage.

Core paths:
- `notebooks/eda.ipynb`
- `notebooks/data_report.html`
- `requirements.txt`

Main entry points: [`src/pipeline.py`](https://github.com/maxim-karmanov/binary_classification/blob/main/src/pipeline.py) (Pipeline dispatcher), [`main.py`](https://github.com/maxim-karmanov/binary_classification/blob/main/main.py) (Prediction API), [`src/train/model.py`](https://github.com/maxim-karmanov/binary_classification/blob/main/src/train/model.py) (Candidate training), [`dvc.yaml`](https://github.com/maxim-karmanov/binary_classification/blob/main/dvc.yaml) (DVC stages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pipeline["DVC ML Pipeline"]
  node_raw_data["Raw train/test CSV<br/>source data"]
  node_dvc{{"DVC stages<br/>orchestrator<br/>[dvc.yaml]"}}
  node_params["Training parameters<br/>[params.yaml]"]
  node_data_stage["Data staging<br/>pipeline stage<br/>[stage.py]"]
  node_feature_stage["Feature engineering<br/>pipeline stage<br/>[stage.py]"]
  node_training["Candidate training<br/>model selection<br/>[model.py]"]
  node_evaluation["Evaluation &amp; promotion<br/>pipeline stage<br/>[stage.py]"]
  node_artifacts[("Promoted model &amp; metadata<br/>deployable artifacts")]
  node_minio[("MinIO DVC remote<br/>artifact remote")]
  node_pipeline_dispatcher["Pipeline dispatcher<br/>pipeline runtime<br/>[pipeline.py]"]
end

subgraph group_serving["Online Serving"]
  node_api["Prediction API<br/>FastAPI/Uvicorn service<br/>[main.py]"]
  node_async_client["Async load generator<br/>API client<br/>[predict_async.py]"]
  node_compose{{"Compose stack<br/>runtime composition<br/>[docker-compose.yml]"}}
end

subgraph group_observability["Observability"]
  node_prometheus[("Prometheus<br/>metrics collector<br/>[prometheus.yml]")]
  node_promtail_loki[("Promtail &amp; Loki<br/>log pipeline<br/>[promtail.yml]")]
  node_grafana["Grafana dashboard<br/>visualization"]
end

node_eda["EDA &amp; offline drift analysis<br/>notebook analysis<br/>[eda.ipynb]"]

node_dvc -->|"dispatches"| node_pipeline_dispatcher
node_params -.->|"parameter changes"| node_dvc
node_raw_data -->|"copied into working data"| node_data_stage
node_pipeline_dispatcher -->|"runs"| node_data_stage
node_data_stage -->|"staged records"| node_feature_stage
node_pipeline_dispatcher -->|"runs"| node_feature_stage
node_feature_stage -->|"feature schema"| node_training
node_params -->|"model settings"| node_training
node_pipeline_dispatcher -->|"runs"| node_training
node_training -->|"trained candidates"| node_evaluation
node_pipeline_dispatcher -->|"runs"| node_evaluation
node_evaluation -->|"promotes selected model"| node_artifacts
node_dvc -.->|"pushes tracked outputs"| node_minio
node_artifacts -->|"loaded at startup"| node_api
node_async_client -->|"concurrent POST /predict"| node_api
node_compose -->|"runs"| node_api
node_compose -->|"runs"| node_minio
node_api -->|"exposes metrics"| node_prometheus
node_api -->|"container logs"| node_promtail_loki
node_prometheus -->|"metrics datasource"| node_grafana
node_promtail_loki -->|"logs datasource"| node_grafana
node_async_client -.->|"responses for offline comparison"| node_eda
node_raw_data -.->|"reference analysis"| node_eda

click node_dvc "https://github.com/maxim-karmanov/binary_classification/blob/main/dvc.yaml"
click node_params "https://github.com/maxim-karmanov/binary_classification/blob/main/params.yaml"
click node_data_stage "https://github.com/maxim-karmanov/binary_classification/blob/main/src/data/stage.py"
click node_feature_stage "https://github.com/maxim-karmanov/binary_classification/blob/main/src/features/stage.py"
click node_training "https://github.com/maxim-karmanov/binary_classification/blob/main/src/train/model.py"
click node_evaluation "https://github.com/maxim-karmanov/binary_classification/blob/main/src/evaluate/stage.py"
click node_minio "https://github.com/maxim-karmanov/binary_classification/blob/main/scripts/setup_dvc_remote.ps1"
click node_pipeline_dispatcher "https://github.com/maxim-karmanov/binary_classification/blob/main/src/pipeline.py"
click node_api "https://github.com/maxim-karmanov/binary_classification/blob/main/main.py"
click node_async_client "https://github.com/maxim-karmanov/binary_classification/blob/main/scripts/predict_async.py"
click node_compose "https://github.com/maxim-karmanov/binary_classification/blob/main/docker-compose.yml"
click node_prometheus "https://github.com/maxim-karmanov/binary_classification/blob/main/observability/prometheus.yml"
click node_promtail_loki "https://github.com/maxim-karmanov/binary_classification/blob/main/observability/promtail.yml"
click node_grafana "https://github.com/maxim-karmanov/binary_classification/blob/main/observability/grafana/dashboards/prediction-api.json"
click node_eda "https://github.com/maxim-karmanov/binary_classification/blob/main/notebooks/eda.ipynb"

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_data,node_dvc,node_params,node_data_stage,node_feature_stage,node_training,node_evaluation,node_artifacts,node_minio,node_pipeline_dispatcher toneBlue
class node_api,node_async_client,node_compose toneAmber
class node_prometheus,node_promtail_loki,node_grafana toneMint
class node_eda toneNeutral
```

## Components

### DVC ML Pipeline

Reproducible data-to-model workflow.

- **Raw train/test CSV**: source data · Kaggle-style source records.
- [DVC stages](https://github.com/maxim-karmanov/binary_classification/blob/main/dvc.yaml): orchestrator · Tracks dependencies, outputs, and parameter changes. · `dvc.yaml`
- [Training parameters](https://github.com/maxim-karmanov/binary_classification/blob/main/params.yaml): parameters · Selects enabled models and preprocessing paths. · `params.yaml`
- [Data staging](https://github.com/maxim-karmanov/binary_classification/blob/main/src/data/stage.py): pipeline stage · Copies source CSVs into versioned working data. · `src/data/stage.py`
- [Feature engineering](https://github.com/maxim-karmanov/binary_classification/blob/main/src/features/stage.py): pipeline stage · Defines the shared raw-record feature contract. · `src/features/stage.py`
- [Candidate training](https://github.com/maxim-karmanov/binary_classification/blob/main/src/train/model.py): model selection · Runs preprocessing, stratified CV, and ROC-AUC search. · `src/train/model.py`
- [Evaluation & promotion](https://github.com/maxim-karmanov/binary_classification/blob/main/src/evaluate/stage.py): pipeline stage · Compares candidates and promotes the selected estimator. · `src/evaluate/stage.py`
- **Promoted model & metadata**: deployable artifacts · Persisted joblib estimator and serving metadata.
- [MinIO DVC remote](https://github.com/maxim-karmanov/binary_classification/blob/main/scripts/setup_dvc_remote.ps1): artifact remote · S3-compatible remote for DVC-tracked artifacts. · `scripts/setup_dvc_remote.ps1`
- [Pipeline dispatcher](https://github.com/maxim-karmanov/binary_classification/blob/main/src/pipeline.py): pipeline runtime · Executes DVC stage logic. · `src/pipeline.py`

### Online Serving

Containerized prediction and load flow.

- [Prediction API](https://github.com/maxim-karmanov/binary_classification/blob/main/main.py): FastAPI/Uvicorn service · Loads artifacts and serves POST /predict. · `main.py`
- [Async load generator](https://github.com/maxim-karmanov/binary_classification/blob/main/scripts/predict_async.py): API client · Batches concurrent requests and saves responses. · `scripts/predict_async.py`
- [Compose stack](https://github.com/maxim-karmanov/binary_classification/blob/main/docker-compose.yml): runtime composition · Provisions API, artifact, and observability services. · `docker-compose.yml`

### Observability

Metrics, logs, and dashboards.

- [Prometheus](https://github.com/maxim-karmanov/binary_classification/blob/main/observability/prometheus.yml): metrics collector · Scrapes request, latency, and prediction metrics. · `observability/prometheus.yml`
- [Promtail & Loki](https://github.com/maxim-karmanov/binary_classification/blob/main/observability/promtail.yml): log pipeline · Filters API container logs and stores them. · `observability/promtail.yml`
- [Grafana dashboard](https://github.com/maxim-karmanov/binary_classification/blob/main/observability/grafana/dashboards/prediction-api.json): visualization · Shows prediction-service metrics and logs. · `observability/grafana/dashboards/prediction-api.json`

### Other components

- [EDA & offline drift analysis](https://github.com/maxim-karmanov/binary_classification/blob/main/notebooks/eda.ipynb): notebook analysis · Separate notebook-based analysis of reference and inference data. · `notebooks/eda.ipynb`

## Connections

- DVC stages → Pipeline dispatcher: dispatches
- Training parameters → DVC stages: parameter changes
- Raw train/test CSV → Data staging: copied into working data
- Pipeline dispatcher → Data staging: runs
- Data staging → Feature engineering: staged records
- Pipeline dispatcher → Feature engineering: runs
- Feature engineering → Candidate training: feature schema
- Training parameters → Candidate training: model settings
- Pipeline dispatcher → Candidate training: runs
- Candidate training → Evaluation & promotion: trained candidates
- Pipeline dispatcher → Evaluation & promotion: runs
- Evaluation & promotion → Promoted model & metadata: promotes selected model
- DVC stages → MinIO DVC remote: pushes tracked outputs
- Promoted model & metadata → Prediction API: loaded at startup
- Async load generator → Prediction API: concurrent POST /predict
- Compose stack → Prediction API: runs
- Compose stack → MinIO DVC remote: runs
- Prediction API → Prometheus: exposes metrics
- Prediction API → Promtail & Loki: container logs
- Prometheus → Grafana dashboard: metrics datasource
- Promtail & Loki → Grafana dashboard: logs datasource
- Async load generator → EDA & offline drift analysis: responses for offline comparison
- Raw train/test CSV → EDA & offline drift analysis: reference analysis
