DualSentry is a high-performance, distributed financial fraud detection system that ingests transaction streams, evaluates fraud risk using XGBoost ML models in < 50ms, and delivers real-time analytics through an interactive React dashboard.
β‘ Quick Start Β· ποΈ Architecture Β· π Key Highlights Β· π‘ API Reference Β· π Documentation Hub
| Model Registry & Hot-Swapping | System Architecture Blueprint |
|---|---|
![]() |
![]() |
| Zero-downtime model activation with drift monitoring statistics | End-to-end event streaming, API Gateway, and database flow |
| Dimension | Specification |
|---|---|
| Core Languages | Go 1.22, Python 3.11, TypeScript 5.0, SQL, HTML5/CSS3 |
| Microservices | Go API Gateway, Python FastAPI ML Engine, React Dashboard, Go Load Simulator |
| Inference SLA | < 50ms p95 latency for real-time risk evaluation |
| Data Streaming | Apache Kafka (8 topic partitions) + Zookeeper coordination |
| Storage & Caching | PostgreSQL 16 (Primary DB) + Redis 7 (Idempotency & Rate Limiting) |
| Security & Auth | JWT Bearer Authentication, Granular RBAC (Admin / Analyst), bcrypt cost 12 |
| Observability | Prometheus metrics exporter + Grafana Dashboards + Structured Audit Logging |
| CI/CD & DevOps | GitHub Actions Pipeline + Multi-stage Docker Builds + Nginx Reverse Proxy |
Financial institutions process millions of transactions daily, facing persistent threats from modern automated fraud vectors.
- Rules Are Static: Traditional rule-based engines fail to detect novel fraud patterns and produce high false-positive rates, degrading legitimate user experience.
- Latency Is Critical: Fraud evaluation must occur synchronously within payment authorization windows (< 100ms total budget).
- Data Drift: Fraud behavior evolves over time; ML models decay if not continuously monitored against statistical drift.
DualSentry combines an event-driven Go gateway for high-throughput ingestion with a Python FastAPI inference engine running an optimized XGBoost classifier. It enforces idempotency via Redis, queues raw transactions to Kafka for downstream consumers, statistical drift detection (PSI/Chi-sq), and supports zero-downtime model hot-swapping via a centralized model registry.
Key technical implementations featured in this repository:
- π Sub-50ms Inference: Optimized FastAPI predictor pipeline using pre-fitted transformers and XGBoost probability thresholding.
- β‘ Go Concurrency & Resilience: Go HTTP/gRPC gateway leveraging worker patterns, Redis sliding-window rate limiting, and circuit breakers for downstream ML fallbacks.
- π Kafka Distributed Streaming: Non-blocking transaction publishing to Kafka (
transactions.raw) for async event processing. - π‘οΈ Enterprise Security & RBAC: JWT Bearer token verification with strict Role-Based Access Control (Admin vs. Analyst role enforcement).
- π Zero-Downtime Model Registry: Dynamic model manager enabling live hot-swapping of active ML models without microservice restarts.
- π Automated Drift & Retraining: Drift runner calculating Population Stability Index (PSI) and triggering containerized model retraining pipelines.
- π Full-Stack Observability: Native Prometheus metrics (
http_requests_total,http_request_duration_seconds) scraped across services into Grafana dashboards.
π€ AI & Machine Learning
- XGBoost Fraud Classifier: Trained on IBM Financial AML dataset achieving ~97% accuracy and ~0.89 F1-Score.
- Dynamic Model Registry: Centralized JSON-backed registry tracking versioning, accuracy metrics, and active model flags.
- Zero-Downtime Hot-Swapping: Switch active model versions live via authenticated Admin API endpoints.
- Statistical Drift Monitoring: Automatic calculation of Population Stability Index (PSI) to detect feature distribution shifts.
- Automated Retraining Pipeline: Modular pipeline for re-extracting dataset baselines, fitting XGBoost models, and updating registry artifacts.
β‘ Backend & Streaming Infrastructure
- High-Throughput Go Gateway: Low-overhead HTTP/gRPC ingestion gateway built with Go 1.22.
- Apache Kafka Event Broker: Distributed transaction topic partitioning (
transactions.raw) with IBM Sarama driver. - Redis Idempotency & Rate Limiting: Deduplication of duplicate transaction IDs and per-IP rate throttling.
- Circuit Breaker Pattern: Resilient fallback handling when ML inference engine is under heavy load.
- PostgreSQL Persistence: Structured transaction logging, historical baselines, and prediction tracking.
π₯οΈ Frontend Dashboard & DevOps
- React 18 + Vite Dashboard: High-performance dashboard built with TypeScript, React Query, and TailwindCSS.
- Interactive Visualizations: Recharts integration for real-time fraud trends, decision distribution pie charts, and KPI cards.
- Code-Split Bundles: Rollup manual chunking delivering a lightweight 31 KB main bundle footprint.
- Nginx Reverse Proxy: Single entry point routing
/api/*to Go Gateway and/ml/*to Python ML Engine with Gzip compression. - GitHub Actions CI/CD: Automated linting, typechecking, unit tests, and Docker Compose validation on every push.
[ Client / Load Simulator ]
β
β 1. POST /api/transactions
βΌ
ββββββββββββββββββββββββ
β Nginx Reverse Proxy β
ββββββββββββ¬ββββββββββββ
β 2. Proxy request
βΌ
ββββββββββββββββββββββββ 3. Deduplicate & Rate-Limit
β Go Ingestion Gatewayβ βββββββββββββββββββββββββββββββββββΆ [ Redis Cache ]
ββββββββββββ¬ββββββββββββ
β 4. Publish Event (Async)
βββββββββββββββββββββββββββββββββββββββββββββββββΆ [ Apache Kafka ]
β 5. Save Raw Transaction
βββββββββββββββββββββββββββββββββββββββββββββββββΆ [ PostgreSQL DB ]
β
β 6. Synchronous Risk Scoring (gRPC / REST)
βΌ
ββββββββββββββββββββββββ
β Python ML Engine β βββΆ [ XGBoost Model ] βββΆ Score: 0.91 (BLOCK)
ββββββββββββ¬ββββββββββββ
β 7. Return Prediction & Write Audit Log
βΌ
ββββββββββββββββββββββββ
β Go Ingestion Gatewayβ βββΆ 8. Persist Prediction βββΆ [ PostgreSQL DB ]
ββββββββββββ¬ββββββββββββ
β
β 9. Return Fraud Status & Response Payload
βΌ
[ Client / React Dashboard ] βββΆ 10. Prometheus Scrape βββΆ [ Grafana ]
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β React Dashboard (Vite) β
β fraud-dashboard:3001 β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β REST API
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Nginx Reverse Proxy (:80) β
β /api/ β ingestion-gateway:8080 β
β /ml/ β ml-anomaly-engine:8000 β
ββββββββββββββ¬ββββββββββββββββββββββββββ¬ββββββββββββββββββββββββ
β β
βΌ βΌ
ββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββ
β Go Ingestion Gateway β β Python ML Anomaly Engine β
β (REST + gRPC + Kafka)β β FastAPI + XGBoost + Registry β
β ingestion-gateway: β β ml-anomaly-engine:8000 β
β 8080 (HTTP) β ββββββββββββββ¬ββββββββββββββββββββββ
β 50051 (gRPC) β β
ββββββββββ¬ββββββββββββββββ β
β β
βΌ βΌ
ββββββββββββββββββ βββββββββββββββββββ
β PostgreSQL ββββββββββββββββ PostgreSQL β
β :5432 β β (shared DB) β
ββββββββββββββββββ βββββββββββββββββββ
β
βΌ
ββββββββββββββββββ βββββββββββββββ ββββββββββββββββββββ
β Redis β β Kafka β β Zookeeper β
β Rate Limiting β β Streaming β β Kafka Coord. β
β :6379 β β :9092 β β :2181 β
ββββββββββββββββββ βββββββββββββββ ββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Observability Stack β
β Prometheus (:9090) + Grafana (:3000) β
βββββββββββββββββββββββββββββββββββββββββββ
| Service | Container Name | Port | Description |
|---|---|---|---|
| fraud-dashboard | fintech-dashboard |
3001 |
React + TypeScript Vite Operations Dashboard |
| ingestion-gateway | fintech-ingestion-gateway |
8080 (HTTP), 50051 (gRPC) |
Go API Gateway, Kafka Producer, Redis Limiter |
| ml-anomaly-engine | fintech-ml-engine |
8000 |
Python FastAPI Inference Engine & Model Registry |
| transaction-simulator | fintech-simulator |
β | Go load generator producing realistic transaction mixes |
| postgres | fintech-postgres |
5432 |
Primary PostgreSQL relational data store |
| redis | fintech-redis |
6379 |
In-memory store for idempotency keys & rate limits |
| kafka | fintech-kafka |
9092 |
Event streaming broker for transaction topics |
| zookeeper | fintech-zookeeper |
2181 |
Cluster management and coordination for Kafka |
| nginx | fintech-nginx |
80 |
Reverse proxy load balancing API routes |
| prometheus | fintech-prometheus |
9090 |
Time-series metrics collection engine |
| grafana | fintech-grafana |
3000 |
Analytics visualization and alerting UI |
The table below outlines the comprehensive technical documentation available in the docs/ directory:
| Guide | Description | Recommended Reading Context |
|---|---|---|
| Architecture | Full architectural blueprint, service inventory, and network layout | Read first to understand system topology |
| System Design | Component responsibilities, request lifecycles, and trade-offs | Read for deep-dive backend & design rationale |
| ML Pipeline | IBM dataset feature engineering, model training, registry & drift | Read when working on ML models & retraining |
| API Reference | Complete REST & gRPC endpoint documentation with request/response schemas | Read when building integrations or frontend features |
| Security Guide | JWT authentication, RBAC policy, password hashing, and Docker security | Read before deploying to production |
| Deployment Guide | Step-by-step production deployment for Vercel, Railway, Render & AWS | Read when preparing cloud deployments |
| Contributing | Local development setup, testing commands, and PR guidelines | Read before submitting contributions |
README.md (Project Overview)
β
βΌ
docs/architecture.md (System Blueprint)
β
βΌ
docs/system-design.md (Design Rationale & Trade-offs)
β
βββββββββββββββββββββββββββββββββ
βΌ βΌ
docs/ml-pipeline.md (ML Engine) docs/api.md (API Contracts)
β β
βββββββββββββββββββββββββββββββββ€
βΌ
docs/security.md & docs/deployment.md
Follow these steps to spin up the entire multi-container platform locally.
- Docker 24+ and Docker Compose v2
- Git
git clone https://github.com/Vaibhav20k/fintech-pipeline.git
cd fintech-pipelinecp .env.example .env(Optionally modify .env to customize default ports or secrets)
docker compose up -d --builddocker compose ps| Endpoint | Target URL | Credentials / Notes |
|---|---|---|
| Fraud Dashboard | http://localhost:3001 | React Operations UI |
| Nginx Reverse Proxy | http://localhost | Main API Entry Point |
| Go Gateway API | http://localhost:8080 | REST & Health Probes |
| Python ML Engine API | http://localhost:8000 | OpenAPI / Swagger Docs at /docs |
| Prometheus UI | http://localhost:9090 | Telemetry Target Scraping |
| Grafana UI | http://localhost:3000 | admin / admin |
fintech-pipeline/
βββ .github/
β βββ workflows/
β βββ ci.yml # GitHub Actions CI/CD Pipeline
βββ fraud-dashboard/ # React 18 + TypeScript + Vite Dashboard
β βββ src/
β β βββ components/ # Reusable UI components & charts
β β βββ hooks/ # React Query data-fetching hooks
β β βββ pages/ # Dashboard views
β β βββ services/ # Axios API client
β β βββ types/ # TypeScript interfaces
β βββ Dockerfile # Production multi-stage Nginx container
β βββ package.json
βββ ingestion-gateway/ # Go 1.22 REST/gRPC API Gateway
β βββ cmd/server/ # Gateway main entry point
β βββ internal/
β β βββ api/handler/ # HTTP handlers (transactions, predictions)
β β βββ config/ # Environment configuration loader
β β βββ kafka/ # Sarama Kafka producer/consumer
β β βββ middleware/ # Rate limiting, IP extraction, CORS
β β βββ ml/ # ML client with Circuit Breaker
β β βββ server/ # HTTP & gRPC server initializers
β βββ proto/ # Protocol Buffer definitions
β βββ Dockerfile # Multi-stage Go build container
βββ ml-anomaly-engine/ # Python 3.11 FastAPI ML Engine
β βββ auth/ # JWT token handler & RBAC dependencies
β βββ config/ # Database & settings manager
β βββ inference/ # FastAPI routes, schemas, predictors
β βββ models/ # Model Registry JSON & saved PKLs
β βββ monitoring/ # Population Stability Index (PSI) drift detector
β βββ retraining/ # Automated model retraining pipeline
β βββ services/ # Audit logger & model manager
β βββ tests/ # Pytest suite
β βββ Dockerfile # Lightweight Python runtime container
β βββ requirements.txt # Pinned dependencies
βββ transaction-simulator/ # Go transaction load generator
βββ database/ # PostgreSQL init scripts & migrations
βββ nginx/ # Reverse proxy configuration
βββ observability/ # Prometheus config & Grafana definitions
βββ docs/ # Comprehensive technical guides
βββ docker-compose.yml # Full-stack orchestrator
βββ .env.example # Master environment template
The ML Engine implements strict JWT Bearer token authentication with Role-Based Access Control (RBAC).
β οΈ Warning: Default development credentials. Always update passwords in.envbefore production deployment.
| Username | Password | Role | Access Scope |
|---|---|---|---|
admin |
admin123 |
admin |
Full read/write access + Model Registration & Activation |
analyst |
analyst123 |
analyst |
Read-only access to predictions, stats, and drift metrics |
curl -X POST http://localhost:8000/login \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=admin&password=admin123"Response Payload:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "bearer",
"role": "admin"
}Include the access token in subsequent request headers:
Authorization: Bearer <access_token>Below is an overview of core API endpoints. See docs/api.md for full request/response schemas.
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/api/transactions |
None | Submit a transaction for ingestion and synchronous risk scoring |
GET |
/api/predictions |
None | Retrieve historical predictions for dashboard viewing |
GET |
/api/dashboard/summary |
None | Get KPI metrics (total count, fraud count, fraud rate) |
POST |
/ml/predict |
Bearer | Synchronous ML fraud probability prediction |
GET |
/ml/models |
Bearer | List all registered model versions |
GET |
/ml/models/active |
Bearer | Retrieve active model details |
POST |
/ml/models/activate |
Admin | Hot-swap active model version |
POST |
/ml/models/register |
Admin | Register new trained model artifact |
GET |
/ml/monitoring |
Bearer | Get live model inference statistics |
GET |
/ml/drift |
Bearer | Run statistical drift detection (PSI) |
GET |
/health |
None | Gateway liveness probe |
DualSentry utilizes an XGBoost Classifier optimized for tabular transaction evaluation.
| Metric | XGBoost v2 (Production) | Isolation Forest (Baseline) |
|---|---|---|
| Accuracy | 97.2% | 85.1% |
| Precision | 91.4% | 72.3% |
| Recall | 88.6% | 81.0% |
| F1-Score | 0.899 | 0.764 |
| AUC-ROC | 0.982 | 0.912 |
- Temporal:
hour,day_of_week,is_weekendderived from ISO timestamps. - Account Ratios:
amount_to_balance_ratio(amount / from_account_balance). - State History: Historical account transaction velocity maintained by Go
baseline_updater.
DualSentry provides end-to-end monitoring out of the box:
- Prometheus Metrics: Exported at
http://localhost:8080/metricsandhttp://localhost:8000/metrics. - Latency Histogram: Tracks
http_request_duration_secondsfor p50, p90, and p99 latency SLAs. - Request Counters: Tracks
http_requests_totalby HTTP method, route, and status code. - Structured Audit Logging: Predictions and admin actions logged with timestamp and user context to
logs/audit.log.
Automated quality control is executed on every GitHub push/PR via .github/workflows/ci.yml:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GitHub Actions CI/CD Pipeline β
βββββββ¬βββββββββββββββ¬βββββββββββββββ¬βββββββββββββββ¬βββββββββββ
β β β β
βΌ βΌ βΌ βΌ
βββββββββββββ βββββββββββββ βββββββββββββ βββββββββββββ
β Go CI β β Python CI β βReact Frontendβ β Docker β
β β’ go fmt β β β’ flake8 β β β’ tsc checkβ β β’ compose β
β β’ go vet β β β’ pytest β β β’ eslint β β syntax β
β β’ go test β β suite β β β’ vite β β check β
β β’ build β βββββββββββββ β build β βββββββββββββ
βββββββββββββ βββββββββββββ
- Multi-stage containerized microservices architecture
- Zero-downtime model registry hot-swapping
- Statistical drift detection (Population Stability Index)
- Vite React frontend code-splitting (< 50KB main bundle)
- Real-time WebSocket alerts for high-risk fraud detections
- Grafana dashboard automated JSON provisioning
- Kubernetes Helm Chart for production deployments
- SHAP model explainability breakdown endpoint
Contributions are welcome! Please follow these steps:
- Review CONTRIBUTING.md for environment setup and coding standards.
- Fork the repository and create your feature branch:
git checkout -b feat/my-feature. - Verify all test suites pass (
go test,pytest,tsc --noEmit). - Commit your changes and open a Pull Request.
This project is licensed under the MIT License β see the LICENSE file for details.



