# computerscistudent/customer-churn-prediction architecture

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

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

## Overview

This is a customer-churn prediction application: training data is ingested and split, feature-engineered, used to train and compare models, and then served through FastAPI for prediction and SHAP explanations. The graph includes the documented API and model capabilities plus an internal preprocessing layer. Edges are limited to relationships shown in the README or sampled source; training, evaluation, and UI template wiring beyond those excerpts is not inferred.

Main entry points: [`src/api/main.py`](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/api/main.py) (FastAPI routes), [`src/models/predict_with_shap.py`](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/models/predict_with_shap.py) (Prediction and SHAP), [`artifacts`](https://github.com/computerscistudent/customer-churn-prediction/tree/main/artifacts) (Model artifacts), [`src/features/build_features.py`](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/features/build_features.py) (Feature engineering)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_raw["Telco source data<br/>[telco.csv]"]
  node_ingestion["Data ingestion<br/>[data_ingestion.py]"]
  node_processed["Train and test data"]
  node_features["Feature engineering<br/>[build_features.py]"]
end

subgraph group_ml["Model lifecycle"]
  node_train["Model training"]
  node_artifacts[("Model artifacts")]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
  node_advanced_eval["Advanced evaluation<br/>[eval_advanced.py]"]
  node_baseline_predictor["Baseline predictor"]
  node_predictor["Prediction and SHAP"]
end

subgraph group_api["Prediction API"]
  node_api["FastAPI routes<br/>[main.py]"]
  node_schema["Request schemas<br/>[schema.py]"]
  node_dependencies["Predictor dependency<br/>[dependences.py]"]
  node_templates["HTML templates"]
end

subgraph group_support["Shared internals"]
  node_logger["Logging<br/>[logger.py]"]
  node_exceptions["Error handling<br/>[exception.py]"]
end

node_user(("API client"))

node_user -->|"submits request"| node_api
node_api -->|"validates with"| node_schema
node_api -->|"resolves predictor"| node_dependencies
node_dependencies -->|"loads instance"| node_predictor
node_api -->|"requests prediction"| node_predictor
node_api -->|"requests explanation"| node_predictor
node_predictor -->|"builds features"| node_features
node_api -->|"renders pages"| node_templates
node_raw -->|"reads data"| node_ingestion
node_ingestion -->|"writes splits"| node_processed
node_train -->|"reads training data"| node_processed
node_train -->|"builds features"| node_features
node_train -->|"saves models"| node_artifacts
node_predictor -->|"loads best model"| node_artifacts
node_baseline_predictor -.->|"loads baseline model"| node_artifacts
node_evaluation -->|"reads test data"| node_processed
node_evaluation -->|"loads baseline model"| node_artifacts
node_advanced_eval -->|"reads test data"| node_processed
node_advanced_eval -->|"builds features"| node_features
node_advanced_eval -->|"loads best model"| node_artifacts
node_ingestion -->|"logs activity"| node_logger
node_features -->|"raises on failure"| node_exceptions
node_predictor -->|"raises on failure"| node_exceptions
node_exceptions -->|"logs errors"| node_logger

click node_raw "https://github.com/computerscistudent/customer-churn-prediction/blob/main/data/raw/telco.csv"
click node_ingestion "https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/data/data_ingestion.py"
click node_processed "https://github.com/computerscistudent/customer-churn-prediction/tree/main/data/processed"
click node_features "https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/features/build_features.py"
click node_train "https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/models/train_model_advance.py"
click node_artifacts "https://github.com/computerscistudent/customer-churn-prediction/tree/main/artifacts"
click node_evaluation "https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/models/evaluate.py"
click node_advanced_eval "https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/models/eval_advanced.py"
click node_baseline_predictor "https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/models/predict_pipeline.py"
click node_api "https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/api/main.py"
click node_schema "https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/api/schema.py"
click node_dependencies "https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/api/dependences.py"
click node_predictor "https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/models/predict_with_shap.py"
click node_templates "https://github.com/computerscistudent/customer-churn-prediction/tree/main/templates"
click node_logger "https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/logger.py"
click node_exceptions "https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/exception.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_raw,node_ingestion,node_processed,node_features,node_user toneBlue
class node_train,node_artifacts,node_evaluation,node_advanced_eval,node_baseline_predictor,node_predictor toneAmber
class node_api,node_schema,node_dependencies,node_templates toneMint
class node_logger,node_exceptions toneRose
```

## Components

### Data preparation

- [Telco source data](https://github.com/computerscistudent/customer-churn-prediction/blob/main/data/raw/telco.csv): `data/raw/telco.csv`
- [Data ingestion](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/data/data_ingestion.py): `src/data/data_ingestion.py`
- [Train and test data](https://github.com/computerscistudent/customer-churn-prediction/tree/main/data/processed): `data/processed`
- [Feature engineering](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/features/build_features.py): `src/features/build_features.py`

### Model lifecycle

- [Model training](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/models/train_model_advance.py): `src/models/train_model_advance.py`
- [Model artifacts](https://github.com/computerscistudent/customer-churn-prediction/tree/main/artifacts): `artifacts`
- [Model evaluation](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/models/evaluate.py): `src/models/evaluate.py`
- [Advanced evaluation](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/models/eval_advanced.py): `src/models/eval_advanced.py`
- [Baseline predictor](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/models/predict_pipeline.py): `src/models/predict_pipeline.py`
- [Prediction and SHAP](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/models/predict_with_shap.py): `src/models/predict_with_shap.py`

### Prediction API

- [FastAPI routes](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/api/main.py): `src/api/main.py`
- [Request schemas](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/api/schema.py): `src/api/schema.py`
- [Predictor dependency](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/api/dependences.py): `src/api/dependences.py`
- [HTML templates](https://github.com/computerscistudent/customer-churn-prediction/tree/main/templates): `templates`

### Shared internals

- [Logging](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/logger.py): `src/logger.py`
- [Error handling](https://github.com/computerscistudent/customer-churn-prediction/blob/main/src/exception.py): `src/exception.py`

### Other components

- **API client**

## Connections

- API client → FastAPI routes: submits request (evidence: `README.md`)
- FastAPI routes → Request schemas: validates with (evidence: `src/api/main.py`)
- FastAPI routes → Predictor dependency: resolves predictor (evidence: `src/api/main.py`)
- Predictor dependency → Prediction and SHAP: loads instance (evidence: `src/api/dependences.py`)
- FastAPI routes → Prediction and SHAP: requests prediction (evidence: `src/api/main.py`)
- FastAPI routes → Prediction and SHAP: requests explanation (evidence: `src/api/main.py`)
- Prediction and SHAP → Feature engineering: builds features (evidence: `src/models/predict_with_shap.py`)
- FastAPI routes → HTML templates: renders pages (evidence: `src/api/main.py`)
- Telco source data → Data ingestion: reads data (evidence: `src/data/data_ingestion.py`)
- Data ingestion → Train and test data: writes splits (evidence: `src/data/data_ingestion.py`)
- Model training → Train and test data: reads training data (evidence: `src/models/train_model_advance.py`)
- Model training → Feature engineering: builds features (evidence: `src/models/train_model_advance.py`)
- Model training → Model artifacts: saves models (evidence: `src/models/train_model_advance.py`)
- Prediction and SHAP → Model artifacts: loads best model
- Baseline predictor → Model artifacts: loads baseline model
- Model evaluation → Train and test data: reads test data (evidence: `src/models/evaluate.py`)
- Model evaluation → Model artifacts: loads baseline model (evidence: `src/models/evaluate.py`)
- Advanced evaluation → Train and test data: reads test data (evidence: `src/models/eval_advanced.py`)
- Advanced evaluation → Feature engineering: builds features (evidence: `src/models/eval_advanced.py`)
- Advanced evaluation → Model artifacts: loads best model (evidence: `src/models/eval_advanced.py`)
- Data ingestion → Logging: logs activity (evidence: `src/data/data_ingestion.py`)
- Feature engineering → Error handling: raises on failure (evidence: `src/features/build_features.py`)
- Prediction and SHAP → Error handling: raises on failure (evidence: `src/models/predict_with_shap.py`)
- Error handling → Logging: logs errors (evidence: `src/exception.py`)
