# anesriad/regression_ml_endtoend architecture

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

- Interactive diagram: https://gitdiagram.com/anesriad/regression_ml_endtoend
- Repository: https://github.com/anesriad/regression_ml_endtoend

## Overview

1. **Overall shape**
   - This repo is an end-to-end housing price regression system built around a single ML pipeline, with separate paths for **offline training**, **online inference**, **batch prediction**, and two **user-facing services**: a FastAPI backend and a Streamlit dashboard.

2. **Data preparation boundary**
   - The core data flow starts in `src/feature_pipeline/`.
   - `load.py` performs the time-aware split: training data is before 2020, evaluation data is 2020–2021, and holdout data is 2022+.
   - `preprocess.py` cleans and normalizes data before modeling.
   - `feature_engineering.py` creates model inputs such as date-derived features plus categorical encodings.

3. **Leakage prevention is a first-class design constraint**
   - The pipeline avoids random splitting and instead uses time-based splits.
   - Encoders are fit only on training data and persisted for later reuse.
   - Training/inference schema alignment is enforced so serving uses the same feature set as training.

4. **Training and model selection subsystem**
   - `src/training_pipeline/` contains the model lifecycle:
     - `train.py` for baseline XGBoost training
     - `tune.py` for Optuna-driven hyperparameter search
     - `eval.py` for metrics and comparison
   - This is the main offline learning boundary where the model is fit and assessed before deployment.

5. **Experiment tracking and reproducibility**
   - MLflow is used to record runs and tuning results.
   - Trained artifacts are persisted under `models/`, including the XGBoost model and saved encoders.
   - The repository includes `configs/mlflow_config.yml` and notebook-driven experimentation history in `notebooks/`.

6. **Inference subsystem**
   - `src/inference_pipeline/inference.py` is the production transformation-and-prediction path.
   - It loads the saved model plus frequency and target encoders, applies the same feature logic as training, and outputs predictions.
   - This subsystem is the boundary between trained artifacts and any serving layer.

7. **Batch prediction path**
   - `src/batch/run_monthly.py` runs monthly batch scoring, likely over holdout or period-based data.
   - This is a separate execution mode from low-latency serving and is useful for scheduled reporting or offline production scoring.

8. **API serving layer**
   - `src/api/main.py` exposes the model through FastAPI.
   - The API is the primary serving boundary for prediction requests and health checks, and it integrates with S3 for model/data access in production.
   - The readme indicates the API is containerized and deployed independently from the dashboard.

9. **Interactive dashboard layer**
   - `app.py` is a Streamlit app that provides an interactive front end.
   - It calls the FastAPI service for predictions rather than embedding model logic directly, which keeps the UI separate from inference logic.
   - The dashboard also handles filtering and visualization of predictions versus actuals.

10. **Cloud and deployment architecture**
   - The project is designed for AWS:
     - S3 for data/model storage
     - ECR for container images
     - ECS/Fargate for running the API and Streamlit services
     - ALB for routing traffic
   - `housing-api-task-def.json` and `streamlit-task-def.json` are deployment descriptors for those services.
   - `Dockerfile` and `Dockerfile.streamlit` define the two runtime containers.

11. **Quality and validation**
   - `configs/ge_expectations.yml` suggests Great Expectations-based data checks.
   - `tests/` covers feature logic, training, inference, and smoke tests, which supports isolation of pipeline stages and prevents regressions.

12. **What is runtime vs. research**
   - The runtime architecture is the pipeline + API + dashboard + batch job.
   - The notebooks are experimentation and analysis artifacts, not part of the deployed serving path, but they explain how the current feature set and model choices were developed.

13. **Primary architecture diagram takeaway**
   - The cleanest diagram is a layered flow:
     - raw housing data → feature pipeline → training/tuning/evaluation → persisted model artifacts
     - persisted model artifacts + feature pipeline logic → inference/batch scoring
     - inference service → API → Streamlit UI
     - all of it deployed as containers on AWS with S3-backed storage and MLflow for experiment tracking.

Main entry points: [`src/feature_pipeline/feature_engineering.py`](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/feature_pipeline/feature_engineering.py) (Engineer features), [`src/training_pipeline/train.py`](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/training_pipeline/train.py) (Train model), [`src/inference_pipeline/inference.py`](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/inference_pipeline/inference.py) (Predict), [`src/training_pipeline/tune.py`](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/training_pipeline/tune.py) (Tune params)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_data["Data prep"]
  node_raw_data[("Housing data<br/>dataset boundary")]
  node_load["Split data<br/>time split<br/>[load.py]"]
  node_preprocess["Clean data<br/>prep step<br/>[preprocess.py]"]
  node_features["Engineer features<br/>feature step"]
  node_ge["Data checks<br/>validation config"]
end

