# sarthakg004/fraud_detection architecture

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

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

## Overview

##### Project Type and Purpose
- This is a data-science / machine-learning pipeline project (“Fraud-Detection”) for semi-supervised fraud detection on banking transactions.
- It uses DVC for data and pipeline versioning, MLflow for experiment tracking, and a standard Python project structure under src/.

##### File Structure
- Top-level:
- dvc.yaml, dvc.lock, .dvc/: pipeline configuration and cache
- data/raw/, data/processed/: versioned datasets
- src/: code modules
- notebooks/: exploratory and prototyping analyses
- mlruns/: MLflow experiment artifacts
- models/: final model artifacts (via DVC or manual commits)
- docs/: Sphinx documentation
- reports/: figures and generated reports
- Makefile, tox.ini, requirements.txt: build, test, and dependency management
- src/ substructure:
- src/data/preprocessing.py
- src/features/feature_engineering.py
- src/models/train_model.py, predict_model.py
- Presence of DVC and MLflow indicates an orchestrated pipeline pattern.

##### README for Additional Insights
- Confirms purpose: “Fraud detection model for bank transactions”
- Semi-supervised learning suggests an unlabeled data ingestion step and label inference stage.

a. Data Layer
- External Data Source → data/raw/ (DVC tracked)
- data/raw/ → Preprocessing (src/data/preprocessing.py) → data/processed/
b. Feature Engineering
- data/processed/ → Feature Engineering (src/features/feature_engineering.py) → feature store or intermediate artifacts
c. Model Training & Evaluation
- Features → train_model.py → MLflow (mlruns/) logs parameters, metrics, artifacts
- DVC stage in dvc.yaml for `train`
d. Model Registry & Artifacts
- MLflow model registry or local folder under models/
- Conda/python_env.yaml, requirements.txt captured in MLflow artifact store
e. Prediction Service
- predict_model.py module (could be wrapped behind API or batch job)
- Model → inference on new raw data
f. Experiment Tracking & Orchestration
- DVC orchestrator (dvc.yaml) governs pipeline stages: preprocess → featurize → train → evaluate → deploy
- MLflow for run tracking, logging, and tag management
g. Documentation & Reporting
- docs/ for Sphinx; reports/ for generated figures and write-ups

##### Architectural Patterns & Design Principles
- Modular pipeline stages, each in its own script and DVC stage
- Separation of concerns: data ingestion, feature engineering, training, inference
- Single source of truth for versioned data (DVC) and metrics/artifacts (MLflow)
- Reproducibility: environment definition in conda/python_env.yaml, pinned dependencies in requirements.txt

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Layer
    ExternalData(("External Data Source")):::data
    RawData["data/raw/ (CSV)"]:::data
    ProcessedData["data/processed/ (Parquet)"]:::data

    %% Processing
    Preprocessing["Preprocessing"]:::processing
    FeatureEng["Feature Engineering"]:::processing
    FeatureData["Features (Parquet)"]:::data

    %% Modeling
    Train["Model Training & Evaluation"]:::modeling
    ModelRegistry["Model Registry & Artifacts"]:::modeling
    Inference["Prediction Service"]:::modeling

    %% Tracking & Orchestration
    subgraph "DVC Pipeline" 
        direction TB
        Params["params.yaml"]:::tracking
        DvcYaml["dvc.yaml"]:::tracking
        Preprocessing --> FeatureEng --> Train
    end
    DVC[".dvc/ (DVC Cache & Config)"]:::tracking
    MLflow["MLflow Server & Runs"]:::tracking

    %% Documentation & Reporting
    Docs["docs/ (Sphinx)"]:::report
    Reports["reports/ (Figures)"]:::report

    %% Notebooks
    subgraph "Notebooks for Prototyping"
        direction TB
        DataNB["data_preprocessing.ipynb"]:::report
        FEATNB["feature_engineering.ipynb"]:::report
        MODELNB["model_building.ipynb"]:::report
    end

    %% Environment
    Env["requirements.txt / conda.yaml"]:::tracking

    %% Connections
    ExternalData --> RawData --> Preprocessing --> ProcessedData
    ProcessedData --> FeatureEng --> FeatureData --> Train --> ModelRegistry
    ModelRegistry --> Inference -->|"New Raw Data"| RawData
    Train --> MLflow
    Inference --> MLflow
    DvcYaml --> DVC
    Params --> DVC
    DVC --> Preprocessing
    MLflow --> Train
    MLflow --> Inference
    Train --> Reports
    MODELNB -->|prototypes| Train
    FEATNB -->|prototypes| FeatureEng
    DataNB -->|prototypes| Preprocessing
    Docs -->|documents| Preprocessing
    Docs -->|documents| FeatureEng
    Docs -->|documents| Train
    Docs -->|documents| Inference

    %% Click Events
    click RawData "https://github.com/sarthakg004/fraud_detection/tree/master/data/raw/"
    click ProcessedData "https://github.com/sarthakg004/fraud_detection/tree/master/data/processed/"
    click Preprocessing "https://github.com/sarthakg004/fraud_detection/blob/master/src/data/preprocessing.py"
    click FeatureEng "https://github.com/sarthakg004/fraud_detection/blob/master/src/features/feature_engineering.py"
    click Train "https://github.com/sarthakg004/fraud_detection/blob/master/src/models/train_model.py"
    click Inference "https://github.com/sarthakg004/fraud_detection/blob/master/src/models/predict_model.py"
    click DvcYaml "https://github.com/sarthakg004/fraud_detection/blob/master/dvc.yaml"
    click DVC "https://github.com/sarthakg004/fraud_detection/tree/master/.dvc/"
    click Params "https://github.com/sarthakg004/fraud_detection/blob/master/params.yaml"
    click MLflow "https://github.com/sarthakg004/fraud_detection/tree/master/mlruns/"
    click ModelRegistry "https://github.com/sarthakg004/fraud_detection/tree/master/models/"
    click Docs "https://github.com/sarthakg004/fraud_detection/tree/master/docs/"
    click Reports "https://github.com/sarthakg004/fraud_detection/tree/master/reports/"
    click DataNB "https://github.com/sarthakg004/fraud_detection/blob/master/notebooks/data_preprocessing.ipynb"
    click FEATNB "https://github.com/sarthakg004/fraud_detection/blob/master/notebooks/feature_engineering.ipynb"
    click MODELNB "https://github.com/sarthakg004/fraud_detection/blob/master/notebooks/model_building.ipynb"
    click Env "https://github.com/sarthakg004/fraud_detection/blob/master/requirements.txt"

    %% Styles
    classDef data fill:#AED6F1,stroke:#21618C,color:#1B4F72
    classDef processing fill:#F5CBA7,stroke:#A04000,color:#78281F
    classDef modeling fill:#ABEBC6,stroke:#196F3D,color:#145A32
    classDef tracking fill:#D7BDE2,stroke:#6C3483,color:#4A235A
    classDef report fill:#D5D8DC,stroke:#626567,color:#1B2631
```
