# tejaskedarpawar/fraud-detection-pipeline architecture

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

- Interactive diagram: https://gitdiagram.com/tejaskedarpawar/fraud-detection-pipeline
- Repository: https://github.com/tejaskedarpawar/fraud-detection-pipeline

## Overview

This repository is a real-time fraud-detection pipeline with two result paths: Kafka-streamed transactions are scored and may become monitored alerts, while API clients can request an individual score and inspect service health and usage metrics. The offline path explores and preprocesses transaction data, then trains and evaluates candidate models for runtime use. The README documents Kafka and Docker orchestration; deployment files are omitted from this runtime map. The graph reflects sampled Python source and documented capabilities; broker wiring beyond the shown Kafka topic operations is not expanded.

Main entry points: [`consumer.py`](https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/consumer.py) (Fraud scorer), [`fraud_eda.py`](https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/fraud_eda.py) (Explore and prepare), [`fraud_model.py`](https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/fraud_model.py) (Train and evaluate), [`main.py`](https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/main.py) (Scoring and metrics API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_offline["Offline ML"]
  node_eda["Explore and prepare<br/>[fraud_eda.py]"]
  node_training_data["Prepared splits"]
  node_training["Train and evaluate<br/>[fraud_model.py]"]
  node_model_file["Selected model"]
end

subgraph group_stream["Streaming Detection"]
  node_producer["Transaction generator<br/>[producer.py]"]
  node_consumer["Fraud scorer<br/>[consumer.py]"]
  node_monitor["Alert monitor<br/>[alert_monitor.py]"]
end

subgraph group_serving["API Serving"]
  node_api["Scoring and metrics API<br/>[main.py]"]
end

subgraph group_messaging["Kafka Messaging"]
  node_transactions["Transactions topic"]
  node_alerts["Fraud alerts topic"]
  node_kafka{{"Kafka broker"}}
end

node_analyst(("Data analyst"))
node_api_client(("API client"))

node_analyst -->|"provides dataset"| node_eda
node_eda -->|"saves splits"| node_training_data
node_training_data -->|"loads splits"| node_training
node_training -->|"saves winner"| node_model_file
node_model_file -->|"loads model"| node_consumer
node_model_file -->|"loads model"| node_api
node_producer -->|"publishes transactions"| node_kafka
node_kafka -->|"routes messages"| node_transactions
node_transactions -->|"consumes transactions"| node_consumer
node_consumer -->|"publishes fraud alerts"| node_kafka
node_kafka -->|"routes alerts"| node_alerts
node_alerts -->|"consumes alerts"| node_monitor
node_api_client -->|"requests scoring or metrics"| node_api

click node_eda "https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/fraud_eda.py"
click node_training "https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/fraud_model.py"
click node_producer "https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/producer.py"
click node_consumer "https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/consumer.py"
click node_monitor "https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/alert_monitor.py"
click node_api "https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/main.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_eda,node_training_data,node_training,node_model_file,node_api_client toneBlue
class node_producer,node_consumer,node_monitor toneAmber
class node_api toneMint
class node_transactions,node_alerts,node_kafka toneRose
class node_analyst toneIndigo
```

## Components

### Offline ML

- [Explore and prepare](https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/fraud_eda.py): `fraud_eda.py`
- **Prepared splits**
- [Train and evaluate](https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/fraud_model.py): `fraud_model.py`
- **Selected model**

### Streaming Detection

- [Transaction generator](https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/producer.py): `producer.py`
- [Fraud scorer](https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/consumer.py): `consumer.py`
- [Alert monitor](https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/alert_monitor.py): `alert_monitor.py`

### API Serving

- [Scoring and metrics API](https://github.com/tejaskedarpawar/fraud-detection-pipeline/blob/main/main.py): `main.py`

### Kafka Messaging

- **Transactions topic**
- **Fraud alerts topic**
- **Kafka broker**

### Other components

- **Data analyst**
- **API client**

## Connections

- Data analyst → Explore and prepare: provides dataset
- Explore and prepare → Prepared splits: saves splits
- Prepared splits → Train and evaluate: loads splits
- Train and evaluate → Selected model: saves winner
- Selected model → Fraud scorer: loads model
- Selected model → Scoring and metrics API: loads model
- Transaction generator → Kafka broker: publishes transactions
- Kafka broker → Transactions topic: routes messages
- Transactions topic → Fraud scorer: consumes transactions
- Fraud scorer → Kafka broker: publishes fraud alerts
- Kafka broker → Fraud alerts topic: routes alerts
- Fraud alerts topic → Alert monitor: consumes alerts
- API client → Scoring and metrics API: requests scoring or metrics
