# swaraj-6/credit_card_default_prediction architecture

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

- Interactive diagram: https://gitdiagram.com/swaraj-6/credit_card_default_prediction
- Repository: https://github.com/swaraj-6/credit_card_default_prediction

## Overview

##### Project Type and Purpose
- This is a full-stack machine-learning web application for predicting credit-card defaults.
- Frontend: simple Flask HTML forms (templates/form.html, templates/result.html).
- Backend: Flask app (application.py) invoking a prediction pipeline (src/pipeline/prediction_pipeline.py).
- ML components: data-ingestion, transformation, model training modules under src/components, producing artifacts (model.pkl, preprocessor.pkl).
- Deployment: configured for AWS Elastic Beanstalk (.ebextensions) and currently hosted on Render.

##### Main Components
a. User Interface (Frontend)
- Browser → HTML form (form.html)
- Result page (result.html)
b. Flask Application (Backend Controller)
- application.py: routes “/” for form, “/predict” for submissions
- src/logger.py & src/exception.py for logging and error handling
c. Prediction Pipeline
- src/pipeline/prediction_pipeline.py loads artifacts, applies preprocessing, returns prediction
- src/utils.py supports loading and I/O
d. Training Pipeline (Offline/Batch)
- src/pipeline/training_pipeline.py orchestrates:
- data_ingestion.py → loads UCI dataset
- data_transformation.py → handles encoding, scaling
- model_training.py → trains model, persists model.pkl & preprocessor.pkl
e. Artifacts Store
- artifacts/: raw.csv, train.csv, test.csv, preprocessor.pkl, model.pkl
f. Configuration & Deployment
- requirements.txt, setup.py
- .ebextensions/python.config for AWS EB

##### Relationships and Data Flow
- User submits form → Flask route calls Prediction Pipeline → Pipeline fetches preprocessor & model from artifacts → returns default/no-default → Flask renders result page.
- Training is invoked separately (CLI or scheduled job): raw.csv → data_ingestion → data_transformation → model_training → write updated artifacts.
- Logging & exception modules wrap all interactions.

##### Architectural Patterns & Principles
- Layered separation:
- Presentation (templates + Flask routes)
- Application (prediction_pipeline & training_pipeline orchestrators)
- Domain/Components (data_ingestion, transformation, model_training)
- Infrastructure (artifact persistence, configuration)
- Single-responsibility modules (each component handles only one pipeline stage).
- Reusability: utils.py for shared I/O, logger/exception for cross-cutting concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation/UI"
        direction TB
        UB["User Browser"]:::blue
        Form["HTML Form"]:::blue
        Result["Result Page"]:::blue
    end

    %% Backend Controller Layer
    subgraph "Backend Controller"
        direction TB
        FA["Flask App"]:::green
        LOG["Logger"]:::gray
        EXC["Exception Handler"]:::gray
    end

    %% Prediction Pipeline
    subgraph "Prediction Pipeline"
        direction TB
        PP["Pipeline Orchestrator"]:::orange
        UTIL["Utilities"]:::orange
    end

    %% Training Pipeline
    subgraph "Training Pipeline"
        direction TB
        TP["Training Orchestrator"]:::orange
        DI["Data Ingestion"]:::orange
        DT["Data Transformation"]:::orange
        MT["Model Training"]:::orange
    end

    %% Data and Artifacts
    subgraph "Data / Artifacts"
        direction TB
        DS["Data Source (raw.csv)"]:::gray
        AS["Artifacts Store"]:::gray
    end

    %% Deployment & Config
    subgraph "Deployment & Config"
        direction TB
        EB["AWS EB Config"]:::gray
        RE["Render.com"]:::gray
        REQ["requirements.txt"]:::gray
        SETUP["setup.py"]:::gray
    end

    %% Relationships
    UB -->|"GET /"| FA
    FA -->|"renders HTML"| Form
    UB -->|"POST /predict"| FA
    FA -->|"Form Data"| PP
    PP -->|"uses Utils"| UTIL
    PP -->|"loads artifacts"| AS
    AS -->|"serves model.pkl & preprocessor.pkl"| PP
    PP -->|"Prediction"| FA
    FA -->|"renders HTML"| Result
    Result --> UB

    %% Offline Training Flow
    CLI["Scheduled Job"]:::gray
    CLI -->|"trigger"| TP
    TP -->|"ingest raw data"| DI
    DI -->|"produce train/test"| DT
    DT -->|"produce features"| MT
    MT -->|"write artifacts"| AS

    %% Logging & Exception
    FA --> LOG
    FA --> EXC
    PP --> LOG
    TP --> LOG

    %% Deployment Links
    FA ---> EB
    FA ---> RE
    FA ---> REQ
    FA ---> SETUP

    %% Click Events
    click Form "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/templates/form.html"
    click Result "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/templates/result.html"
    click FA "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/application.py"
    click LOG "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/src/logger.py"
    click EXC "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/src/exception.py"
    click PP "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/src/pipeline/prediction_pipeline.py"
    click UTIL "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/src/utils.py"
    click TP "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/src/pipeline/training_pipeline.py"
    click DI "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/src/components/data_ingestion.py"
    click DT "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/src/components/data_transformation.py"
    click MT "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/src/components/model_training.py"
    click AS "https://github.com/swaraj-6/credit_card_default_prediction/tree/main/artifacts/"
    click EB "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/.ebextensions/python.config"
    click REQ "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/requirements.txt"
    click SETUP "https://github.com/swaraj-6/credit_card_default_prediction/blob/main/setup.py"

    %% Styles
    classDef blue fill:#D0E8FF,stroke:#0366D6,color:#000
    classDef green fill:#DFF7D8,stroke:#228B22,color:#000
    classDef orange fill:#FFE3B8,stroke:#DD8500,color:#000
    classDef gray fill:#F0F0F0,stroke:#888,color:#000
```
