# suvkp/fraud_detection architecture

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

- Interactive diagram: https://gitdiagram.com/suvkp/fraud_detection
- Repository: https://github.com/suvkp/fraud_detection

## Overview

##### Main Components
- Data Collection & Ingestion:
- Represented by the modules in src: data_loader.py for loading input data.
- Data Preprocessing:
- Handled by src/data_preprocessing.py, which cleans and prepares the data.
- Exploratory Data Analysis (EDA):
- Notebooks in the notebook directory (01_eda.ipynb) and src/eda.py provide analysis and insights.
- Feature Engineering / Feature Selection:
- The src/feature_selection.py module highlights data/features chosen for model training.
- Model Training:
- Managed through src/model_training.py and pipeline/train_pipeline.py. This part includes training models using the engineered features.
- Model Evaluation:
- Implemented in src/model_evaluation.py to assess model performance and benchmark different approaches.
- Model Inference (Deployment):
- Handled by src/model_inference.py and pipeline/inference_pipeline.py for running predictions on unseen data.
- Utility Functions:
- Supporting functions in src/util.py that may be used across the various modules.
- Entry Point:
- The run_pipeline.py script serves as the primary trigger for executing training or inference pipelines.

##### Relationships and Interactions
- Data flows from loading (data_loader.py) to preprocessing (data_preprocessing.py).
- Preprocessed data is then explored (EDA notebooks and src/eda.py) and refined via feature selection.
- The refined dataset is split into two pipelines:
- Training pipeline: where the model is trained using src/model_training.py and pipeline/train_pipeline.py.
- Inference pipeline: where the trained model is used for prediction via src/model_inference.py and pipeline/inference_pipeline.py.
- Model evaluation (in src/model_evaluation.py) acts as a checkpoint that feeds back into training for potential improvements.
- Utility functions (in src/util.py) support all these stages.

##### Architectural Patterns and Design Principles
- Modular separation of concerns: Each stage of the machine learning workflow is encapsulated in its own file/module.
- Pipeline-based design: Separate directories for training (train_pipeline) and inference (inference_pipeline) enforce clarity in workflow execution.
- Use of notebooks for early-stage EDA ensures that exploratory analysis is not mixed with production pipelines.
- The design is linear in terms of data flow yet modular enough to allow for independent unit testing and iterative improvements.

##### Key Technologies and Tools
- Python (as evident from .py files) is the core language.
- Jupyter Notebooks for EDA and early-stage development.
- Machine Learning frameworks and libraries (implied by the context) for model training, evaluation, and inference.
- Version control (given the .gitignore), indicating a mature development process.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point
    entry("Entry Point (run_pipeline.py)"):::entry

    %% Data Processing Subgraph
    subgraph "Data Processing"
        dp1["Data Loader"]:::processing
        dp2["Data Preprocessing"]:::processing
        eda1["EDA Notebook"]:::processing
        eda2["EDA Script"]:::processing
        fs["Feature Selection"]:::processing
    end

    %% Modeling Pipeline Subgraph
    subgraph "Modeling Pipeline"
        %% Training Pipeline Subgroup
        subgraph "Training Pipeline"
            mt1["Model Training (script)"]:::modeling
            mt2["Train Pipeline"]:::modeling
        end
        mt["Model Training Combined"]:::modeling
        me["Model Evaluation"]:::modeling
        %% Inference Pipeline Subgroup
        subgraph "Inference Pipeline"
            mi1["Model Inference (script)"]:::modeling
            mi2["Inference Pipeline"]:::modeling
        end
        mi["Model Inference Combined"]:::modeling
    end

    %% Utility Functions Node
    util["Utility Functions"]:::utility

    %% Data Flow Connections
    entry -->|"triggers"| dp1
    dp1 -->|"loads data"| dp2
    dp2 -->|"prepares"| eda1
    dp2 -->|"prepares"| eda2
    eda1 -->|"provides insights"| fs
    eda2 -->|"provides insights"| fs
    fs -->|"selects features for"| mt1
    fs -->|"selects features for"| mi1
    mt1 -->|"combined with"| mt
    mt2 -->|"combined with"| mt
    mt -->|"evaluated by"| me
    me -->|"feedback improves"| mt
    mi1 -->|"combined with"| mi
    mi2 -->|"combined with"| mi

    %% Utility dotted connections (supporting functions)
    dp1 -.->|"utilized"| util
    dp2 -.->|"utilized"| util
    eda1 -.->|"utilized"| util
    eda2 -.->|"utilized"| util
    fs -.->|"utilized"| util
    mt -.->|"utilized"| util
    me -.->|"utilized"| util
    mi -.->|"utilized"| util

    %% Click Events
    click entry "https://github.com/suvkp/fraud_detection/blob/main/run_pipeline.py"
    click dp1 "https://github.com/suvkp/fraud_detection/blob/main/src/data_loader.py"
    click dp2 "https://github.com/suvkp/fraud_detection/blob/main/src/data_preprocessing.py"
    click eda1 "https://github.com/suvkp/fraud_detection/blob/main/notebook/01_eda.ipynb"
    click eda2 "https://github.com/suvkp/fraud_detection/blob/main/src/eda.py"
    click fs "https://github.com/suvkp/fraud_detection/blob/main/src/feature_selection.py"
    click mt1 "https://github.com/suvkp/fraud_detection/blob/main/src/model_training.py"
    click mt2 "https://github.com/suvkp/fraud_detection/blob/main/pipeline/train_pipeline.py"
    click me "https://github.com/suvkp/fraud_detection/blob/main/src/model_evaluation.py"
    click mi1 "https://github.com/suvkp/fraud_detection/blob/main/src/model_inference.py"
    click mi2 "https://github.com/suvkp/fraud_detection/blob/main/pipeline/inference_pipeline.py"
    click util "https://github.com/suvkp/fraud_detection/blob/main/src/util.py"

    %% Styles
    classDef entry fill:#a2d2ff,stroke:#333,stroke-width:2px;
    classDef processing fill:#d0f0c0,stroke:#333,stroke-width:2px;
    classDef modeling fill:#ffc9c9,stroke:#333,stroke-width:2px;
    classDef utility fill:#f9f7d9,stroke:#333,stroke-width:2px;
```
