π A production-style fraud detection platform for fintech use cases, built with Python, FastAPI, machine learning, rules engines, anomaly detection, and MLOps.
FinShield is designed to simulate how modern fintech fraud detection systems are built in real-world environments.
Instead of training a single notebook model, this project combines:
- π§ supervised fraud classification for known fraud patterns
- π΅οΈ anomaly detection for unknown suspicious behavior
- π rules-based scoring for interpretable business logic
- βοΈ hybrid scoring for final risk decisions
- π‘ FastAPI endpoints for real-time fraud scoring
- π monitoring, audit logging, and MLflow tracking for operational credibility
The goal is to make this repo feel like a serious portfolio-grade fintech ML system rather than a simple beginner project.
Fraud detection in fintech is not solved with one model alone.
Real systems usually combine:
- historical behavior analysis
- merchant and device intelligence
- hand-crafted fraud rules
- probabilistic models
- anomaly scoring
- explainable decisioning
- monitoring and audit trails
FinShield follows that same pattern.
It ingests transaction history, builds fraud features, trains supervised and unsupervised models, evaluates rules, combines all signals into a final score, and exposes the results through a real-time API.
FinShield helps answer questions like:
- Is this transaction suspicious based on past behavior?
- Does it break known fraud rules?
- Does it look abnormal compared to normal activity?
- Should it be approved, reviewed, or blocked?
- Why did the system make that decision?
Raw Transaction Data
β
βΌ
Data Validation + Cleaning
β
βΌ
Batch Feature Engineering
β
βββ Customer Behavior Features
βββ Velocity Features
βββ Merchant Risk Features
βββ Time Features
βββ Geo / Device Features
β
βΌ
Training Pipelines
β
βββ Logistic Regression Baseline
βββ XGBoost Supervised Model
βββ Isolation Forest Anomaly Model
β
βΌ
Saved Model Artifacts
β
βΌ
Realtime Feature Builder
β
βΌ
Fraud Intelligence Layers
β
βββ Rules Engine
βββ Supervised Model Inference
βββ Anomaly Detection Inference
β
βΌ
Hybrid Fraud Scoring Engine
β
βΌ
Decision Output
βββ Approve β
βββ Review β οΈ
βββ Block β
β
βΌ
Operational Layer
βββ FastAPI Endpoints
βββ Audit Logs
βββ Monitoring Reports
βββ MLflow Experiment Tracking
Fraud models are only as good as the features they consume.
This project engineers rich behavioral and contextual features such as:
- β° Transaction time features (hour, weekend, night flags)
- β‘ Customer transaction velocity (1d, 7d, 30d)
- π° Rolling spend behavior
- π Amount deviation from customer history
- πͺ Merchant historical fraud rate
- π± New device indicator
- π Foreign transaction flag
Rules provide fast, interpretable fraud logic based on domain knowledge.
Example rules include:
- πΈ High transaction amount
- π± New device + large spend
- π Rapid repeat activity
- πͺ Merchant fraud hotspot
- π Foreign high-value transaction
π Rules are stored in YAML configuration and can be modified without changing code.
The supervised model learns from labeled fraud data and predicts fraud probability.
Implemented models:
- Logistic Regression (baseline)
- XGBoost (primary classifier)
The anomaly model detects unusual or unseen patterns without relying on labels.
Implemented model:
- Isolation Forest
The final fraud score combines multiple intelligence layers:
- π Rule-based score
- π§ Supervised model probability
- π΅οΈ Anomaly score
This reflects how real-world fraud systems blend rules and machine learning.
Transactions are scored in real time using FastAPI endpoints.
- β‘ Low-latency inference
- π On-the-fly feature generation
- π API-based decisioning
The platform includes production-style observability features:
- π MLflow experiment tracking
- π§Ύ Prediction audit logs
- π Drift report generation
- π¦ Model metadata storage
- β Production-style Python project structure
- β Configurable fraud rules engine (YAML-driven)
- β Supervised fraud model training (Logistic + XGBoost)
- β Anomaly detection pipeline (Isolation Forest)
- β Hybrid risk scoring engine
- β FastAPI real-time serving layer
- β Model metadata endpoint
- β Monitoring and drift reporting
- β Audit logging for predictions
- β MLflow experiment tracking
- β Unit, integration, and API tests
- β Docker + GitHub Actions CI
finshield-fraud-detection-platform/
βββ apps/
β βββ api/
β β βββ main.py
β βββ monitoring/
β β βββ monitor.py
β βββ training/
β βββ train.py
β
βββ configs/
β βββ base.yaml
β βββ features.yaml
β βββ model.yaml
β βββ rules.yaml
β
βββ data/
β βββ raw/
β βββ interim/
β βββ processed/
β βββ samples/
β
βββ docs/
β βββ api.md
β βββ architecture.md
β βββ model-card.md
β βββ runbook.md
β
βββ features/
β βββ batch_features.py
β βββ realtime_features.py
β
βββ models/
β βββ anomaly/
β βββ supervised/
β βββ artifacts/
β
βββ pipelines/
β βββ data_validation.py
β βββ training_pipeline.py
β βββ scoring_pipeline.py
β βββ evaluation_pipeline.py
β
βββ src/
β βββ common/
β βββ data/
β βββ models/
β βββ monitoring/
β βββ rules/
β βββ scoring/
β
βββ tests/
β βββ api/
β βββ integration/
β βββ unit/
β
βββ logs/
βββ reports/
βββ mlruns/
βββ Dockerfile
βββ docker-compose.yml
βββ Makefile
βββ pyproject.toml
βββ README.md
π― What This System Does
high_amount foreign_high_amount rapid_repeat_activity merchant_fraud_hotspot new_device_high_amount
- detect fraud using learned patterns π§
- detect suspicious unknown behavior π΅οΈ
- apply business fraud rules π
- combine everything into a final decision βοΈ
- explain why the decision was made π
πΉ Swagger API
π http://127.0.0.1:8000/docs
πΉ Hybrid Fraud Scoring Example
π₯ Input:
{
"amount": 12000,
"country": "ZA",
"device_type": "desktop"
}π€ Output:
{
"final_score": 84.55,
"decision": "block",
"top_reasons": [
"high_amount",
"merchant_fraud_hotspot",
"high_model_probability"
]
}Transaction β Features β Rules + ML + Anomaly β Hybrid Score β Decision
Raw Data
β
Feature Engineering
β
βββ Rules Engine
βββ ML Model (XGBoost)
βββ Anomaly Model (Isolation Forest)
β
Hybrid Scoring Engine
β
Decision (Approve / Review / Block)
β
API + Monitoring + Logs
- Behavioral features (spend patterns)
- Velocity features (transaction frequency)
- Risk features (merchant fraud rate)
- Context features (time, geo, device)
- YAML-configurable
- Explainable decisions
- Instant fraud detection layer
- Logistic Regression (baseline)
- XGBoost (primary)
- Isolation Forest
- Detects unknown fraud patterns
final_score =
0.30 * rules
+ 0.45 * ML probability
+ 0.25 * anomaly score
- FastAPI-based scoring
- Production-style endpoints
- MLflow experiment tracking
- Audit logs (every prediction tracked)
- Drift reports
- Model metadata endpoints
- Hybrid fraud detection system
- Explainable decisions
- Real-time scoring API
- ML + anomaly detection
- Monitoring + audit logging
- CI/CD pipeline
- Fully tested system
| Score | Decision |
|---|---|
| 0β39 | β Approve |
| 40β69 | |
| 70β100 | β Block |
pip install -e .[dev]
pytest
python pipelines/training_pipeline.py
python -m uvicorn apps.api.main:app --reloadπ Open:
http://127.0.0.1:8000/docs
| Type | Location |
|---|---|
| MLflow runs | mlruns/ |
| Audit logs | logs/ |
| Drift reports | reports/ |
| Models | models/artifacts/ |
pytestβ Unit
β Integration
β API
This project shows ability in:
- Machine Learning Engineering
- Backend Development (FastAPI)
- Data Engineering (pipelines)
- MLOps (MLflow, monitoring)
- System Design
- Fraud Detection Domain
- Feature store (Feast)
- SHAP explainability
- Streaming fraud detection (Kafka)
- Dashboard (React)
- Cloud deployment (AWS/GCP)
Thabang Rakeng
Fullstack (MERN, dotnet) | Ai/Ml developers
This project is intentionally built to demonstrate:
β real-world ML system thinking
β production pipeline design
β hybrid decision systems
β clean architecture
FinShield is built to showcase what a modern fraud detection platform can look like when engineering, ML, and MLOps are combined thoughtfully.
If you found this useful, give the repo a β