# m-tanusree-reddy/credit-risk-predictor- architecture

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

- Interactive diagram: https://gitdiagram.com/m-tanusree-reddy/credit-risk-predictor-
- Repository: https://github.com/m-tanusree-reddy/credit-risk-predictor-

## Overview

#### Purpose and entry points
Credit Risk Predictor scores applicant default risk using persisted model artifacts behind a FastAPI service, with a React/Vite dashboard for individual assessment and capped batch CSV scoring. Primary runtime entry points are `backend/main.py` (Uvicorn/FastAPI) and `frontend/src/main.tsx` (browser application). A previous Streamlit implementation remains at `frontend/legacy_streamlit_app.py`.

#### Model-serving boundary
The Python prediction service owns model inference and feature scaling, using serialized artifacts in `models/credit_risk_model.pkl` and `models/scaler.pkl`. `backend/main.py` is the API boundary between browser-facing request data and Python/ML dependencies. Training/source data is retained separately in `Data/cs-training.csv`, with development work represented by `notebook.ipynb`; these are not part of the normal interactive serving path.

#### Frontend application shell
The SPA is initialized by `frontend/src/main.tsx` and composed from `frontend/src/App.tsx`. It is built and served through Vite configuration in `frontend/vite.config.ts`; local frontend configuration can select a non-default API base URL via `frontend/.env.example`. The frontend is an independent Node/browser runtime from the Python backend.

#### Assessment and dashboard flows
The UI separates major user workflows into dashboard, single-applicant assessment, and batch views: `frontend/src/components/DashboardView.tsx`, `frontend/src/components/AssessmentView.tsx`, and `frontend/src/components/BatchView.tsx`. Shared client-side request/response contracts are represented in `frontend/src/types.ts`, while API communication is centralized in `frontend/src/utils/api.ts`. This keeps model-service protocol concerns outside visual components.

#### Batch ingestion and scoring
Batch processing begins in the browser, where CSV input is parsed and capped at 500 records before submission to avoid browser and API CPU bottlenecks. `frontend/src/components/BatchView.tsx` owns the user-facing progress and result workflow; `frontend/src/utils/api.ts` crosses the service boundary for scoring. The application cleans likely index/system columns and uses structured identifiers when applicant-name metadata is absent.

#### Explainability path
Detailed explanation is intentionally deferred from fast batch scoring: `frontend/src/components/ExplainabilityView.tsx` provides the on-demand SHAP-oriented presentation, while `frontend/src/components/BatchView.tsx` exposes the interaction from scored applicants. This creates a control-flow split between low-latency risk-level predictions and per-applicant detailed explanation requests, expected to be served by `backend/main.py`.

#### Deployment and auxiliary API surface
The repository includes a TypeScript API handler at `api/extract.ts` and Vercel deployment configuration in `vercel.json`, indicating a serverless/deployment-facing integration surface distinct from local FastAPI execution. `frontend/server.ts` is also a server-side frontend-adjacent runtime entry point. These should be checked when changing deployment routing so browser requests, serverless handlers, and `backend/main.py` do not diverge.

