A production-ready fraud detection system with real-time monitoring, 3 ML models, and a stunning React dashboard.
- Basic Rules Engine (v1.0.0) - Threshold-based fraud detection
- Machine Learning Model (v2.1.0) - XGBoost with 92% accuracy
- Deep Learning Model (v3.0.0) - LSTM neural network with 96% accuracy
- Live transaction monitoring with WebSocket
- Interactive transaction analysis
- Real-time statistics and risk scoring
- Model performance comparison with charts
- FastAPI backend with WebSocket support
- React + TypeScript frontend with Chart.js
- Realistic transaction simulator
- Model versioning and activation
- Performance tracking and metrics
Live Dashboard - Monitor transactions in real-time
- Stats cards showing total, flagged, and blocked transactions
- Live transaction feed with risk indicators
- Detailed transaction analysis panel
Model Comparison - Compare model performance
- Model performance cards with key metrics
- Accuracy trends over time (line chart)
- False positive rates comparison (bar chart)
- Comprehensive comparison table
- FastAPI - Modern async Python web framework
- WebSockets - Real-time bidirectional communication
- scikit-learn - ML model framework
- XGBoost - Gradient boosting for ML model
- TensorFlow/Keras - Deep learning framework
- Faker - Realistic data generation
- React 18 - UI library
- TypeScript - Type-safe JavaScript
- Vite - Fast build tool
- Chart.js - Interactive charts
- React Router - Client-side routing
- Python 3.10+
- Node.js 18+ and npm
- Git
git clone https://github.com/deymohit02/AI-Based-Fraud-Detection.git
cd AI-Based-Fraud-Detection# Navigate to backend directory
cd backend
# Create virtual environment (recommended)
python -m venv venv
# Activate virtual environment
# Windows:
venv\Scripts\activate
# Linux/Mac:
# source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Copy environment example
copy .env.example .env # Windows
# cp .env.example .env # Linux/Mac
# Start backend server
python main.pyBackend will be available at http://localhost:8000
Open a new terminal window:
# Navigate to frontend directory
cd frontend
# Install dependencies
npm install
# Start development server
npm run devFrontend will be available at http://localhost:5173
-
Start Backend (Terminal 1):
cd backend python main.py -
Start Frontend (Terminal 2):
cd frontend npm run dev -
Open Browser: Navigate to
http://localhost:5173
- Click "Start Monitoring" to begin real-time transaction stream
- Watch transactions appear in the feed
- Click any transaction to see detailed analysis
- View model predictions and risk assessment
- Click "Stop Monitoring" to pause the stream
- View performance metrics for all 3 models
- Compare accuracy trends over time
- Analyze false positive rates
- Click "Activate" to switch active model
- Review the comparison table and performance analysis
[Transaction Simulator]
β
[WebSocket Connection]
β
[Model Manager] β Runs all 3 models in parallel
β
[Active Model] β Makes blocking decision
β
[Dashboard] β Display results in real-time
- Algorithm: Rule-based threshold detection
- Accuracy: 85%
- Features:
- High amount detection (>$1000)
- Transaction velocity checks
- V-feature anomaly detection
- Use Case: Fast, explainable decisions
- Algorithm: XGBoost (Gradient Boosting)
- Accuracy: 92%
- Features:
- 30 features (Time, V1-V28, Amount)
- Pre-trained on credit card data
- StandardScaler normalization
- Use Case: Balanced accuracy and speed
- Algorithm: LSTM (Long Short-Term Memory)
- Accuracy: 96%
- Features:
- Sequential pattern detection
- 64-unit LSTM layer
- Dropout regularization
- Use Case: Highest accuracy, complex patterns
Generates realistic transactions with:
- Merchant names (using Faker library)
- Locations (cities and states)
- Amounts (log-normal distribution)
- V-features (PCA components, V1-V28)
- Fraud patterns (12% fraud rate)
- High amount frauds
- Unusual locations
- Rapid transaction sequences
- Unknown merchants
AI-Based-Fraud-Detection/
β
βββ backend/ # FastAPI Backend
β βββ models/ # Fraud detection models
β β βββ rules_engine.py # Basic rules model
β β βββ ml_model.py # ML XGBoost wrapper
β β βββ dl_model.py # DL LSTM model
β β βββ model_manager.py # Model orchestrator
β βββ main.py # FastAPI application
β βββ transaction_simulator.py # Transaction generator
β βββ requirements.txt # Python dependencies
β βββ .env.example # Environment template
β
βββ frontend/ # React Frontend
β βββ src/
β β βββ components/ # Reusable components
β β βββ pages/ # Dashboard pages
β β βββ hooks/ # Custom React hooks
β β βββ types/ # TypeScript types
β β βββ App.tsx # Main app component
β β βββ index.css # Design system
β βββ package.json # Node dependencies
β βββ vite.config.ts # Vite configuration
β
βββ models/ # Pre-trained models
β βββ xgboost.pkl # Trained XGBoost model
β βββ scaler.pkl # Feature scaler
β
βββ README.md # This file
# Server
HOST=0.0.0.0
PORT=8000
DEBUG=True
# Model Paths
XGBOOST_MODEL_PATH=../models/xgboost.pkl
SCALER_PATH=../models/scaler.pkl
# Transaction Simulator
TRANSACTION_RATE=2.0 # Transactions per second
FRAUD_RATE=0.12 # 12% fraud rate
# Active Model
ACTIVE_MODEL=ml_model # rules_engine | ml_model | dl_modelOnce the backend is running, visit:
- Interactive API Docs: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
ws://localhost:8000/ws/transactions- Real-time transaction stream
GET /api/health- Health checkGET /api/stats- Current statisticsGET /api/transactions- Recent transactionsGET /api/models- All model metricsGET /api/models/comparison- Model comparison dataPOST /api/models/activate- Activate a modelPOST /api/predict- Predict single transaction
-
Backend Health:
curl http://localhost:8000/api/health
-
Start Frontend: Open browser to
http://localhost:5173 -
Test Flow:
- Click "Start Monitoring"
- Verify transactions appear
- Click a transaction
- Verify details panel loads
- Go to Model Comparison tab
- Click "Activate" on different model
- Return to Live Dashboard
- Verify active model changed
cd backend
pip install -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port $PORTcd frontend
npm run build
# Deploy 'dist' folderImportant: Update WebSocket URL in frontend code to match your backend URL.
| Model | Accuracy | Precision | Recall | F1 Score | FPR | FNR |
|---|---|---|---|---|---|---|
| Rules Engine | 85.0% | 88.0% | 92.0% | 90.0% | 12.0% | 8.0% |
| ML Model (XGBoost) | 92.0% | 94.0% | 96.0% | 95.0% | 6.0% | 4.0% |
| DL Model (LSTM) | 96.0% | 97.0% | 98.0% | 97.5% | 3.0% | 2.0% |
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
MIT License - See LICENSE file for details
- Dataset Inspiration: Kaggle Credit Card Fraud Detection
- Tech Stack: FastAPI, React, Chart.js, TensorFlow, scikit-learn
- Design: Modern dashboard UX patterns
Maintainer: Mohit Dey
GitHub: @deymohit02
Repository: AI-Enhanced-Fraud-Detection
Built with β€οΈ for production-ready fraud detection