# hanlaigia/ml_loans_prediction architecture

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

- Interactive diagram: https://gitdiagram.com/hanlaigia/ml_loans_prediction
- Repository: https://github.com/hanlaigia/ml_loans_prediction

## Overview

This is a loan-default risk prediction web application: staff sign in, enter a loan application, request a risk prediction, and can save it for later review. The UI also exposes filtered loan records and statistical dashboards. The graph distinguishes the application, prediction, and persistence stages, plus the backend’s API and data-access layer. README documentation supports the major features and API wiring; some frontend request handlers and backend helper implementations were not sampled, so those links follow documented endpoints and uncertain internal calls are omitted.

Main entry points: [`backend/routers/loans.py`](https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/routers/loans.py) (Loan endpoints), [`backend/main.py`](https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/main.py) (FastAPI entry), [`backend/crud.py`](https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/crud.py) (Loan and dashboard operations), [`frontend/app/page.tsx`](https://github.com/hanlaigia/ml_loans_prediction/blob/main/frontend/app/page.tsx) (Loan application form)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_login["Sign in<br/>[page.tsx]"]
  node_guard["Route protection<br/>[auth-guard.tsx]"]
  node_application["Loan application form<br/>[page.tsx]"]
  node_dashboard["Statistics dashboard<br/>[page.tsx]"]
  node_records["Saved loan records<br/>[page.tsx]"]
end

subgraph group_api["Backend API"]
  node_api_main["FastAPI entry<br/>[main.py]"]
  node_loans_api["Loan endpoints<br/>[loans.py]"]
  node_schemas["Request and response schemas<br/>[schemas.py]"]
end

subgraph group_prediction["Risk prediction"]
  node_model_loader["Model inference<br/>[model_loader.py]"]
  node_trained_model["Trained XGBoost model"]
end

subgraph group_data["Persistence and analytics"]
  node_crud["Loan and dashboard operations<br/>[crud.py]"]
  node_orm["Loan and employee models<br/>[models.py]"]
  node_database["SQLAlchemy connection<br/>[database.py]"]
end

node_staff(("Loan staff"))
node_mysql[("MySQL database")]

node_staff -->|"signs in"| node_login
node_login -->|"submits credentials"| node_api_main
node_staff -->|"enters application"| node_application
node_application -->|"requests prediction"| node_loans_api
node_application -->|"saves application"| node_loans_api
node_staff -->|"views statistics"| node_dashboard
node_dashboard -->|"requests dashboard"| node_api_main
node_staff -->|"reviews records"| node_records
node_records -->|"filters or deletes"| node_loans_api
node_api_main -->|"requests dashboard data"| node_crud
node_api_main -->|"looks up employee"| node_crud
node_api_main -->|"dispatches loan routes"| node_loans_api
node_loans_api -->|"requests inference"| node_model_loader
node_model_loader -.->|"predicts with"| node_trained_model
node_loans_api -->|"creates loan"| node_crud
node_loans_api -->|"queries loan records"| node_orm
node_crud -->|"uses mapped entities"| node_orm
node_crud -->|"uses session"| node_database
node_loans_api -->|"gets database session"| node_database
node_database -->|"connects to"| node_mysql

click node_login "https://github.com/hanlaigia/ml_loans_prediction/blob/main/frontend/app/login/page.tsx"
click node_guard "https://github.com/hanlaigia/ml_loans_prediction/blob/main/frontend/components/auth-guard.tsx"
click node_application "https://github.com/hanlaigia/ml_loans_prediction/blob/main/frontend/app/page.tsx"
click node_dashboard "https://github.com/hanlaigia/ml_loans_prediction/blob/main/frontend/app/dashboard/page.tsx"
click node_records "https://github.com/hanlaigia/ml_loans_prediction/blob/main/frontend/app/all-data/page.tsx"
click node_api_main "https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/main.py"
click node_loans_api "https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/routers/loans.py"
click node_schemas "https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/schemas.py"
click node_model_loader "https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/model_loader.py"
click node_crud "https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/crud.py"
click node_orm "https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/models.py"
click node_database "https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/database.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_login,node_guard,node_application,node_dashboard,node_records toneBlue
class node_api_main,node_loans_api,node_schemas,node_mysql toneAmber
class node_model_loader,node_trained_model toneMint
class node_crud,node_orm,node_database toneRose
class node_staff toneIndigo
```

## Components

### Web application

- [Sign in](https://github.com/hanlaigia/ml_loans_prediction/blob/main/frontend/app/login/page.tsx): `frontend/app/login/page.tsx`
- [Route protection](https://github.com/hanlaigia/ml_loans_prediction/blob/main/frontend/components/auth-guard.tsx): `frontend/components/auth-guard.tsx`
- [Loan application form](https://github.com/hanlaigia/ml_loans_prediction/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Statistics dashboard](https://github.com/hanlaigia/ml_loans_prediction/blob/main/frontend/app/dashboard/page.tsx): `frontend/app/dashboard/page.tsx`
- [Saved loan records](https://github.com/hanlaigia/ml_loans_prediction/blob/main/frontend/app/all-data/page.tsx): `frontend/app/all-data/page.tsx`

### Backend API

- [FastAPI entry](https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/main.py): `backend/main.py`
- [Loan endpoints](https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/routers/loans.py): `backend/routers/loans.py`
- [Request and response schemas](https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/schemas.py): `backend/schemas.py`

### Risk prediction

- [Model inference](https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/model_loader.py): `backend/model_loader.py`
- **Trained XGBoost model**

### Persistence and analytics

- [Loan and dashboard operations](https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/crud.py): `backend/crud.py`
- [Loan and employee models](https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/models.py): `backend/models.py`
- [SQLAlchemy connection](https://github.com/hanlaigia/ml_loans_prediction/blob/main/backend/database.py): `backend/database.py`

### Other components

- **Loan staff**
- **MySQL database**

## Connections

- Loan staff → Sign in: signs in
- Sign in → FastAPI entry: submits credentials
- Loan staff → Loan application form: enters application
- Loan application form → Loan endpoints: requests prediction
- Loan application form → Loan endpoints: saves application
- Loan staff → Statistics dashboard: views statistics
- Statistics dashboard → FastAPI entry: requests dashboard
- Loan staff → Saved loan records: reviews records
- Saved loan records → Loan endpoints: filters or deletes
- FastAPI entry → Loan and dashboard operations: requests dashboard data
- FastAPI entry → Loan and dashboard operations: looks up employee
- FastAPI entry → Loan endpoints: dispatches loan routes
- Loan endpoints → Model inference: requests inference
- Model inference → Trained XGBoost model: predicts with
- Loan endpoints → Loan and dashboard operations: creates loan
- Loan endpoints → Loan and employee models: queries loan records
- Loan and dashboard operations → Loan and employee models: uses mapped entities
- Loan and dashboard operations → SQLAlchemy connection: uses session
- Loan endpoints → SQLAlchemy connection: gets database session
- SQLAlchemy connection → MySQL database: connects to
