Skip to content

Scalable AI fraud detection system combining Spark, ensemble ML/DL models, RAG-based explanations, and event-driven architecture for real-time, explainable, and high-accuracy fraud detection.

Notifications You must be signed in to change notification settings

deymohit02/AI-Enhanced-Fraud-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

46 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FraudGuard AI - Real-Time Fraud Detection Dashboard

A production-ready fraud detection system with real-time monitoring, 3 ML models, and a stunning React dashboard.

Dashboard Preview Python React TypeScript


✨ Features

🎯 3 Fraud Detection Models

  • 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

πŸ“Š Real-Time Dashboard

  • Live transaction monitoring with WebSocket
  • Interactive transaction analysis
  • Real-time statistics and risk scoring
  • Model performance comparison with charts

πŸš€ Production-Ready

  • FastAPI backend with WebSocket support
  • React + TypeScript frontend with Chart.js
  • Realistic transaction simulator
  • Model versioning and activation
  • Performance tracking and metrics

πŸ–ΌοΈ Screenshots

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

πŸ› οΈ Tech Stack

Backend

  • 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

Frontend

  • React 18 - UI library
  • TypeScript - Type-safe JavaScript
  • Vite - Fast build tool
  • Chart.js - Interactive charts
  • React Router - Client-side routing

πŸš€ Quick Start

Prerequisites

  • Python 3.10+
  • Node.js 18+ and npm
  • Git

1. Clone Repository

git clone https://github.com/deymohit02/AI-Based-Fraud-Detection.git
cd AI-Based-Fraud-Detection

2. Backend Setup

# 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.py

Backend will be available at http://localhost:8000

3. Frontend Setup

Open a new terminal window:

# Navigate to frontend directory
cd frontend

# Install dependencies
npm install

# Start development server
npm run dev

Frontend will be available at http://localhost:5173


πŸ“– Usage

Starting the System

  1. Start Backend (Terminal 1):

    cd backend
    python main.py
  2. Start Frontend (Terminal 2):

    cd frontend
    npm run dev
  3. Open Browser: Navigate to http://localhost:5173

Using the Dashboard

Live Dashboard Tab

  1. Click "Start Monitoring" to begin real-time transaction stream
  2. Watch transactions appear in the feed
  3. Click any transaction to see detailed analysis
  4. View model predictions and risk assessment
  5. Click "Stop Monitoring" to pause the stream

Model Comparison Tab

  1. View performance metrics for all 3 models
  2. Compare accuracy trends over time
  3. Analyze false positive rates
  4. Click "Activate" to switch active model
  5. Review the comparison table and performance analysis

🎯 How It Works

Transaction Flow

[Transaction Simulator] 
    ↓
[WebSocket Connection]
    ↓
[Model Manager] β†’ Runs all 3 models in parallel
    ↓
[Active Model] β†’ Makes blocking decision
    ↓
[Dashboard] β†’ Display results in real-time

Models

1. Basic Rules Engine (v1.0.0)

  • Algorithm: Rule-based threshold detection
  • Accuracy: 85%
  • Features:
    • High amount detection (>$1000)
    • Transaction velocity checks
    • V-feature anomaly detection
  • Use Case: Fast, explainable decisions

2. Machine Learning Model (v2.1.0)

  • 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

3. Deep Learning Model (v3.0.0)

  • Algorithm: LSTM (Long Short-Term Memory)
  • Accuracy: 96%
  • Features:
    • Sequential pattern detection
    • 64-unit LSTM layer
    • Dropout regularization
  • Use Case: Highest accuracy, complex patterns

Transaction Simulator

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

πŸ“ Project Structure

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

πŸ”§ Configuration

Backend Configuration (.env)

# 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_model

🎨 API Documentation

Once the backend is running, visit:

Key Endpoints

WebSocket

  • ws://localhost:8000/ws/transactions - Real-time transaction stream

REST API

  • GET /api/health - Health check
  • GET /api/stats - Current statistics
  • GET /api/transactions - Recent transactions
  • GET /api/models - All model metrics
  • GET /api/models/comparison - Model comparison data
  • POST /api/models/activate - Activate a model
  • POST /api/predict - Predict single transaction

πŸ§ͺ Testing

Manual Testing

  1. Backend Health:

    curl http://localhost:8000/api/health
  2. Start Frontend: Open browser to http://localhost:5173

  3. 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

πŸš€ Production Deployment

Backend (Render, Railway, or similar)

cd backend
pip install -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port $PORT

Frontend (Vercel, Netlify, or similar)

cd frontend
npm run build
# Deploy 'dist' folder

Important: Update WebSocket URL in frontend code to match your backend URL.


πŸ“Š Performance Metrics

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%

🀝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

πŸ“„ License

MIT License - See LICENSE file for details


πŸ™ Acknowledgments

  • Dataset Inspiration: Kaggle Credit Card Fraud Detection
  • Tech Stack: FastAPI, React, Chart.js, TensorFlow, scikit-learn
  • Design: Modern dashboard UX patterns

πŸ“§ Contact

Maintainer: Mohit Dey
GitHub: @deymohit02
Repository: AI-Enhanced-Fraud-Detection


Built with ❀️ for production-ready fraud detection

About

Scalable AI fraud detection system combining Spark, ensemble ML/DL models, RAG-based explanations, and event-driven architecture for real-time, explainable, and high-accuracy fraud detection.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published