# regu7/loan_defaults_prediction architecture

> Architecture diagram of the GitHub repository regu7/loan_defaults_prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/regu7/loan_defaults_prediction
- Repository: https://github.com/regu7/loan_defaults_prediction

## Overview

##### Project Type and Purpose
- The project is a machine learning (ML) application with an end-to-end predictive modeling pipeline. Its purpose is to predict whether a loan applicant will default using historical loan application data.
- The README outlines that it is designed for practical decision-making at LendingClub, involving both training and prediction phases. It also details steps to run training via command-line scripts and deploy a streamlit app, with an option for a dockerized deployment.

##### File Structure Insights
- Top-level files like app.py, Dockerfile, setup.py, and deploy/requirements.txt indicate the project supports both local and containerized deployments.
- The project is structured with a clear separation of concerns:
a. The ML pipeline is split across directories:
- "src/components": Contains modules for data ingestion, transformation, and model training.
- "src/pipeline": Contains pipeline scripts such as train_pipeline.py (for model training) and predict_pipeline.py (for model inference).
b. "artifacts" directory stores model outputs (model.pkl, preprocessor.pkl) and any related metadata (cat_unique_values.json).
c. Notebooks provide exploratory analysis and prototyping.
d. AWS directory suggests potential integration for deployment or model hosting on a cloud platform.
- Additional files include logging, exception handling (src/logger.py, src/exception.py), and utilities (src/utils.py) which support maintainability and debugging.

##### Architectural Components to Highlight
a. Data Ingestion & Transformation:
- Data ingestion component (src/components/data_ingestion.py) that gathers and prepares raw data.
- Follow it with the data transformation module (src/components/data_transformation.py), which cleans and processes the data.

b. Model Training:
- Output artifacts (stored in the artifacts folder like model.pkl and preprocessor.pkl) produced as a result of training.

c. Prediction Pipeline:
- App.py entry point which runs a Streamlit web app interface to allow users to input data and retrieve prediction results.

d. Deployment & Integration:
- Docker container (Dockerfile) used for containerizing the application.
- Integration with external deployment environments (via the deploy directory and AWS key files from the aws directory).
- If desired, add note for dependency management (deploy/requirements.txt) and the setup file (setup.py) for package-based installations.

##### Architectural Patterns and Design Principles
- Modular design: the separation into components and pipelines aligns with principles of decoupling and reusability.
- Clear separation of training and prediction logic.
- Streams from the Streamlit app (app.py) to the prediction pipeline to illustrate the real-time inference path.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% ML Pipeline Subgraph
    subgraph "ML Pipeline"
        direction TB
        DI("Data Ingestion Module"):::module
        DT("Data Transformation Module"):::module
        MT("Model Trainer"):::module
        TP("Training Pipeline Orchestration"):::module
        AR("Artifacts/Storage"):::artifact
        DI --> DT
        DT --> MT
        MT --> TP
        TP --> AR
    end

    %% Real-Time Prediction Subgraph
    subgraph "Real-Time Prediction"
        direction TB
        PP("Prediction Pipeline"):::module
        FE("Streamlit App Interface"):::frontend
        FE --> PP
        AR --> PP
    end

    %% Deployment & Integration Subgraph
    subgraph "Deployment & Integration"
        direction TB
        DC("Docker Container"):::deployment
        DS("Deployment Scripts"):::deployment
        CI("Cloud Infrastructure"):::deployment
        DC --> DS
        DS --> CI
    end

    %% Utilities & Support Subgraph
    subgraph "Utilities & Support"
        direction TB
        LOG("Logging"):::utility
        EXC("Exception Handling"):::utility
        UTIL("Additional Utilities"):::utility
    end

    %% Data Flow - Additional Arrows
    AR -->|"model_info"| PP

    %% Docker Container encapsulates ML Pipeline and Frontend
    DC -->|"contains"| DI
    DC -->|"contains"| FE

    %% Styles
    classDef module fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef artifact fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef frontend fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef deployment fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef utility fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;

    %% Click Events
    click DI "https://github.com/regu7/loan_defaults_prediction/blob/main/src/components/data_ingestion.py"
    click DT "https://github.com/regu7/loan_defaults_prediction/blob/main/src/components/data_transformation.py"
    click MT "https://github.com/regu7/loan_defaults_prediction/blob/main/src/components/model_trainer.py"
    click TP "https://github.com/regu7/loan_defaults_prediction/blob/main/src/pipeline/train_pipeline.py"
    click PP "https://github.com/regu7/loan_defaults_prediction/blob/main/src/pipeline/predict_pipeline.py"
    click AR "https://github.com/regu7/loan_defaults_prediction/tree/main/artifacts"
    click FE "https://github.com/regu7/loan_defaults_prediction/blob/main/app.py"
    click DC "https://github.com/regu7/loan_defaults_prediction/tree/main/Dockerfile"
    click DS "https://github.com/regu7/loan_defaults_prediction/blob/main/deploy/requirements.txt"
    click CI "https://github.com/regu7/loan_defaults_prediction/tree/main/aws"
    click LOG "https://github.com/regu7/loan_defaults_prediction/blob/main/src/logger.py"
    click EXC "https://github.com/regu7/loan_defaults_prediction/blob/main/src/exception.py"
    click UTIL "https://github.com/regu7/loan_defaults_prediction/blob/main/src/utils.py"
```
