An end-to-end AI-powered fraud detection pipeline that generates synthetic transactions, trains models using AutoML (PyCaret), detects fraud in real-time via WebSockets, and visualizes everything on a live cyberpunk dashboard.
Secure180 is a complete real-time fraud detection system that simulates a production environment for credit card transaction monitoring. It combines AutoML model training, real-time transaction simulation, instant fraud scoring, and a live cyberpunk-themed dashboard β all in a single, self-contained application.
| Feature | Description |
|---|---|
| π€ AutoML Training | PyCaret compares 8+ ML algorithms and selects the best one automatically |
| π‘ Real-Time Streaming | WebSocket-based live data feed β transactions every 2 seconds |
| π¨ Instant Alerts | Color-coded terminal alerts + dashboard toast notifications |
| π Interactive Globe | 3D globe visualization showing fraud origin locations |
| π 6 Live Charts | Doughnut, line, radar, bar, hourly, and geospatial visualizations |
| β‘ Sub-100ms Detection | Millisecond-level fraud scoring per transaction |
| ποΈ Persistent Storage | SQLite database for transaction history and model metrics |
graph TB
subgraph "Data Layer"
A[("ποΈ Synthetic Data<br/>Generator")] -->|50K transactions| B[("π creditcard_sample.csv")]
B --> C["βοΈ SMOTE<br/>Balancing"]
end
subgraph "ML Layer"
C --> D["π§ PyCaret Setup<br/>normalize + fix_imbalance"]
D --> E["π compare_models()<br/>8 algorithms"]
E --> F["π― tune_model()<br/>Hyperparameter Tuning"]
F --> G[("πΎ best_fraud_model.pkl")]
end
subgraph "Application Layer"
H["π² Transaction<br/>Simulator"] -->|every 2s| I["π‘οΈ Fraud<br/>Detector"]
G --> I
I --> J["ποΈ SQLite<br/>Database"]
I --> K["π¨ Alert<br/>System"]
I --> L["π‘ WebSocket<br/>Broadcast"]
end
subgraph "API Layer (FastAPI)"
L --> M["π REST Endpoints"]
L --> N["π WebSocket /ws"]
M --> O["π Dashboard"]
N --> O
end
style A fill:#1a1a2e,stroke:#00d4ff,color:#fff
style G fill:#1a1a2e,stroke:#00ff9d,color:#fff
style I fill:#1a1a2e,stroke:#ff2d55,color:#fff
style O fill:#1a1a2e,stroke:#a855f7,color:#fff
flowchart LR
A["make_classification()<br/>10K samples, 29 features"] --> B["Feature Engineering<br/>V1-V28 + Amount + Time"]
B --> C["Class Imbalance<br/>99% legit, 1% fraud"]
C --> D["SMOTE Oversampling<br/>Balance to ~50/50"]
D --> E["Export CSV<br/>creditcard_sample.csv"]
style A fill:#0d1b2a,stroke:#00d4ff,color:#e0e0e0
style B fill:#0d1b2a,stroke:#00d4ff,color:#e0e0e0
style C fill:#0d1b2a,stroke:#ffb800,color:#e0e0e0
style D fill:#0d1b2a,stroke:#00ff9d,color:#e0e0e0
style E fill:#0d1b2a,stroke:#a855f7,color:#e0e0e0
flowchart TD
A["π₯ Load Dataset"] --> B["βοΈ PyCaret Setup<br/>normalize=True<br/>fix_imbalance=True<br/>session_id=42"]
B --> C["π compare_models()"]
C --> D1["Random Forest"]
C --> D2["Extra Trees"]
C --> D3["Gradient Boosting"]
C --> D4["Logistic Regression"]
C --> D5["Decision Tree"]
C --> D6["KNN"]
C --> D7["Naive Bayes"]
C --> D8["AdaBoost"]
D1 & D2 & D3 & D4 & D5 & D6 & D7 & D8 --> E["π Best Model<br/>Selected by F1 Score"]
E --> F["π§ tune_model()<br/>Hyperparameter Optimization"]
F --> G["πΎ Save Model<br/>best_fraud_model.pkl"]
F --> H["π Save Metrics<br/>model_comparison.json"]
style E fill:#1a1a2e,stroke:#00ff9d,color:#fff
style F fill:#1a1a2e,stroke:#ffb800,color:#fff
style G fill:#1a1a2e,stroke:#00d4ff,color:#fff
| Metric | Description |
|---|---|
| F1 Score | Primary selection criterion β harmonic mean of precision and recall |
| AUC | Area Under ROC Curve β overall discriminative ability |
| Precision | Ratio of true positives to predicted positives |
| Recall | Ratio of true positives to actual positives |
| Accuracy | Overall correct predictions |
- AutoML model selection across 8 classification algorithms
- Hyperparameter tuning with F1 optimization
- Three-tier risk classification: LOW / MEDIUM / HIGH
- Configurable thresholds (fraud: 0.5, high-risk: 0.7)
- WebSocket streaming β live transaction feed to all connected clients
- 2-second intervals β simulated transaction generation
- Broadcast architecture β multiple dashboard instances supported
- Automatic stats refresh β KPIs update every 5 transactions
- Doughnut Chart β Legit vs. fraud transaction ratio
- Live Line Chart β Streaming transaction amounts (last 60)
- Radar Chart β Fraud distribution by merchant category
- Bar Chart β Fraud rate per store category
- 3D Globe β Geographic fraud origin visualization
- Hourly Chart β Fraud activity by hour of day
- Terminal alerts with color-coded severity (π¨ RED / π‘ YELLOW / β GREEN)
- Dashboard toast notifications for fraud events
- Persistent fraud log file for audit trail
- Risk-level badges on all transaction records
| Component | Technology | Purpose |
|---|---|---|
| Backend | FastAPI + Uvicorn | REST API + WebSocket server |
| ML Engine | PyCaret 3.3 | AutoML training and prediction |
| Database | SQLite + SQLAlchemy | Transaction & model storage |
| Frontend | Vanilla HTML/CSS/JS | Single-file cyberpunk dashboard |
| Charts | Chart.js 4.4 | Interactive data visualizations |
| Globe | Globe.gl | 3D geospatial fraud mapping |
| Data Gen | scikit-learn + imbalanced-learn | Synthetic dataset + SMOTE |
| Streaming | WebSockets | Real-time bi-directional communication |
Secure360/
βββ fraud_detection_system/
βββ run_system.py # π Main entry point β orchestrates everything
βββ config.py # βοΈ Global configuration (thresholds, paths)
βββ requirements.txt # π¦ Python dependencies
β
βββ api/
β βββ __init__.py
β βββ main_api.py # π FastAPI app β REST + WebSocket endpoints
β
βββ models/
β βββ __init__.py
β βββ automl_trainer.py # π€ PyCaret AutoML training pipeline
β βββ saved_model/
β βββ best_fraud_model.pkl # πΎ Trained model (generated)
β
βββ realtime/
β βββ __init__.py
β βββ fraud_detector.py # π‘οΈ Real-time prediction engine
β βββ transaction_simulator.py # π² Synthetic transaction generator
β
βββ database/
β βββ __init__.py
β βββ db_handler.py # ποΈ SQLite operations & queries
β βββ fraud_detection.db # π Database file (generated)
β
βββ alerts/
β βββ __init__.py
β βββ alert_system.py # π¨ Terminal alerts & fraud logging
β βββ fraud_alerts.log # π Fraud audit log (generated)
β
βββ data/
β βββ __init__.py
β βββ generate_dataset.py # π Synthetic data + SMOTE pipeline
β βββ creditcard_sample.csv # π Generated dataset (50K rows)
β βββ model_comparison.json # π AutoML comparison results
β
βββ dashboard/
βββ __init__.py
βββ index.html # π¨ Cyberpunk dashboard (single file)
- Python 3.10+ (required for PyCaret 3.x compatibility)
- pip package manager
# 1. Clone the repository
git clone https://github.com/<your-username>/Secure360.git
cd Secure360/fraud_detection_system
# 2. Create virtual environment
python3 -m venv .venv
source .venv/bin/activate # macOS/Linux
# .venv\Scripts\activate # Windows
# 3. Install dependencies
pip install -r requirements.txt
# 4. Launch the system
python run_system.pysequenceDiagram
participant User
participant System as run_system.py
participant Data as generate_dataset.py
participant ML as automl_trainer.py
participant DB as db_handler.py
participant API as FastAPI Server
User->>System: python run_system.py
System->>Data: Check/Generate dataset
Data-->>System: β
50K transactions ready
System->>ML: Check/Train model
ML-->>System: β
Best model saved (.pkl)
System->>DB: Initialize tables
DB-->>System: β
SQLite ready
System->>API: Start Uvicorn server
API-->>User: π http://localhost:8000
loop Every 2 seconds
API->>API: Generate transaction
API->>API: Predict fraud
API->>API: Store + Alert + Broadcast
end
| Service | URL |
|---|---|
| π Dashboard | http://localhost:8000 |
| π‘ WebSocket | ws://localhost:8000/ws |
| π API Docs | http://localhost:8000/docs |
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Serve the dashboard HTML |
GET |
/health |
Health check β model status |
GET |
/stats |
Fraud statistics + model info |
GET |
/transactions?limit=100 |
Recent transactions |
GET |
/transactions/fraud?limit=50 |
Fraud-only transactions |
GET |
/model-comparison |
AutoML model comparison results |
GET |
/hourly-stats |
Fraud count by hour |
GET |
/category-stats |
Fraud rate by merchant category |
| Endpoint | Message Types |
|---|---|
ws://localhost:8000/ws |
transaction β new transaction data |
stats_update β refreshed KPI metrics |
Example WebSocket message:
{
"type": "transaction",
"data": {
"transaction_id": "a1b2c3d4-...",
"timestamp": "2026-02-20T11:30:00",
"amount": 2450.00,
"merchant_category": "electronics",
"location": "Lagos/Nigeria",
"fraud_probability": 0.9234,
"prediction": 1,
"risk_level": "HIGH",
"processing_time_ms": 45.23,
"model_used": "AutoML"
}
}The dashboard features a cyberpunk-inspired UI with real-time data streaming:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π‘οΈ FRAUDSHIELD AI π΄ LIVE β CONNECTED β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β [Total] [Fraud] [Rate%] [Saved$] [Speed] [Model] β β KPI Cards
ββββββββββββ¬ββββββββββββββββββ¬ββββββββββββββββββββββββββ€
β π© Donut β π Live Line β π‘ Radar β β Charts Row 1
ββββββββββββ΄ββββββββββββββββββ€ββββββββββββββββββββββββββ€
β π Categoryβ π Globe β π Hourly β β Charts Row 2
βββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββ€
β π Transaction Feed β π¨ Fraud Alerts β β Bottom Row
βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββ
- Dark cyberpunk theme with grid background and neon accents
- Real-time animations β slide-in rows, pulsing indicators, toast alerts
- 6 KPI cards with color-coded borders (cyan, red, yellow, green, purple)
- Interactive 3D globe showing fraud origin hotspots
- Fully responsive β works on desktop, tablet, and mobile
πΈ Add your own screenshots below after running the system!
Place screenshots in a
screenshots/folder and update the paths:  
- Uses
sklearn.make_classification()to create 10,000 synthetic transactions with 29 features (V1βV28 + Amount) - Applies SMOTE (Synthetic Minority Oversampling) to balance fraud/legit classes
- Saves balanced dataset to
creditcard_sample.csv
- PyCaret AutoML compares 8 classification models:
- Random Forest, Extra Trees, Gradient Boosting, Logistic Regression, Decision Tree, KNN, Naive Bayes, AdaBoost
- Best model selected by F1 Score
- Winner is hyperparameter-tuned and saved as
.pkl
- Transaction Simulator generates realistic transactions every 2 seconds
- ~2% fraud rate with high-amount, suspicious-location patterns
- Fraud Detector loads the trained model and scores each transaction
- Returns probability, prediction, risk level, and processing time
- Color-coded terminal output: π¨ Fraud / π‘ Suspicious / β Legitimate
- Persistent
fraud_alerts.logfor audit compliance
- FastAPI serves REST endpoints and WebSocket connections
- Single HTML dashboard connects via WebSocket for live updates
- Chart.js renders 6 interactive visualizations
- Globe.gl provides 3D geographic fraud mapping
βββββββββββββββββββββββββββββββββββββββββββββββ
β Fraud Probability β Risk Level β
βββββββββββββββββββββββββββββββββββββββββββββββ€
β 0.0 - 0.4 β π’ LOW β
β 0.4 - 0.7 β π‘ MEDIUM β
β 0.7 - 1.0 β π΄ HIGH β
βββββββββββββββββββββββββββββββββββββββββββββββ
All settings are in config.py:
DATABASE_PATH = "database/fraud_detection.db"
MODEL_SAVE_PATH = "models/saved_model/best_fraud_model"
FRAUD_THRESHOLD = 0.5 # Minimum probability to flag as fraud
HIGH_RISK_THRESHOLD = 0.7 # Threshold for HIGH risk level
TRANSACTION_INTERVAL_SECONDS = 2 # Seconds between simulated transactions
HOST = "0.0.0.0"
PORT = 8000- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License β see the LICENSE file for details.
Gagandeep Kaur (E11625)
Built with β€οΈ using Python, FastAPI, PyCaret, and Chart.js