# tejabdhhskas-a11y/fraud-detection-system architecture

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

- Interactive diagram: https://gitdiagram.com/tejabdhhskas-a11y/fraud-detection-system
- Repository: https://github.com/tejabdhhskas-a11y/fraud-detection-system

## Overview

This repository is a UPI fraud-detection system: synthetic transaction data is generated, used to train and evaluate an XGBoost model, and the saved model is served through a FastAPI prediction endpoint. A separate SHAP workflow explains model behavior. The main request path accepts transaction features, scales them, predicts fraud probability, and returns a risk classification. The README documents the overall workflow and reported model performance; the graph’s implementation links are based on the sampled source, so unsampled behavior is not inferred.

Main entry points: [`generate_data.py`](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/generate_data.py) (Transaction Dataset), [`train_model.py`](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/train_model.py) (Training Pipeline), [`app.py`](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/app.py) (FastAPI Service), [`explain.py`](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/explain.py) (SHAP Analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Synthetic Data"]
  node_generator["Transaction Generator<br/>[generate_data.py]"]
  node_dataset["Transaction Dataset<br/>[generate_data.py]"]
end

subgraph group_training["Model Training"]
  node_trainer["Training Pipeline<br/>[train_model.py]"]
  node_model["Fraud Model<br/>[fraud_model.pkl]"]
  node_scaler["Feature Scaler<br/>[scaler.pkl]"]
end

subgraph group_serving["Prediction API"]
  node_api["FastAPI Service<br/>[app.py]"]
  node_features["Feature Scaling<br/>[app.py]"]
  node_inference["Fraud Inference<br/>[app.py]"]
  node_result["Risk Response<br/>[app.py]"]
end

subgraph group_explainability["Model Explanations"]
  node_explainer["SHAP Analysis<br/>[explain.py]"]
end

node_operator(("API Client"))

node_operator -->|"submits transaction"| node_api
node_generator -->|"generates"| node_dataset
node_dataset -->|"loads CSV"| node_trainer
node_trainer -->|"saves model"| node_model
node_trainer -->|"saves scaler"| node_scaler
node_api -->|"builds features"| node_features
node_features -->|"transforms with"| node_scaler
node_api -->|"requests prediction"| node_inference
node_inference -->|"predicts with"| node_model
node_inference -->|"returns risk"| node_result
node_dataset -->|"samples transactions"| node_explainer
node_explainer -->|"transforms sample"| node_scaler
node_explainer -->|"explains predictions"| node_model

click node_generator "https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/generate_data.py"
click node_dataset "https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/generate_data.py"
click node_trainer "https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/train_model.py"
click node_model "https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/fraud_model.pkl"
click node_scaler "https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/scaler.pkl"
click node_api "https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/app.py"
click node_features "https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/app.py"
click node_inference "https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/app.py"
click node_result "https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/app.py"
click node_explainer "https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/explain.py"

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_generator,node_dataset,node_operator toneBlue
class node_trainer,node_model,node_scaler toneAmber
class node_api,node_features,node_inference,node_result toneMint
class node_explainer toneRose
```

## Components

### Synthetic Data

- [Transaction Generator](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/generate_data.py): `generate_data.py`
- [Transaction Dataset](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/generate_data.py): `generate_data.py`

### Model Training

- [Training Pipeline](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/train_model.py): `train_model.py`
- [Fraud Model](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/fraud_model.pkl): `fraud_model.pkl`
- [Feature Scaler](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/scaler.pkl): `scaler.pkl`

### Prediction API

- [FastAPI Service](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/app.py): `app.py`
- [Feature Scaling](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/app.py): `app.py`
- [Fraud Inference](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/app.py): `app.py`
- [Risk Response](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/app.py): `app.py`

### Model Explanations

- [SHAP Analysis](https://github.com/tejabdhhskas-a11y/fraud-detection-system/blob/main/explain.py): `explain.py`

### Other components

- **API Client**

## Connections

- API Client → FastAPI Service: submits transaction (evidence: `README.md`)
- Transaction Generator → Transaction Dataset: generates (evidence: `generate_data.py`)
- Transaction Dataset → Training Pipeline: loads CSV (evidence: `train_model.py`)
- Training Pipeline → Fraud Model: saves model (evidence: `train_model.py`)
- Training Pipeline → Feature Scaler: saves scaler (evidence: `train_model.py`)
- FastAPI Service → Feature Scaling: builds features (evidence: `app.py`)
- Feature Scaling → Feature Scaler: transforms with (evidence: `app.py`)
- FastAPI Service → Fraud Inference: requests prediction (evidence: `app.py`)
- Fraud Inference → Fraud Model: predicts with (evidence: `app.py`)
- Fraud Inference → Risk Response: returns risk (evidence: `app.py`)
- Transaction Dataset → SHAP Analysis: samples transactions (evidence: `explain.py`)
- SHAP Analysis → Feature Scaler: transforms sample (evidence: `explain.py`)
- SHAP Analysis → Fraud Model: explains predictions (evidence: `explain.py`)
