# manishkumarpatel13/loan-eligibility architecture

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

- Interactive diagram: https://gitdiagram.com/manishkumarpatel13/loan-eligibility
- Repository: https://github.com/manishkumarpatel13/loan-eligibility

## Overview

##### Main Components to Identify
- API / Frontend Layer: Files such as app.py and api.py (and their copies inside the hacktu directory) indicate entry points into the application. This layer likely exposes RESTful endpoints for receiving loan application data.
- Business Logic / Controller: The presence of architecture.py and handler.py (inside hacktu) suggests a mediation layer that governs the data workflow and execution of business rules.
- Data Storage / Database: SQL scripts (user_input.sql found in multiple locations) and database-specific directories (e.g., hacktu/database) indicate that there’s an underlying database system used for persisting user input or loan application data. Also, files like fetch_inputs_from_db.py and generate_user_input_json.py further underscore database interactions.
- Deployment / Containerization: The hacktu directory contains a Dockerfile and build scripts (build_mar.ps1 and build_mar.sh), which hint at containerized deployment and packaging (possibly for model serving via a model archive).

##### Relationships and Interactions
- User (client) submits loan application data which is first captured by the API (via app.py/api.py).
- The API routes the data to controller or handler modules (architecture.py or handler.py) that orchestrate the request.
- These components then interact with the Database – either fetching additional inputs (via fetch_inputs_from_db.py) or writing data persisted in SQL databases.
- Before prediction, the raw input data is transformed using preprocessor components and label encoders.
- The transformed data is fed to the ML model (loaded via load_and_use_model.py or model.py) which produces a loan eligibility decision.
- The inference results flow back through the system (controller/API) to be presented to the user.
- The Dockerfile alongside build scripts allow containerization of the complete runtime environment, ensuring deployment consistency.

##### Architectural Patterns & Design Principles
- Layered architecture: The project is divided in clear layers (input/API -> business logic -> data processing -> model inference -> database).
- Modularity: Separation of concerns is emphasized with distinct scripts for data fetching, model handling, and API endpoints. This modular design facilitates easier extension and maintenance.
- Containerization and reproducible builds: With Docker and build scripts, the project is designed to be easily deployed across different environments.
- Experimentation and production parity: Having both Jupyter notebooks and production scripts (train.py, model.py) indicates a workflow that moves from experimental phases to production-ready deployments.

##### Final Visuals and Notations
- That each component has a clear label (e.g., “API Layer”, “ML Inference”, “Database”).
- Optionally, include annotations such as “Containerized deployment” near the Dockerfile component.

## Diagram (Mermaid)