subgraph group_grp_train["Training"]
  node_train["Train model<br/>xgboost train<br/>[train.py]"]
  node_tune["Tune params<br/>optuna search<br/>[tune.py]"]
  node_eval["Evaluate model<br/>metrics compare<br/>[eval.py]"]
  node_mlflow["Track runs<br/>experiment tracking<br/>[mlflow_config.yml]"]
  node_artifact_model["Model artifact<br/>persisted model<br/>[xgb_model.pkl]"]
  node_artifact_encoders["Encoders<br/>[freq_encoder.pkl]"]
end

subgraph group_grp_serve["Serving"]
  node_infer["Predict<br/>inference pipeline<br/>[inference.py]"]
  node_batch["Monthly batch<br/>batch scoring<br/>[run_monthly.py]"]
  node_api["FastAPI<br/>serving api<br/>[main.py]"]
  node_ui["Streamlit app<br/>dashboard<br/>[app.py]"]
end

subgraph group_grp_deploy["Deployment"]
  node_docker_api["API image<br/>container build"]
  node_docker_ui["UI image<br/>container build"]
  node_task_api["API task<br/>ecs task def"]
  node_task_ui["UI task<br/>ecs task def"]
end

node_raw_data -->|"split"| node_load
node_load -->|"clean"| node_preprocess
node_preprocess -->|"featurize"| node_features
node_ge -.->|"validate"| node_load
node_features -->|"fit"| node_train
node_features -->|"search"| node_tune
node_features -->|"score"| node_eval
node_train -->|"save"| node_artifact_model
node_train -->|"save"| node_artifact_encoders
node_tune -->|"best model"| node_artifact_model
node_train -.->|"log"| node_mlflow
node_tune -.->|"log"| node_mlflow
node_artifact_model -->|"load"| node_infer
node_artifact_encoders -->|"load"| node_infer
node_infer -->|"score"| node_batch
node_infer -->|"serve"| node_api
node_api -->|"requests"| node_ui
node_docker_api -.->|"build"| node_api
node_docker_ui -.->|"build"| node_ui
node_task_api -.->|"deploy"| node_docker_api
node_task_ui -.->|"deploy"| node_docker_ui