Main entry points: [`frontend/src/App.tsx`](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/App.tsx) (Application shell), [`frontend/src/utils/api.ts`](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/utils/api.ts) (API client), [`frontend/src/components/BatchView.tsx`](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/components/BatchView.tsx) (Batch scoring), [`backend/main.py`](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/backend/main.py) (Prediction API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React / Vite frontend"]
  node_browser(("Browser user<br/>client"))
  node_frontend_entry["SPA entry<br/>React entry<br/>[main.tsx]"]
  node_app_shell["Application shell<br/>React app<br/>[App.tsx]"]
  node_dashboard["Dashboard<br/>view<br/>[DashboardView.tsx]"]
  node_assessment["Single assessment<br/>view<br/>[AssessmentView.tsx]"]
  node_batch["Batch scoring<br/>view<br/>[BatchView.tsx]"]
  node_explainability["Explanation view"]
  node_api_client{{"API client<br/>protocol client<br/>[api.ts]"}}
  node_contracts["Client contracts<br/>TypeScript types<br/>[types.ts]"]
  node_vite["Vite build / serve<br/>build runtime<br/>[vite.config.ts]"]
  node_frontend_server["Frontend server<br/>Node entry<br/>[server.ts]"]
end

subgraph group_backend["Python model service"]
  node_fastapi{{"Prediction API<br/>FastAPI service<br/>[main.py]"}}
  node_model[("Risk model<br/>serialized model")]
  node_scaler[("Feature scaler<br/>serialized artifact<br/>[scaler.pkl]")]
end

subgraph group_deployment["Deployment integration"]
  node_extract_handler{{"Extract handler<br/>serverless handler<br/>[extract.ts]"}}
  node_vercel["Vercel routing<br/>deployment config<br/>[vercel.json]"]
end

node_training_data[("Training data<br/>CSV dataset<br/>[cs-training.csv]")]
node_notebook["Model development<br/>notebook<br/>[notebook.ipynb]"]
node_legacy_streamlit["Legacy Streamlit UI<br/>legacy app"]

node_browser -->|"loads"| node_frontend_entry
node_frontend_entry -->|"mounts"| node_app_shell
node_app_shell -->|"renders"| node_dashboard
node_app_shell -->|"renders"| node_assessment
node_app_shell -->|"renders"| node_batch
node_assessment -->|"score request"| node_api_client
node_batch -->|"capped CSV scoring"| node_api_client
node_batch -->|"select applicant"| node_explainability
node_explainability -->|"detail request"| node_api_client
node_api_client -.->|"uses"| node_contracts
node_api_client -->|"HTTP scoring / explanation"| node_fastapi
node_fastapi -->|"loads for inference"| node_model
node_fastapi -->|"loads for features"| node_scaler
node_vite -->|"builds / serves"| node_frontend_entry
node_frontend_server -.->|"server-side runtime"| node_app_shell
node_vercel -->|"routes deployment traffic"| node_extract_handler
node_vercel -.->|"deploys runtime"| node_frontend_server
node_training_data -.->|"development input"| node_notebook
node_notebook -.->|"produces artifact"| node_model

click node_frontend_entry "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/main.tsx"
click node_app_shell "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/App.tsx"
click node_dashboard "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/components/DashboardView.tsx"
click node_assessment "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/components/AssessmentView.tsx"
click node_batch "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/components/BatchView.tsx"
click node_explainability "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/components/ExplainabilityView.tsx"
click node_api_client "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/utils/api.ts"
click node_contracts "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/types.ts"
click node_vite "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/vite.config.ts"
click node_frontend_server "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/server.ts"
click node_fastapi "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/backend/main.py"
click node_model "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/models/credit_risk_model.pkl"
click node_scaler "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/models/scaler.pkl"
click node_extract_handler "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/api/extract.ts"
click node_vercel "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/vercel.json"
click node_training_data "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/Data/cs-training.csv"
click node_notebook "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/notebook.ipynb"
click node_legacy_streamlit "https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/legacy_streamlit_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_browser,node_frontend_entry,node_app_shell,node_dashboard,node_assessment,node_batch,node_explainability,node_api_client,node_contracts,node_vite,node_frontend_server toneBlue
class node_fastapi,node_model,node_scaler toneAmber
class node_extract_handler,node_vercel toneMint
class node_training_data,node_notebook,node_legacy_streamlit toneNeutral
```

## Components

### React / Vite frontend

Independent browser and Node runtime.

- **Browser user**: client
- [SPA entry](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/main.tsx): React entry · `frontend/src/main.tsx`
- [Application shell](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/App.tsx): React app · `frontend/src/App.tsx`
- [Dashboard](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/components/DashboardView.tsx): view · `frontend/src/components/DashboardView.tsx`
- [Single assessment](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/components/AssessmentView.tsx): view · `frontend/src/components/AssessmentView.tsx`
- [Batch scoring](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/components/BatchView.tsx): view · Parses CSV, removes likely system columns, and caps input at 500 records. · `frontend/src/components/BatchView.tsx`
- [Explanation view](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/components/ExplainabilityView.tsx): view · On-demand SHAP-oriented applicant detail. · `frontend/src/components/ExplainabilityView.tsx`
- [API client](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/utils/api.ts): protocol client · `frontend/src/utils/api.ts`
- [Client contracts](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/src/types.ts): TypeScript types · `frontend/src/types.ts`
- [Vite build / serve](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/vite.config.ts): build runtime · `frontend/vite.config.ts`
- [Frontend server](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/server.ts): Node entry · `frontend/server.ts`

### Python model service

FastAPI serving boundary for inference and explanations.

- [Prediction API](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/backend/main.py): FastAPI service · Accepts browser-facing scoring and detailed explanation requests. · `backend/main.py`
- [Risk model](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/models/credit_risk_model.pkl): serialized model · `models/credit_risk_model.pkl`
- [Feature scaler](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/models/scaler.pkl): serialized artifact · `models/scaler.pkl`

### Deployment integration

Serverless and routing surface.

- [Extract handler](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/api/extract.ts): serverless handler · `api/extract.ts`
- [Vercel routing](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/vercel.json): deployment config · `vercel.json`

### Other components

- [Training data](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/Data/cs-training.csv): CSV dataset · Retained outside the normal serving path. · `Data/cs-training.csv`
- [Model development](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/notebook.ipynb): notebook · Development work outside the normal serving path. · `notebook.ipynb`
- [Legacy Streamlit UI](https://github.com/m-tanusree-reddy/credit-risk-predictor-/blob/main/frontend/legacy_streamlit_app.py): legacy app · Previous implementation retained alongside the SPA. · `frontend/legacy_streamlit_app.py`

## Connections

- Browser user → SPA entry: loads
- SPA entry → Application shell: mounts
- Application shell → Dashboard: renders
- Application shell → Single assessment: renders
- Application shell → Batch scoring: renders
- Single assessment → API client: score request
- Batch scoring → API client: capped CSV scoring
- Batch scoring → Explanation view: select applicant
- Explanation view → API client: detail request
- API client → Client contracts: uses
- API client → Prediction API: HTTP scoring / explanation
- Prediction API → Risk model: loads for inference
- Prediction API → Feature scaler: loads for features
- Vite build / serve → SPA entry: builds / serves
- Frontend server → Application shell: server-side runtime
- Vercel routing → Extract handler: routes deployment traffic
- Vercel routing → Frontend server: deploys runtime
- Training data → Model development: development input
- Model development → Risk model: produces artifact
