# adityadev-17/fraud-detection architecture

> Architecture diagram of the GitHub repository adityadev-17/fraud-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adityadev-17/fraud-detection
- Repository: https://github.com/adityadev-17/fraud-detection

## Overview

1. **Repository purpose**
   This repo is a small, offline machine-learning project for **fraudulent transaction classification**. Its architecture is centered on a training/analysis workflow that produces a **serialized prediction pipeline** for later reuse.

2. **Primary artifacts**
   There are three meaningful code/assets in the repo:
   - `FraudDetection.ipynb` — the main exploratory and model-development notebook
   - `fraud_detection.py` — a Python script likely used for reusable training or prediction logic
   - `fraud_detection_pipeline.pkl` — a saved scikit-learn pipeline/model artifact

3. **Core subsystem: data preparation and EDA**
   The notebook is the likely place where raw transaction data is loaded and prepared using **Pandas/NumPy**, then explored with **Matplotlib/Seaborn**. This layer handles cleaning, feature inspection, fraud-vs-non-fraud distribution analysis, and correlation/feature-importance exploration.

4. **Core subsystem: imbalanced classification training**
   Fraud detection here is an **imbalanced binary classification** problem. The training workflow likely includes imbalance handling such as class weighting or resampling, then fitting one or more scikit-learn classifiers. The README emphasizes evaluation with precision, recall, F1, ROC-AUC, and confusion matrix, which are the key model-quality gates in this system.

5. **Feature and model boundary**
   The system appears to operate on a tabular transaction dataset with engineered customer/transaction variables plus a fraud label. The architectural boundary is: **raw dataset → feature-prepared matrix → trained classifier/pipeline**. The saved `.pkl` suggests preprocessing and model steps are packaged together rather than kept separate.

6. **Serialized inference artifact**
   `fraud_detection_pipeline.pkl` is the main deployable output. It likely contains a fitted preprocessing + model pipeline so that future transaction records can be scored consistently without redoing training-time logic manually. This is the artifact you would place on the “model serving” side of an architecture diagram.

7. **Script vs notebook separation**
   The notebook is for experimentation, visualization, and model comparison; the `.py` file is the more reusable execution path. Architecturally, this creates a split between:
   - **research/training workspace** in the notebook
   - **repeatable code path** in the Python script
   - **persisted model artifact** in the pickle file

8. **Data flow**
   The main flow is:
   raw transaction dataset → preprocessing/EDA → imbalance handling → train/test split → model training → evaluation → serialization to `fraud_detection_pipeline.pkl`.
   For inference, the flow is:
   new transaction record → same feature preparation/pipeline → fraud/non-fraud prediction.

9. **External dependencies that matter**
   The repo depends on the Python scientific stack: **Pandas**, **NumPy**, **scikit-learn**, and visualization libraries. These dependencies matter architecturally because the project is built as a **local analytical ML pipeline**, not as a service-backed or distributed system.

10. **What is not present**
   There is no visible API layer, database, message queue, dashboard app, or real-time streaming component in the repository. So the current architecture is best understood as a **single-machine ML project** with a trained artifact, not a production fraud-monitoring platform.

11. **Likely diagram boundaries**
   If drawing an architecture diagram, the main boxes are:
   - **Dataset source** outside the repo
   - **Notebook/script training environment**
   - **Model evaluation outputs**
   - **Saved pipeline artifact**
   - Optional future inference consumer that loads the `.pkl`

12. **Overall architectural shape**
   This repo is an **end-to-end supervised learning pipeline** with a strong offline training orientation. Its center of gravity is model development and serialization, with the notebook serving as the analytical engine and the pickle file serving as the reusable prediction boundary.

