A real-time e-commerce transaction fraud detection system using Machine Learning, Kafka streaming, and Redis cache.
Dashboard overview — metrics, live fraud alerts, test transaction form, risk distribution:
Live transaction feed — real-time scoring, latency, and blocked fraud transactions:
Frontend (React) ──► Backend API (Node.js/Express)
│
▼
Kafka: transactions.raw
│
▼
Python Fraud Service (FastAPI + LightGBM)
│ │
▼ ▼
Redis (user state) Kafka: transactions.scored
│
▼
Backend updates DB + WebSocket
│
▼
Frontend Dashboard (real-time)
| Layer | Technology |
|---|---|
| Frontend | React, Vite, TailwindCSS, Recharts |
| Backend API | Node.js, Express, TypeScript, PostgreSQL |
| Fraud Service | Python, FastAPI, LightGBM, SMOTE |
| Streaming | Apache Kafka |
| Cache/State | Redis |
| ML | Scikit-learn, XGBoost, LightGBM, imbalanced-learn |
- Imbalanced Data: SMOTE oversampling with ~0.8% fraud rate in training data
- Latency: Per-transaction scoring latency measured and displayed, target <50ms
- Real-time: Kafka event-driven pipeline + WebSocket live dashboard
- Behavioral features: Velocity, amount anomaly, geo/device fingerprint via Redis
- Docker & Docker Compose
- Node.js 20+ (local dev)
- Python 3.11+ (local dev)
docker compose up --buildServices:
- Frontend: http://localhost:5174
- Backend API: http://localhost:3001
- Fraud Service: http://localhost:8000
- Kafka: localhost:9092
- Redis: localhost:6379
- PostgreSQL: localhost:5432
1. Infrastructure:
docker compose up zookeeper kafka redis postgres -d2. Train ML model:
cd fraud-service
pip install -r requirements.txt
python scripts/train_model.py3. Fraud Service:
cd fraud-service
uvicorn app.main:app --reload --port 80004. Backend:
cd backend
npm install
npm run db:migrate
npm run dev5. Frontend:
cd frontend
npm install
npm run devcd fraud-service
pip install requests
python scripts/generate_transactions.pyOr use the dashboard UI: Submit Normal TX / Submit Fraud-like TX buttons.
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/transactions |
Create transaction, publish to Kafka |
| GET | /api/transactions |
List transactions |
| GET | /api/transactions/alerts |
Fraud alerts |
| GET | /api/transactions/stats |
Dashboard metrics |
| GET | /api/health |
Health check |
| WS | /ws |
Real-time feed |
| Method | Endpoint | Description |
|---|---|---|
| POST | /score |
Score a single transaction (sync) |
| POST | /score/batch |
Score a batch |
| GET | /metrics |
Latency, fraud rate metrics |
| GET | /health |
Model + Redis status |
transactions.raw— New transactions from the backendtransactions.scored— Scoring results from the fraud service
├── backend/ # Node.js API + Kafka producer/consumer
├── frontend/ # React dashboard
├── fraud-service/ # Python ML anti-fraud microservice
│ ├── app/
│ │ ├── ml/ # LightGBM scorer
│ │ ├── features/ # Feature engineering
│ │ ├── consumer/ # Kafka worker
│ │ └── redis_store.py
│ ├── scripts/
│ │ ├── train_model.py
│ │ └── generate_transactions.py
│ └── models/ # Trained model artifacts
├── schemas/ # JSON schemas
└── docker-compose.yml
MIT

