# jensbender/loan-default-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/jensbender/loan-default-prediction
- Repository: https://github.com/jensbender/loan-default-prediction

## Overview

This is a loan-default risk prediction web application. A borrower enters application details in Gradio; the frontend formats them and posts to FastAPI, which validates inputs, runs the downloaded scikit-learn pipeline, applies its prediction threshold, and returns a prediction with probabilities. The pipeline includes missing-value handling, feature engineering, encoding/scaling, selection, and a Random Forest model. Backend monitoring and optional IP geolocation are also represented. Pipeline internals are sampled, but portions of the backend are omitted, so uncertain processing links are not expanded.

Main entry points: [`backend/app.py`](https://github.com/jensbender/loan-default-prediction/blob/main/backend/app.py) (FastAPI endpoint), [`src/pipeline.py`](https://github.com/jensbender/loan-default-prediction/blob/main/src/pipeline.py) (Random Forest pipeline), [`frontend/app.py`](https://github.com/jensbender/loan-default-prediction/blob/main/frontend/app.py) (Gradio form), [`backend/schemas.py`](https://github.com/jensbender/loan-default-prediction/blob/main/backend/schemas.py) (Input/output schemas)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interface"]
  node_ui["Gradio form<br/>[app.py]"]
end

subgraph group_service["Prediction service"]
  node_api["FastAPI endpoint<br/>[app.py]"]
  node_schemas["Input/output schemas<br/>[schemas.py]"]
end

subgraph group_ml["Prediction pipeline"]
  node_model["Random Forest pipeline<br/>[pipeline.py]"]
  node_features["Feature engineering"]
  node_constants["Feature mappings"]
end

subgraph group_ops["Monitoring"]
  node_monitor["Prediction logging<br/>[app.py]"]
  node_geo[("GeoIP database")]
end

node_borrower(("Applicant"))
node_hub["Hugging Face Hub"]

node_borrower -->|"enters application"| node_ui
node_ui -->|"posts prediction request"| node_api
node_api -->|"validates inputs"| node_schemas
node_api -->|"runs inference"| node_model
node_model -->|"uses transformers"| node_features
node_model -->|"configures stages"| node_constants
node_schemas -->|"uses allowed labels"| node_constants
node_api -->|"writes prediction records"| node_monitor
node_api -->|"looks up client country"| node_geo
node_api -->|"downloads pipeline"| node_hub
node_hub -.->|"supplies serialized pipeline"| node_model
node_api -->|"mounts Gradio app"| node_ui

click node_ui "https://github.com/jensbender/loan-default-prediction/blob/main/frontend/app.py"
click node_api "https://github.com/jensbender/loan-default-prediction/blob/main/backend/app.py"
click node_schemas "https://github.com/jensbender/loan-default-prediction/blob/main/backend/schemas.py"
click node_model "https://github.com/jensbender/loan-default-prediction/blob/main/src/pipeline.py"
click node_features "https://github.com/jensbender/loan-default-prediction/blob/main/src/custom_transformers.py"
click node_constants "https://github.com/jensbender/loan-default-prediction/blob/main/src/global_constants.py"
click node_monitor "https://github.com/jensbender/loan-default-prediction/blob/main/backend/app.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_ui toneBlue
class node_api,node_schemas toneAmber
class node_model,node_features,node_constants toneMint
class node_monitor,node_geo toneRose
class node_borrower,node_hub toneIndigo
```

## Components

### User interface

- [Gradio form](https://github.com/jensbender/loan-default-prediction/blob/main/frontend/app.py): `frontend/app.py`

### Prediction service

- [FastAPI endpoint](https://github.com/jensbender/loan-default-prediction/blob/main/backend/app.py): `backend/app.py`
- [Input/output schemas](https://github.com/jensbender/loan-default-prediction/blob/main/backend/schemas.py): `backend/schemas.py`

### Prediction pipeline

- [Random Forest pipeline](https://github.com/jensbender/loan-default-prediction/blob/main/src/pipeline.py): `src/pipeline.py`
- [Feature engineering](https://github.com/jensbender/loan-default-prediction/blob/main/src/custom_transformers.py): `src/custom_transformers.py`
- [Feature mappings](https://github.com/jensbender/loan-default-prediction/blob/main/src/global_constants.py): `src/global_constants.py`

### Monitoring

- [Prediction logging](https://github.com/jensbender/loan-default-prediction/blob/main/backend/app.py): `backend/app.py`
- **GeoIP database**

### Other components

- **Applicant**
- **Hugging Face Hub**

## Connections

- Applicant → Gradio form: enters application (evidence: `README.md`)
- Gradio form → FastAPI endpoint: posts prediction request (evidence: `frontend/app.py`)
- FastAPI endpoint → Input/output schemas: validates inputs (evidence: `backend/app.py`)
- FastAPI endpoint → Random Forest pipeline: runs inference (evidence: `README.md`)
- Random Forest pipeline → Feature engineering: uses transformers (evidence: `src/pipeline.py`)
- Random Forest pipeline → Feature mappings: configures stages (evidence: `src/pipeline.py`)
- Input/output schemas → Feature mappings: uses allowed labels (evidence: `backend/schemas.py`)
- FastAPI endpoint → Prediction logging: writes prediction records (evidence: `backend/app.py`)
- FastAPI endpoint → GeoIP database: looks up client country (evidence: `backend/app.py`)
- FastAPI endpoint → Hugging Face Hub: downloads pipeline (evidence: `backend/app.py`)
- Hugging Face Hub → Random Forest pipeline: supplies serialized pipeline (evidence: `README.md`)
- FastAPI endpoint → Gradio form: mounts Gradio app (evidence: `backend/app.py`)