Main entry points: [`FraudDetection.ipynb`](https://github.com/adityadev-17/fraud-detection/blob/main/FraudDetection.ipynb) (Notebook), [`fraud_detection.py`](https://github.com/adityadev-17/fraud-detection/blob/main/fraud_detection.py) (Training script), [`fraud_detection_pipeline.pkl`](https://github.com/adityadev-17/fraud-detection/blob/main/fraud_detection_pipeline.pkl) (Pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_repo["Repo assets"]
  node_notebook["Notebook"]
  node_script["Training script<br/>python workflow<br/>[fraud_detection.py]"]
  node_pipeline[("Pipeline<br/>serialized artifact")]
end

subgraph group_workflow["ML workflow"]
  node_prep["Prep data<br/>preprocessing"]
  node_eda["EDA<br/>analysis"]
  node_imbalance["Balance data<br/>imbalance handling"]
  node_split["Train split<br/>data split"]
  node_model["Classifier<br/>sklearn model"]
  node_eval["Evaluate<br/>metrics"]
end

node_dataset[("Txn data<br/>external dataset")]
node_consumer["Scoring use<br/>inference consumer"]

node_dataset -->|"load"| node_eda
node_dataset -->|"prepare"| node_prep
node_notebook -->|"explore"| node_eda
node_notebook -->|"develop"| node_prep
node_notebook -->|"tune"| node_imbalance
node_prep -->|"feed"| node_split
node_imbalance -->|"apply"| node_split
node_split -->|"train"| node_model
node_model -->|"measure"| node_eval
node_model -->|"serialize"| node_pipeline
node_script -->|"run"| node_prep
node_script -->|"fit"| node_model
node_script -->|"save"| node_pipeline
node_pipeline -->|"score"| node_consumer

click node_notebook "https://github.com/adityadev-17/fraud-detection/blob/main/FraudDetection.ipynb"
click node_script "https://github.com/adityadev-17/fraud-detection/blob/main/fraud_detection.py"
click node_pipeline "https://github.com/adityadev-17/fraud-detection/blob/main/fraud_detection_pipeline.pkl"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_notebook,node_script,node_pipeline toneBlue
class node_prep,node_eda,node_imbalance,node_split,node_model,node_eval toneAmber
class node_dataset,node_consumer toneNeutral
```

## Components

### Repo assets

Primary tracked artifacts in this repository.

- [Notebook](https://github.com/adityadev-17/fraud-detection/blob/main/FraudDetection.ipynb): analysis notebook · Exploratory training workspace for data inspection, visualization, and model development. · `FraudDetection.ipynb`
- [Training script](https://github.com/adityadev-17/fraud-detection/blob/main/fraud_detection.py): python workflow · Reusable Python path for repeatable preprocessing, training, or scoring logic. · `fraud_detection.py`
- [Pipeline](https://github.com/adityadev-17/fraud-detection/blob/main/fraud_detection_pipeline.pkl): serialized artifact · Saved fitted preprocessing-plus-model pipeline for consistent reuse. · `fraud_detection_pipeline.pkl`

### ML workflow

Offline training and serialization steps for fraud classification.

- **Prep data**: preprocessing · Cleans, encodes, and shapes transaction features into model-ready tabular input.
- **EDA**: analysis · Inspects class balance, distributions, correlations, and feature behavior.
- **Balance data**: imbalance handling · Handles fraud-class skew via weighting or resampling before fitting.
- **Train split**: data split · Partitions prepared data into train and test sets for validation.
- **Classifier**: sklearn model · Fits the fraud-vs-non-fraud predictive model on tabular features.
- **Evaluate**: metrics · Checks precision, recall, F1, ROC-AUC, and confusion matrix performance.

### Other components

- **Txn data**: external dataset · Raw transaction records and fraud labels consumed by the project.
- **Scoring use**: inference consumer · Future caller that loads the saved pipeline to score new transactions.

## Connections

- Txn data → EDA: load · Raw data is first inspected and summarized.
- Txn data → Prep data: prepare · Transaction fields are transformed into model inputs.
- Notebook → EDA: explore · Notebook drives visualization and exploratory analysis.
- Notebook → Prep data: develop · Notebook implements and iterates on feature preparation.
- Notebook → Balance data: tune · Notebook tests fraud-class balancing strategies.
- Prep data → Train split: feed · Prepared features are split for validation.
- Balance data → Train split: apply · Balancing is applied before or within training partitioning.
- Train split → Classifier: train · Training partition fits the classifier.
- Classifier → Evaluate: measure · Holdout predictions are scored with classification metrics.
- Classifier → Pipeline: serialize · Fitted preprocessing and classifier are saved together.
- Training script → Prep data: run · Python script provides reusable preprocessing execution.
- Training script → Classifier: fit · Script can invoke training logic for the classifier.
- Training script → Pipeline: save · Script can emit the persisted pipeline artifact.
- Pipeline → Scoring use: score · The saved artifact is loaded for future inference.
