End-to-end fraud detection platform β ML scoring, rule engine, explainability, and live simulation in one system.
π Live Demo Β· π Features Β· ποΈ Architecture Β· πΈ Screenshots Β· π API Docs
Banks process millions of transactions daily. A human can't review each one. Traditional fraud systems are black boxes β they flag transactions but can't explain why. Compliance teams need audit trails. Business teams need explainability.
This system solves all three:
| Challenge | This System's Solution |
|---|---|
| π΄ Real-time detection | ML scoring on every transaction in < 100ms |
| β« Black-box decisions | SHAP explainability + policy reason tracking |
| π Audit compliance | Full SQLite log of every prediction + override |
| πΈ False positives | Hybrid model β ML + business rules in layers |
| π No visibility | Live SaaS dashboard with trend analytics |
UI Design: Custom CSS design system β glassmorphism cards, spline charts, gradient fills. Zero default Streamlit components. Built to look like a real fintech SaaS product.
- Random Forest classifier β trained on 9,600+ financial transactions
- 20+ engineered features β balance errors, velocity ratios, behavioral signals, time patterns
- Imbalanced data handling β undersampling + class weighting
- Evaluation metrics β ROC-AUC, PR-AUC, Precision/Recall at multiple thresholds
Rule 1: Amount > sender balance + account emptied β CRITICAL override
Rule 2: Multiple suspicious signals (β₯3) β HIGH override
Rule 3: Very high signal count (β₯5) β CRITICAL override
Rule 4: Large transaction + zero-balance dest. β HIGH override
Rule 5: Velocity flag + new device β HIGH override
- Live Transaction Simulator β inject single or batch transactions, charts update instantly
- Session State architecture β no page reload required
- 5 KPI cards β total transactions, critical alerts, high risk, override rate, avg score
- Risk distribution donut β always shows full dataset, unaffected by filters
- Alert trend line chart β spline curves, gradient fills, simulated points highlighted
- Build any transaction manually β merchant, country, amount, hour, signals
- Real-time risk preview β score updates as you move sliders
- Batch simulate up to 100 transactions with custom fraud mix %
- Session stats β injected count, high risk, critical breakdown
POST /predictβ fraud prediction with full breakdownGET /logsβ paginated audit trailGET /statsβ aggregate metricsGET /debug/{id}β feature-level explanationPOST /admin/seed-logsβ test data generation
- Global feature importance visualization
- Per-transaction explanation β "why was this flagged?"
- Policy trigger reasons tracked and displayed
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DATA FLOW β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Transaction Input
β
βΌ
βββββββββββββββββββββ
β Feature Engine β β 20+ derived features
β (engineering.py) β balance_error, velocity,
ββββββββββ¬βββββββββββ amount_ratio, time_flags
β
βΌ
βββββββββββββββββββββ βββββββββββββββββββββ
β ML Scorer β β Policy Engine β
β Random Forest ββββββββΆ β 5 Business Rules β
β β probability β β β override flag β
βββββββββββββββββββββ ββββββββββ¬βββββββββββ
β
βΌ
βββββββββββββββββββββ
β Decision Layer β
β Final Risk Level β
β LOW/MED/HIGH/ β
β CRITICAL β
ββββββββββ¬βββββββββββ
β
ββββββββββββββββββββββββΌβββββββββββββββββββββββ
βΌ βΌ βΌ
ββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββ
β SQLite Log β β FastAPI JSON β β Streamlit β
β Audit Trail β β Response β β Dashboard β
ββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββ
Transaction-Fraud-Intelligence/
β
βββ π app/ # Streamlit Dashboard
β βββ Home.py # Main dashboard entry point
β βββ premium_design.py # CSS design system
β βββ simulator.py # Live ML simulation engine
β βββ utils_dashboard.py # DB query helpers
β
βββ π pages/ # Multi-page Streamlit
β βββ 1_Alerts_Monitoring.py
β βββ 2_Model_Performance.py
β βββ 3_Transaction_Simulator.py
β
βββ π api/ # FastAPI Backend
β βββ main.py # All API endpoints
β
βββ π data/
β βββ processed/ # Cleaned, feature-engineered data
β βββ raw/ # Original source data (gitignored)
β
βββ π models/ # Saved ML models (.pkl)
β
βββ π notebooks/ # Jupyter analysis (8 notebooks)
β βββ 01_data_understanding.ipynb
β βββ 02_eda.ipynb
β βββ 03_data_preprocessing.ipynb
β βββ 04_feature_engineering.ipynb
β βββ 05_model_building.ipynb
β βββ 06_model_evaluation.ipynb
β βββ 07_explainability_shap.ipynb
β
βββ π reports/ # Generated charts and PDFs
βββ π scripts/ # One-time utility scripts
β
βββ .gitignore
βββ requirements.txt
βββ README.md
Python 3.12+
pip# 1. Clone the repository
git clone https://github.com/prince3235/Transaction-Fraud-Intelligence.git
cd Transaction-Fraud-Intelligence
# 2. Install dependencies
pip install -r requirements.txt
# 3. Seed the database with sample data
python scripts/seed_data.py
# 4. Launch the dashboard
streamlit run app/Home.py# In a separate terminal
uvicorn api.main:app --reload
# API docs available at:
# http://localhost:8000/docsDashboard runs on
http://localhost:8501API runs onhttp://localhost:8000
| Method | Endpoint | Description |
|---|---|---|
POST |
/predict |
Score a transaction β returns risk level + reasons |
GET |
/logs |
Paginated audit trail of all predictions |
GET |
/stats |
Aggregate metrics β counts, rates, distributions |
GET |
/debug/{id} |
Feature-level breakdown for a specific transaction |
POST |
/admin/seed-logs |
Generate sample transaction data |
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{
"amount": 85000,
"oldbalanceOrg": 90000,
"newbalanceOrig": 0,
"type": "TRANSFER",
"step": 2
}'{
"transaction_id": 9628,
"ml_probability": 0.8934,
"ml_risk_level": "CRITICAL",
"final_risk_level": "CRITICAL",
"final_risk_score": 94,
"policy_override_applied": true,
"policy_reasons": [
"Policy: Amount > sender balance + sender account emptied",
"Policy: Multiple suspicious signals detected (>=3)"
],
"recommended_action": "HOLD",
"explanation": "High transfer amount with complete account drainage detected."
}| Metric | Score |
|---|---|
| ROC-AUC | 0.97+ |
| PR-AUC | 0.89+ |
| Precision (CRITICAL) | 0.91 |
| Recall (CRITICAL) | 0.88 |
| F1 Score | 0.89 |
Top Features by SHAP Importance:
balance_errorβ amount vs balance discrepancyamount_to_orig_ratioβ transaction size relative to accountis_high_amountβ absolute amount threshold flagtransaction_hourβ time-of-day risk signalvelocity_flagβ unusual transaction frequency
| Layer | Technology |
|---|---|
| ML Model | Scikit-learn (Random Forest) |
| Explainability | SHAP |
| Backend API | FastAPI + Uvicorn |
| Dashboard | Streamlit |
| Charts | Plotly (spline, donut, gradient fills) |
| Database | SQLite |
| Data | Pandas, NumPy |
| UI Design | Custom CSS β DM Sans, glassmorphism, CSS variables |
- ML model training + evaluation
- Policy override engine (5 rules)
- FastAPI backend with audit logging
- Premium Streamlit dashboard
- Live transaction simulator
- SHAP explainability
- Email/Slack alerts on CRITICAL detection
- Docker containerization
- Real-time streaming (Kafka integration)
- Model retraining pipeline
Pull requests are welcome! For major changes, please open an issue first.
git checkout -b feature/your-feature
git commit -m "feat: add your feature"
git push origin feature/your-featureThis project is licensed under the MIT License β see LICENSE for details.



