# dheerajrai-dev/credilens architecture

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

- Interactive diagram: https://gitdiagram.com/dheerajrai-dev/credilens
- Repository: https://github.com/dheerajrai-dev/credilens

## Overview

CrediLens is an explainable credit-risk decision-support application. Applicants enter loan and personal attributes in the Streamlit dashboard; the client uses the FastAPI service when available, otherwise it invokes inference in-process. The service scores applicants, applies the calibrated-model threshold, and returns recommendations and explanations; separate dashboard views provide batch scoring, model evaluation, and global explainability. The README documents model artifacts and capabilities beyond the sampled service implementation, so those documented stages are included without asserting unsampled internal calls.

Main entry points: [`app/frontend/api_client.py`](https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/api_client.py) (API client), [`app/services/prediction_service.py`](https://github.com/dheerajrai-dev/credilens/blob/main/app/services/prediction_service.py) (Inference engine), [`app/frontend/streamlit_app.py`](https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/streamlit_app.py) (Streamlit dashboard), [`app/api/routes/prediction.py`](https://github.com/dheerajrai-dev/credilens/blob/main/app/api/routes/prediction.py) (Prediction routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dashboard["Dashboard"]
  node_dashboard["Streamlit dashboard<br/>[streamlit_app.py]"]
  node_prediction_view["Applicant prediction<br/>[prediction_view.py]"]
  node_evaluation_view["Model evaluation<br/>[evaluation_view.py]"]
  node_explainability_view["Global explainability"]
  node_batch_view["Batch scoring<br/>[batch_view.py]"]
  node_api_client["API client<br/>[api_client.py]"]
  node_styles["Dashboard styling<br/>[styles.py]"]
end

subgraph group_serving["API Serving"]
  node_api_service["FastAPI service<br/>[main.py]"]
  node_prediction_routes["Prediction routes<br/>[prediction.py]"]
  node_service_dependency["Service dependency<br/>[dependencies.py]"]
  node_service_lifecycle["Model startup<br/>[lifespan.py]"]
end

subgraph group_inference["Risk Inference"]
  node_prediction_service["Inference engine"]
  node_model_pipeline["Calibrated model"]
  node_baseline_models["Baseline models<br/>[baselines.joblib]"]
  node_decision_threshold["Decision threshold<br/>[best_threshold.pkl]"]
end

subgraph group_contracts["Data Contracts"]
  node_applicant_schema["Applicant schema<br/>[credit.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

node_user(("Credit analyst"))

node_user -->|"uses"| node_dashboard
node_dashboard -->|"dispatches"| node_prediction_view
node_dashboard -->|"dispatches"| node_evaluation_view
node_dashboard -->|"dispatches"| node_explainability_view
node_dashboard -->|"dispatches"| node_batch_view
node_dashboard -->|"creates"| node_api_client
node_dashboard -->|"applies"| node_styles
node_prediction_view -->|"requests predictions"| node_api_client
node_evaluation_view -->|"requests evaluation"| node_api_client
node_batch_view -.->|"requests scoring"| node_api_client
node_api_client -->|"calls over HTTP"| node_api_service
node_api_client -->|"falls back in-process"| node_prediction_service
node_api_client -->|"validates input"| node_applicant_schema
node_api_client -->|"reads host and port"| node_config
node_api_service -.->|"registers routes"| node_prediction_routes
node_prediction_routes -->|"resolves service"| node_service_dependency
node_service_dependency -->|"gets instance"| node_prediction_service
node_prediction_routes -->|"calls inference"| node_prediction_service
node_prediction_routes -->|"validates and returns"| node_applicant_schema
node_service_lifecycle -->|"initializes"| node_prediction_service
node_prediction_service -->|"loads and scores"| node_model_pipeline
node_prediction_service -->|"loads for comparison"| node_baseline_models
node_prediction_service -->|"loads decision cutoff"| node_decision_threshold
node_prediction_service -->|"returns typed results"| node_applicant_schema

click node_dashboard "https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/streamlit_app.py"
click node_prediction_view "https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/views/prediction_view.py"
click node_evaluation_view "https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/views/evaluation_view.py"
click node_explainability_view "https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/views/explainability_view.py"
click node_batch_view "https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/views/batch_view.py"
click node_api_client "https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/api_client.py"
click node_styles "https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/styles.py"
click node_api_service "https://github.com/dheerajrai-dev/credilens/blob/main/app/api/main.py"
click node_prediction_routes "https://github.com/dheerajrai-dev/credilens/blob/main/app/api/routes/prediction.py"
click node_service_dependency "https://github.com/dheerajrai-dev/credilens/blob/main/app/api/dependencies.py"
click node_service_lifecycle "https://github.com/dheerajrai-dev/credilens/blob/main/app/api/lifespan.py"
click node_prediction_service "https://github.com/dheerajrai-dev/credilens/blob/main/app/services/prediction_service.py"
click node_model_pipeline "https://github.com/dheerajrai-dev/credilens/blob/main/models/Credit_risk_model.pkl"
click node_baseline_models "https://github.com/dheerajrai-dev/credilens/blob/main/models/baselines.joblib"
click node_decision_threshold "https://github.com/dheerajrai-dev/credilens/blob/main/models/best_threshold.pkl"
click node_applicant_schema "https://github.com/dheerajrai-dev/credilens/blob/main/app/schemas/credit.py"
click node_config "https://github.com/dheerajrai-dev/credilens/blob/main/app/core/config.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_dashboard,node_prediction_view,node_evaluation_view,node_explainability_view,node_batch_view,node_api_client,node_styles toneBlue
class node_api_service,node_prediction_routes,node_service_dependency,node_service_lifecycle toneAmber
class node_prediction_service,node_model_pipeline,node_baseline_models,node_decision_threshold toneMint
class node_applicant_schema,node_config toneRose
class node_user toneIndigo
```

## Components

### Dashboard

- [Streamlit dashboard](https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/streamlit_app.py): `app/frontend/streamlit_app.py`
- [Applicant prediction](https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/views/prediction_view.py): `app/frontend/views/prediction_view.py`
- [Model evaluation](https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/views/evaluation_view.py): `app/frontend/views/evaluation_view.py`
- [Global explainability](https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/views/explainability_view.py): `app/frontend/views/explainability_view.py`
- [Batch scoring](https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/views/batch_view.py): `app/frontend/views/batch_view.py`
- [API client](https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/api_client.py): `app/frontend/api_client.py`
- [Dashboard styling](https://github.com/dheerajrai-dev/credilens/blob/main/app/frontend/styles.py): `app/frontend/styles.py`

### API Serving

- [FastAPI service](https://github.com/dheerajrai-dev/credilens/blob/main/app/api/main.py): `app/api/main.py`
- [Prediction routes](https://github.com/dheerajrai-dev/credilens/blob/main/app/api/routes/prediction.py): `app/api/routes/prediction.py`
- [Service dependency](https://github.com/dheerajrai-dev/credilens/blob/main/app/api/dependencies.py): `app/api/dependencies.py`
- [Model startup](https://github.com/dheerajrai-dev/credilens/blob/main/app/api/lifespan.py): `app/api/lifespan.py`

### Risk Inference

- [Inference engine](https://github.com/dheerajrai-dev/credilens/blob/main/app/services/prediction_service.py): `app/services/prediction_service.py`
- [Calibrated model](https://github.com/dheerajrai-dev/credilens/blob/main/models/Credit_risk_model.pkl): `models/Credit_risk_model.pkl`
- [Baseline models](https://github.com/dheerajrai-dev/credilens/blob/main/models/baselines.joblib): `models/baselines.joblib`
- [Decision threshold](https://github.com/dheerajrai-dev/credilens/blob/main/models/best_threshold.pkl): `models/best_threshold.pkl`

### Data Contracts

- [Applicant schema](https://github.com/dheerajrai-dev/credilens/blob/main/app/schemas/credit.py): `app/schemas/credit.py`
- [Runtime configuration](https://github.com/dheerajrai-dev/credilens/blob/main/app/core/config.py): `app/core/config.py`

### Other components

- **Credit analyst**

## Connections

- Credit analyst → Streamlit dashboard: uses (evidence: `README.md`)
- Streamlit dashboard → Applicant prediction: dispatches (evidence: `app/frontend/streamlit_app.py`)
- Streamlit dashboard → Model evaluation: dispatches (evidence: `app/frontend/streamlit_app.py`)
- Streamlit dashboard → Global explainability: dispatches (evidence: `app/frontend/streamlit_app.py`)
- Streamlit dashboard → Batch scoring: dispatches (evidence: `app/frontend/streamlit_app.py`)
- Streamlit dashboard → API client: creates (evidence: `app/frontend/streamlit_app.py`)
- Streamlit dashboard → Dashboard styling: applies (evidence: `app/frontend/streamlit_app.py`)
- Applicant prediction → API client: requests predictions (evidence: `app/frontend/views/prediction_view.py`)
- Model evaluation → API client: requests evaluation (evidence: `app/frontend/views/evaluation_view.py`)
- Batch scoring → API client: requests scoring
- API client → FastAPI service: calls over HTTP (evidence: `app/frontend/api_client.py`)
- API client → Inference engine: falls back in-process (evidence: `app/frontend/api_client.py`)
- API client → Applicant schema: validates input (evidence: `app/frontend/api_client.py`)
- API client → Runtime configuration: reads host and port (evidence: `app/frontend/api_client.py`)
- FastAPI service → Prediction routes: registers routes
- Prediction routes → Service dependency: resolves service (evidence: `app/api/routes/prediction.py`)
- Service dependency → Inference engine: gets instance (evidence: `app/api/dependencies.py`)
- Prediction routes → Inference engine: calls inference (evidence: `app/api/routes/prediction.py`)
- Prediction routes → Applicant schema: validates and returns (evidence: `app/api/routes/prediction.py`)
- Model startup → Inference engine: initializes (evidence: `app/api/lifespan.py`)
- Inference engine → Calibrated model: loads and scores (evidence: `README.md`)
- Inference engine → Baseline models: loads for comparison (evidence: `README.md`)
- Inference engine → Decision threshold: loads decision cutoff (evidence: `README.md`)
- Inference engine → Applicant schema: returns typed results (evidence: `app/api/routes/prediction.py`)
