# kadufallone/credit-risk-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/kadufallone/credit-risk-prediction
- Repository: https://github.com/kadufallone/credit-risk-prediction

## Overview

Credit Risk Predictor trains a default-probability model from a CSV and serves predictions through a FastAPI REST API. The training workflow loads and cleans records, makes a stratified train/test split, fits a preprocessing-and-classification pipeline, evaluates it, and saves a model artifact. For inference, the API validates client data, the predictor returns a probability and risk category, and the API formats the response. Training internals and API wiring are excerpted; the dataset and generated artifact are documented in the README, so their precise runtime details are not independently inspected.

Main entry points: [`src/api.py`](https://github.com/kadufallone/credit-risk-prediction/blob/main/src/api.py) (FastAPI routes), [`src/train.py`](https://github.com/kadufallone/credit-risk-prediction/blob/main/src/train.py) (Preprocess and train), [`src/predictor.py`](https://github.com/kadufallone/credit-risk-prediction/blob/main/src/predictor.py) (Default probability), [`models`](https://github.com/kadufallone/credit-risk-prediction/tree/main/models) (Trained model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Model training"]
  node_dataset["Credit risk CSV"]
  node_training_data["Clean and split data<br/>[train.py]"]
  node_model_pipeline["Preprocess and train<br/>[train.py]"]
  node_evaluation["Evaluate model<br/>[train.py]"]
  node_model_artifact[("Trained model")]
end

subgraph group_serving["Prediction service"]
  node_api["FastAPI routes<br/>[api.py]"]
  node_predictor["Default probability<br/>[predictor.py]"]
  node_risk["Risk classification<br/>[predictor.py]"]
end

subgraph group_contracts["API contracts"]
  node_client_schema["Client input schema<br/>[schemas.py]"]
  node_prediction_schema["Prediction response<br/>[schemas.py]"]
end

node_client(("API client"))

node_dataset -->|"loads and cleans"| node_training_data
node_training_data -->|"splits data"| node_model_pipeline
node_model_pipeline -->|"fits and evaluates"| node_evaluation
node_model_pipeline -->|"saves model"| node_model_artifact
node_client -->|"submits request"| node_api
node_api -->|"validates input"| node_client_schema
node_api -->|"requests prediction"| node_predictor
node_predictor -->|"loads model"| node_model_artifact
node_predictor -->|"classifies probability"| node_risk
node_api -->|"formats response"| node_prediction_schema

click node_dataset "https://github.com/kadufallone/credit-risk-prediction/blob/main/data/credit_risk_dataset.csv"
click node_training_data "https://github.com/kadufallone/credit-risk-prediction/blob/main/src/train.py"
click node_model_pipeline "https://github.com/kadufallone/credit-risk-prediction/blob/main/src/train.py"
click node_evaluation "https://github.com/kadufallone/credit-risk-prediction/blob/main/src/train.py"
click node_model_artifact "https://github.com/kadufallone/credit-risk-prediction/tree/main/models"
click node_api "https://github.com/kadufallone/credit-risk-prediction/blob/main/src/api.py"
click node_client_schema "https://github.com/kadufallone/credit-risk-prediction/blob/main/src/schemas.py"
click node_predictor "https://github.com/kadufallone/credit-risk-prediction/blob/main/src/predictor.py"
click node_risk "https://github.com/kadufallone/credit-risk-prediction/blob/main/src/predictor.py"
click node_prediction_schema "https://github.com/kadufallone/credit-risk-prediction/blob/main/src/schemas.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_dataset,node_training_data,node_model_pipeline,node_evaluation,node_model_artifact,node_client toneBlue
class node_api,node_predictor,node_risk toneAmber
class node_client_schema,node_prediction_schema toneMint
```

## Components

### Model training

- [Credit risk CSV](https://github.com/kadufallone/credit-risk-prediction/blob/main/data/credit_risk_dataset.csv): `data/credit_risk_dataset.csv`
- [Clean and split data](https://github.com/kadufallone/credit-risk-prediction/blob/main/src/train.py): `src/train.py`
- [Preprocess and train](https://github.com/kadufallone/credit-risk-prediction/blob/main/src/train.py): `src/train.py`
- [Evaluate model](https://github.com/kadufallone/credit-risk-prediction/blob/main/src/train.py): `src/train.py`
- [Trained model](https://github.com/kadufallone/credit-risk-prediction/tree/main/models): `models`

### Prediction service

- [FastAPI routes](https://github.com/kadufallone/credit-risk-prediction/blob/main/src/api.py): `src/api.py`
- [Default probability](https://github.com/kadufallone/credit-risk-prediction/blob/main/src/predictor.py): `src/predictor.py`
- [Risk classification](https://github.com/kadufallone/credit-risk-prediction/blob/main/src/predictor.py): `src/predictor.py`

### API contracts

- [Client input schema](https://github.com/kadufallone/credit-risk-prediction/blob/main/src/schemas.py): `src/schemas.py`
- [Prediction response](https://github.com/kadufallone/credit-risk-prediction/blob/main/src/schemas.py): `src/schemas.py`

### Other components

- **API client**

## Connections

- Credit risk CSV → Clean and split data: loads and cleans (evidence: `src/train.py`)
- Clean and split data → Preprocess and train: splits data (evidence: `src/train.py`)
- Preprocess and train → Evaluate model: fits and evaluates (evidence: `src/train.py`)
- Preprocess and train → Trained model: saves model (evidence: `src/train.py`)
- API client → FastAPI routes: submits request (evidence: `README.md`)
- FastAPI routes → Client input schema: validates input (evidence: `src/api.py`)
- FastAPI routes → Default probability: requests prediction (evidence: `src/api.py`)
- Default probability → Trained model: loads model (evidence: `src/predictor.py`)
- Default probability → Risk classification: classifies probability (evidence: `src/predictor.py`)
- FastAPI routes → Prediction response: formats response (evidence: `src/api.py`)
