A full-stack, real-time machine learning pipeline that detects fraudulent financial transactions in milliseconds. This project ingests a high-throughput stream of transactions, processes them via Apache Kafka, scores them using a LightGBM model deployed with FastAPI, and visualizes the results on a live Streamlit dashboard.
- Real-Time Streaming: Simulates 20M+ transaction volume using a custom Producer and Apache Kafka.
- Low-Latency Inference: Deployed LightGBM model via FastAPI (REST) with sub-50ms response times.
- Imbalanced Data Handling: Trained on the PaySim dataset (0.2% fraud rate) using dynamic class weighting to achieve 99% Recall.
- Live Dashboard: Interactive Streamlit interface to monitor transaction traffic, flagged fraud, and estimated saved revenue.
- Containerized Infrastructure: Uses Docker Compose to orchestrate Kafka services without manual setup.
The system follows a decoupled microservices architecture:
- Producer: Generates synthetic financial transactions and pushes them to the
financial_transactionsKafka topic. - Kafka Broker: Central messaging backbone for real-time streaming.
- Inference Service (FastAPI): Serves a trained LightGBM model for ultra-fast predictions.
- Detector / Consumer: Listens to Kafka, sends data to the API, logs alerts.
- Dashboard: Monitors stream activity and fraud alerts in real time.
- Language: Python 3.12
- ML Model: LightGBM (Gradient Boosting)
- Streaming: Apache Kafka (KRaft mode)
- API Framework: FastAPI + Uvicorn
- Visualization: Streamlit + Altair
- Containerization: Docker & Docker Compose
- Docker Desktop installed and running.
- Python 3.9+
git clone https://github.com/MananxRobin/fraud-detection-system.git
cd fraud-detection-systempip install -r requirements.txtUse
confluent-kafkainstead ofkafka-pythonfor Python 3.12.
docker-compose up -dWait ~30 seconds for Kafka to initialize.
Open 4 terminals:
python app.pystreamlit run dashboard.pypython detector.pypython producer.pyThen open http://localhost:8501 to view your live dashboard.
| Metric | Score | Notes |
|---|---|---|
| Accuracy | 99.8% | High due to class imbalance |
| Recall (Fraud) | 99% | Most important metric |
| Precision | ~11% | Acceptable false positives for safety |
├── docker-compose.yml # Kafka infrastructure
├── requirements.txt # Python dependencies
├── README.md # Documentation
├── app.py # FastAPI inference service
├── dashboard.py # Streamlit dashboard
├── detector.py # Kafka consumer logic
├── producer.py # Data stream simulator
├── train_model.py # Training & feature engineering
└── fraud_model.pkl # Saved LightGBM model
- Database Integration (PostgreSQL) for audit trails
- Feature Store (Redis) for velocity-based real-time features
- Cloud Deployment using AWS ECS or Kubernetes
Author: Manan Ambaliya License: MIT