```mermaid
graph TD
    Client("Client/User"):::client

    subgraph "API/Frontend"
        APIRoot_app("app.py (Root)"):::api
        APIRoot_api("api.py (Root)"):::api
        APIHacktu_app("hacktu/app.py"):::api
        APIHacktu_api("hacktu/api.py"):::api
    end

    subgraph "Business Logic"
        BLRoot_arch("architecture.py (Root)"):::logic
        BLHacktu_arch("hacktu/architecture.py"):::logic
        BLHacktu_handler("hacktu/handler.py"):::logic
    end

    subgraph "ML Pipeline"
        subgraph "Model Code & Training"
            MLC_R_model("model.py (Root)"):::ml
            MLC_R_train("train.py (Root)"):::ml
            MLC_R_load("load_and_use_model.py (Root)"):::ml
            MLC_H_model("hacktu/model.py"):::ml
            MLC_H_train("hacktu/train.py"):::ml
            MLC_H_load("hacktu/load_and_use_model.py"):::ml
        end
        subgraph "Preprocessing & Artifacts"
            MLP_R_preproc("loan_approval_preprocessor.joblib (Root)"):::ml
            MLP_R_preproc2("preprocessor.joblib (Root)"):::ml
            MLP_R_label("label_encoders.joblib (Root)"):::ml
            MLP_R_artif1("loan_approval_model.pth (Root)"):::ml
            MLP_R_artif2("model.joblib (Root)"):::ml
            MLP_R_artif3("model.mar (Root)"):::ml
            MLP_R_artif4("model.pt (Root)"):::ml
            MLP_H_preproc("hacktu/loan_approval_preprocessor.joblib"):::ml
            MLP_H_preproc2("hacktu/preprocessor.joblib"):::ml
            MLP_H_label("hacktu/label_encoders.joblib"):::ml
            MLP_H_artif1("hacktu/loan_approval_model.pth"):::ml
            MLP_H_artif2("hacktu/model.joblib"):::ml
            MLP_H_artif3("hacktu/model.mar"):::ml
            MLP_H_artif4("hacktu/model.pt"):::ml
        end
        subgraph "Experimentation Notebooks"
            MLN_R_model("model.ipynb (Root)"):::ml
            MLN_R_neural("neural_classification.ipynb (Root)"):::ml
            MLN_H_model("hacktu/model.ipynb"):::ml
            MLN_H_neural("hacktu/neural_classification.ipynb"):::ml
        end
    end

    subgraph "Data Storage / Database"
        DB_R_fetch("fetch_inputs_from_db.py (Root)"):::db
        DB_R_generate("generate_user_input_json.py (Root)"):::db
        DB_R_sql("user_input.sql (Root)"):::db
        DB_H_fetch("hacktu/fetch_inputs_from_db.py"):::db
        DB_H_generate("hacktu/generate_user_input_json.py"):::db
        DB_H_sql1("hacktu/database/user_input.sql"):::db
        DB_H_sql2("hacktu/database/fetch_inputs_from_db.py"):::db
        DB_H_sql3("hacktu/database/generate_user_input_json.py"):::db
    end

    subgraph "Deployment / Containerization"
        DEP_Docker("Dockerfile (hacktu)"):::dep
        DEP_build_ps1("build_mar.ps1 (hacktu)"):::dep
        DEP_build_sh("build_mar.sh (hacktu)"):::dep
    end

    %% Data flow connections
    Client -->|"submitLoanApplication"| APIRoot_app
    Client -->|"submitLoanApplication"| APIHacktu_app

    APIRoot_app -->|"routesRequest"| BLRoot_arch
    APIHacktu_app -->|"routesRequest"| BLHacktu_arch

    %% ML Pipeline: Preprocessing -> Model Inference -> Return Prediction (Root)
    BLRoot_arch -->|"preprocessData"| MLP_R_preproc
    MLP_R_preproc -->|"modelInference"| MLC_R_model
    MLC_R_model -->|"sendPrediction"| BLRoot_arch

    %% ML Pipeline: Preprocessing -> Model Inference -> Return Prediction (Hacktu)
    BLHacktu_arch -->|"preprocessData"| MLP_H_preproc2
    MLP_H_preproc2 -->|"modelInference"| MLC_H_model
    MLC_H_model -->|"sendPrediction"| BLHacktu_arch

    %% Database interactions
    BLRoot_arch -->|"dbInteraction"| DB_R_fetch
    BLHacktu_arch -->|"dbInteraction"| DB_H_fetch
    DB_R_fetch -->|"returnData"| BLRoot_arch
    DB_H_fetch -->|"returnData"| BLHacktu_arch

    %% Response flow back to API layer
    BLRoot_arch -->|"response"| APIRoot_app
    BLHacktu_arch -->|"response"| APIHacktu_app

    %% Deployment configuration
    BLRoot_arch -->|"containerConfig"| DEP_Docker
    BLHacktu_arch -->|"containerConfig"| DEP_Docker

    %% Experimentation trigger
    BLRoot_arch -->|"evalExperiment"| MLN_R_model
    BLHacktu_arch -->|"evalExperiment"| MLN_H_model

    %% Click Events for API / Frontend Layer
    click APIRoot_app "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/app.py"
    click APIRoot_api "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/api.py"
    click APIHacktu_app "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/app.py"
    click APIHacktu_api "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/api.py"

    %% Click Events for Business Logic / Controller
    click BLRoot_arch "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/architecture.py"
    click BLHacktu_arch "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/architecture.py"
    click BLHacktu_handler "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/handler.py"

    %% Click Events for ML Model & Inference Pipeline - Model Code & Training
    click MLC_R_model "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/model.py"
    click MLC_R_train "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/train.py"
    click MLC_R_load "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/load_and_use_model.py"
    click MLC_H_model "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/model.py"
    click MLC_H_train "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/train.py"
    click MLC_H_load "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/load_and_use_model.py"

    %% Click Events for ML Model & Inference Pipeline - Preprocessing & Artifacts (Root)
    click MLP_R_preproc "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/loan_approval_preprocessor.joblib"
    click MLP_R_preproc2 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/preprocessor.joblib"
    click MLP_R_label "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/label_encoders.joblib"
    click MLP_R_artif1 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/loan_approval_model.pth"
    click MLP_R_artif2 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/model.joblib"
    click MLP_R_artif3 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/model.mar"
    click MLP_R_artif4 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/model.pt"

    %% Click Events for ML Model & Inference Pipeline - Preprocessing & Artifacts (Hacktu)
    click MLP_H_preproc "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/loan_approval_preprocessor.joblib"
    click MLP_H_preproc2 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/preprocessor.joblib"
    click MLP_H_label "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/label_encoders.joblib"
    click MLP_H_artif1 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/loan_approval_model.pth"
    click MLP_H_artif2 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/model.joblib"
    click MLP_H_artif3 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/model.mar"
    click MLP_H_artif4 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/model.pt"

    %% Click Events for ML Model & Inference Pipeline - Experimentation Notebooks
    click MLN_R_model "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/model.ipynb"
    click MLN_R_neural "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/neural_classification.ipynb"
    click MLN_H_model "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/model.ipynb"
    click MLN_H_neural "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/neural_classification.ipynb"

    %% Click Events for Data Storage / Database
    click DB_R_fetch "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/fetch_inputs_from_db.py"
    click DB_R_generate "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/generate_user_input_json.py"
    click DB_R_sql "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/user_input.sql"
    click DB_H_fetch "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/fetch_inputs_from_db.py"
    click DB_H_generate "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/generate_user_input_json.py"
    click DB_H_sql1 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/database/user_input.sql"
    click DB_H_sql2 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/database/fetch_inputs_from_db.py"
    click DB_H_sql3 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/database/generate_user_input_json.py"

    %% Click Events for Deployment / Containerization
    click DEP_Docker "https://github.com/manishkumarpatel13/loan-eligibility/tree/main/hacktu/Dockerfile"
    click DEP_build_ps1 "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/build_mar.ps1"
    click DEP_build_sh "https://github.com/manishkumarpatel13/loan-eligibility/blob/main/hacktu/build_mar.sh"

    %% Styles
    classDef client fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef api fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef logic fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef ml fill:#f9c5d1,stroke:#c0392b,stroke-width:2px;
    classDef db fill:#d5f5e3,stroke:#239b56,stroke-width:2px;
    classDef dep fill:#f5b7b1,stroke:#a93226,stroke-width:2px;
```