click node_load "https://github.com/anesriad/regression_ml_endtoend/blob/main/src/feature_pipeline/load.py"
click node_preprocess "https://github.com/anesriad/regression_ml_endtoend/blob/main/src/feature_pipeline/preprocess.py"
click node_features "https://github.com/anesriad/regression_ml_endtoend/blob/main/src/feature_pipeline/feature_engineering.py"
click node_ge "https://github.com/anesriad/regression_ml_endtoend/blob/main/configs/ge_expectations.yml"
click node_train "https://github.com/anesriad/regression_ml_endtoend/blob/main/src/training_pipeline/train.py"
click node_tune "https://github.com/anesriad/regression_ml_endtoend/blob/main/src/training_pipeline/tune.py"
click node_eval "https://github.com/anesriad/regression_ml_endtoend/blob/main/src/training_pipeline/eval.py"
click node_mlflow "https://github.com/anesriad/regression_ml_endtoend/blob/main/configs/mlflow_config.yml"
click node_artifact_model "https://github.com/anesriad/regression_ml_endtoend/blob/main/models/xgb_model.pkl"
click node_artifact_encoders "https://github.com/anesriad/regression_ml_endtoend/blob/main/models/freq_encoder.pkl"
click node_infer "https://github.com/anesriad/regression_ml_endtoend/blob/main/src/inference_pipeline/inference.py"
click node_batch "https://github.com/anesriad/regression_ml_endtoend/blob/main/src/batch/run_monthly.py"
click node_api "https://github.com/anesriad/regression_ml_endtoend/blob/main/src/api/main.py"
click node_ui "https://github.com/anesriad/regression_ml_endtoend/blob/main/app.py"
click node_docker_api "https://github.com/anesriad/regression_ml_endtoend/tree/main/Dockerfile"
click node_docker_ui "https://github.com/anesriad/regression_ml_endtoend/blob/main/Dockerfile.streamlit"
click node_task_api "https://github.com/anesriad/regression_ml_endtoend/blob/main/housing-api-task-def.json"
click node_task_ui "https://github.com/anesriad/regression_ml_endtoend/blob/main/streamlit-task-def.json"

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_load,node_preprocess,node_features,node_ge toneBlue
class node_train,node_tune,node_eval,node_mlflow,node_artifact_model,node_artifact_encoders toneAmber
class node_infer,node_batch,node_api,node_ui toneMint
class node_docker_api,node_docker_ui,node_task_api,node_task_ui toneRose
```

## Components

### Data prep

Time-aware feature pipeline and data validation

- **Housing data**: dataset boundary · Incoming housing records before split and cleaning
- [Split data](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/feature_pipeline/load.py): time split · Chronological train/eval/holdout partitioning to avoid leakage · `src/feature_pipeline/load.py`
- [Clean data](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/feature_pipeline/preprocess.py): prep step · Normalization and cleaning before feature creation · `src/feature_pipeline/preprocess.py`
- [Engineer features](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/feature_pipeline/feature_engineering.py): feature step · Date-derived features and categorical encodings · `src/feature_pipeline/feature_engineering.py`
- [Data checks](https://github.com/anesriad/regression_ml_endtoend/blob/main/configs/ge_expectations.yml): validation config · Great Expectations rules for data quality and schema consistency · `configs/ge_expectations.yml`

### Training

Offline model fitting, tuning, and evaluation

- [Train model](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/training_pipeline/train.py): xgboost train · Baseline XGBoost model fitting · `src/training_pipeline/train.py`
- [Tune params](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/training_pipeline/tune.py): optuna search · Hyperparameter search and best-run selection · `src/training_pipeline/tune.py`
- [Evaluate model](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/training_pipeline/eval.py): metrics compare · Metric calculation and model comparison · `src/training_pipeline/eval.py`
- [Track runs](https://github.com/anesriad/regression_ml_endtoend/blob/main/configs/mlflow_config.yml): experiment tracking · MLflow configuration and run logging · `configs/mlflow_config.yml`
- [Model artifact](https://github.com/anesriad/regression_ml_endtoend/blob/main/models/xgb_model.pkl): persisted model · Saved XGBoost model used for later inference · `models/xgb_model.pkl`
- [Encoders](https://github.com/anesriad/regression_ml_endtoend/blob/main/models/freq_encoder.pkl): persisted encoders · Saved frequency and target encoders reused in serving · `models/freq_encoder.pkl`

### Serving

Inference, API, batch scoring, and UI

- [Predict](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/inference_pipeline/inference.py): inference pipeline · Loads artifacts, applies training-aligned transforms, and outputs predictions · `src/inference_pipeline/inference.py`
- [Monthly batch](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/batch/run_monthly.py): batch scoring · Scheduled offline scoring over period-based data · `src/batch/run_monthly.py`
- [FastAPI](https://github.com/anesriad/regression_ml_endtoend/blob/main/src/api/main.py): serving api · Prediction and health-check service boundary · `src/api/main.py`
- [Streamlit app](https://github.com/anesriad/regression_ml_endtoend/blob/main/app.py): dashboard · Interactive UI that calls the API for predictions · `app.py`

### Deployment

Containers and AWS task definitions

- [API image](https://github.com/anesriad/regression_ml_endtoend/tree/main/Dockerfile): container build · Container definition for the FastAPI runtime · `Dockerfile`
- [UI image](https://github.com/anesriad/regression_ml_endtoend/blob/main/Dockerfile.streamlit): container build · Container definition for the Streamlit runtime · `Dockerfile.streamlit`
- [API task](https://github.com/anesriad/regression_ml_endtoend/blob/main/housing-api-task-def.json): ecs task def · AWS task definition for the API service · `housing-api-task-def.json`
- [UI task](https://github.com/anesriad/regression_ml_endtoend/blob/main/streamlit-task-def.json): ecs task def · AWS task definition for the Streamlit service · `streamlit-task-def.json`

## Connections

- Housing data → Split data: split · Time-based partitioning starts from raw housing records
- Split data → Clean data: clean · Split datasets are cleaned before features are built
- Clean data → Engineer features: featurize · Preprocessed rows are transformed into model inputs
- Data checks → Split data: validate · Quality checks constrain the upstream data boundary
- Engineer features → Train model: fit · Training consumes engineered features
- Engineer features → Tune params: search · Hyperparameter tuning reuses the same feature set
- Engineer features → Evaluate model: score · Evaluation compares predictions on held-out data
- Train model → Model artifact: save · Baseline training persists the fitted model
- Train model → Encoders: save · Training persists encoders for later reuse
- Tune params → Model artifact: best model · Best tuned model is written as the deployable artifact
- Train model → Track runs: log · Training runs are recorded for reproducibility
- Tune params → Track runs: log · Tuning trials and best params are tracked
- Model artifact → Predict: load · Inference loads the saved model artifact
- Encoders → Predict: load · Inference loads persisted encoders to match training
- Predict → Monthly batch: score · Monthly batch jobs reuse the same prediction path
- Predict → FastAPI: serve · FastAPI exposes the inference pipeline
- FastAPI → Streamlit app: requests · Dashboard submits prediction requests to the API
- API image → FastAPI: build · API container packages the serving runtime
- UI image → Streamlit app: build · UI container packages the dashboard runtime
- API task → API image: deploy · ECS task runs the API image
- UI task → UI image: deploy · ECS task runs the Streamlit image
