Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

image image image

πŸ” ThreatLens

AI-Powered Insider Threat Detection for Banking Systems


Python FastAPI React MongoDB Docker HuggingFace


Gemini Groq scikit-learn iDEA Team


Detect. Explain. Contain. ThreatLens watches when no one else is watching.


image

πŸ“‹ Table of Contents


🎯 Problem Statement

This project addresses PS1: AI-Driven Early Warning System for Internal & Privileged User Fraud.

Banking systems face severe vulnerabilities from privileged insiders β€” admins, branch staff, relationship managers, and IT teams β€” whose malicious actions blend seamlessly with normal operations and bypass traditional, externally-focused security perimeters.

ThreatLens is a real-time AI-powered Early Warning System that profiles behavioural baselines for individual privileged users, detects cross-silo anomalies (Core Banking, CRM, Treasury, Loans, Email) using an unsupervised Isolation Forest model, and deploys an Explainable AI Copilot (Gemini + Groq Llama 3.1) to translate every detected threat into an instant, actionable natural language incident summary β€” compressing SOC investigation time from hours to seconds.


πŸš€ Live Demo

Link
πŸ”— Live App https://ag235772-threat-lens.hf.space
πŸŽ₯ Demo Video [Insert YouTube Link here]

Credentials for demo:

  • SOC Analyst View β†’ navigate to the Fraud Investigation Hub
  • Manager View β†’ navigate to the Manager Dashboard (kill-switch access)
  • Trigger Live Events β†’ use the Simulated Banking Portal to generate real-time anomalies through the full pipeline

βš™οΈ How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         THREATLENS PIPELINE                                 β”‚
β”‚                                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚   Simulated  β”‚    β”‚   FastAPI    β”‚    β”‚  Isolation   β”‚    β”‚  Gemini  β”‚   β”‚
β”‚  β”‚   Banking    │───▢│   Gateway   │───▢│   Forest     │───▢│  + Groq β”‚   β”‚
β”‚  β”‚   Portal     β”‚    β”‚  (Async)     β”‚    β”‚  ML Engine   β”‚    β”‚  XAI     β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜   β”‚
β”‚   Core Banking              β”‚                   β”‚                 β”‚         β”‚
β”‚   CRM  |  Treasury          β”‚              anomaly_score          β”‚         β”‚
β”‚   Loans | Email       MongoDB Atlas         + is_anomaly          β”‚         β”‚
β”‚                             β”‚                   β”‚                 β”‚         β”‚
β”‚                       β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”‚
β”‚                       β”‚         React SOC Investigation Hub              β”‚  β”‚
β”‚                       β”‚   ForceGraph2D  |  Kill Switch  |  XAI Copilot   β”‚  β”‚
β”‚                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  1. Ingest β€” The Simulated Banking Portal generates events across 5 silos; each event is POST'd to FastAPI with user ID, action type, amount, geo-location, and timestamp.
  2. Detect β€” The Isolation Forest model scores every event against the behavioural baseline. Outliers (anomaly score < 0) are flagged instantly.
  3. Explain β€” Gemini 2.5 Flash generates a full incident report. The Groq Llama 3.1 Copilot answers live SOC analyst questions in under 100ms.
  4. Contain β€” The Manager Dashboard's kill switch immediately revokes the suspicious user's session.

πŸ› οΈ Tech Stack

Layer Technology Purpose
Frontend React + Vite, ForceGraph2D Real-time SOC dashboard, interactive threat network visualisation
Backend Python 3.10, FastAPI, Uvicorn Async REST API, ML inference pipeline, static file serving
Database MongoDB Atlas, Motor (Async) Flexible NoSQL event storage across multi-silo log structures
ML Engine Scikit-learn (Isolation Forest), Pandas, NumPy, Joblib Unsupervised anomaly detection; no labeled fraud data required
AI / XAI Google Gemini 2.5 Flash, Groq Llama 3.1-8B Natural language incident reports + real-time SOC Copilot Q&A
Deployment Docker (Multi-Stage Build), Hugging Face Spaces Single-container, zero-cost public hosting on port 7860

πŸ’» How to Run Locally

Prerequisites


Option A β€” Run Frontend + Backend Separately (Development)

1. Clone the repository

git clone https://github.com/AUG235772/ThreatLens
cd threatlens

2. Configure environment variables

# Create a .env file inside /backend
cp backend/.env.example backend/.env

Edit backend/.env:

MONGO_URI=your_mongodb_atlas_connection_string
GEMINI_API_KEY_1=your_gemini_api_key
GEMINI_API_KEY_2=your_gemini_api_key_2        # optional β€” used for rotation
GEMINI_API_KEY_3=your_gemini_api_key_3        # optional β€” used for rotation
GROQ_API_KEY=your_groq_api_key

3. Install backend dependencies and start the API

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

API will be live at http://localhost:8000 OpenAPI docs at http://localhost:8000/docs

4. Install frontend dependencies and start the React app

# In a new terminal
cd frontend
npm install
npm run dev

App will be live at http://localhost:5173


Option B β€” Run with Docker (mirrors Hugging Face deployment)

# Build the image
docker build -t threatlens .

# Run with your environment variables
docker run -p 7860:7860 \
  -e MONGO_URI=your_mongo_uri \
  -e GEMINI_API_KEY_1=your_gemini_key \
  -e GROQ_API_KEY=your_groq_key \
  threatlens

Full app (UI + API) accessible at http://localhost:7860


πŸ“ Project Structure

threatlens/
β”‚
β”œβ”€β”€ πŸ“‚ backend/
β”‚   β”œβ”€β”€ πŸ“‚ app/
β”‚   β”‚   └── main.py              ← FastAPI app: routes, ML inference, XAI engine, MongoDB connection
β”‚   β”œβ”€β”€ requirements.txt         ← All Python dependencies
β”‚   └── .env.example             ← Environment variable template
β”‚
β”œβ”€β”€ πŸ“‚ frontend/
β”‚   β”œβ”€β”€ πŸ“‚ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx              ← Root React component + routing
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ components/       ← SOC Investigation Hub, Manager Dashboard, Simulated Portal
β”‚   β”‚   └── πŸ“‚ pages/            ← Page-level views
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.js
β”‚
β”œβ”€β”€ πŸ“‚ ml_engine/
β”‚   β”œβ”€β”€ πŸ“‚ models/
β”‚   β”‚   β”œβ”€β”€ isolation_forest.pkl ← Trained Isolation Forest model (Joblib)
β”‚   β”‚   β”œβ”€β”€ le_action.pkl        ← LabelEncoder for action_type feature
β”‚   β”‚   └── le_geo.pkl           ← LabelEncoder for geo_location feature
β”‚   └── model_training.ipynb    ← Full EDA + training pipeline notebook
β”‚
β”œβ”€β”€ πŸ“‚ assets/                   ← README screenshots (add yours here)
β”‚
β”œβ”€β”€ Dockerfile                   ← Multi-stage build (Node 20 β†’ Python 3.10-slim)
└── README.md

πŸ“Š Dataset

All data is 100% synthetic, generated by Team Dhurandhars using the training notebook at /ml_engine/model_training.ipynb.

Property Value
Total Events 6,000
Normal Events (95%) 5,700
Anomalous Events (5%) 300
Systems Covered Core Banking, CRM, Treasury, Loans, Email
Simulated Employees 10 privileged users across 5 departments
Simulation Period 30 days
Reproducibility Seed SEED = 42

Features per event:

Feature Type Description
amount_inr Float Transaction amount in Indian Rupees
is_business_hours Binary 1 if event occurred 9am–6pm Mon–Fri
hour_of_day Int (0–23) Hour the event was triggered
action_code Encoded Int LabelEncoded action type (20 possible actions)
geo_code Encoded Int LabelEncoded geographic location

Normal profile: Business hours Β· Domestic geo (Mumbai, Delhi, Bangalore) Β· Routine actions (LOGIN_SUCCESS, VIEW_RECORD, DOMESTIC_TRANSFER) Β· Moderate INR amounts

Anomalous profile injected: Off-hours Β· Foreign geo (Moscow, Beijing, Dubai, Lagos) Β· Suspicious actions (BULK_EXPORT, UNAUTHORIZED_API_CALL, MASS_RECORD_ACCESS) Β· Extreme amounts

No real bank data was used at any stage.


πŸ“ˆ Model Performance

Isolation Forest β€” Unsupervised Anomaly Detection

Metric Value
Algorithm Isolation Forest
n_estimators 100
contamination 0.05 (5%)
Training Set Size 6,000 events
XAI Coverage 100% of flagged anomalies receive a natural language incident summary
Inference Speed Near-instantaneous (no GPU required)
Model Artefacts isolation_forest.pkl Β· le_action.pkl Β· le_geo.pkl

⚠️ Note: Results are on synthetic data. Performance on real-world banking data would require re-training on actual institutional event logs with real behavioural baselines.


⚠️ Known Limitations

  • Synthetic data only β€” The system relies on simulated event sequences rather than live enterprise event streams (e.g., Apache Kafka). All employee activity is synthetically generated and does not represent real bank telemetry.

  • External LLM APIs β€” XAI features depend on Gemini and Groq APIs, which are subject to rate limiting (mitigated via 3-key rotation). These external APIs are not suitable for production environments containing real customer PII due to data privacy constraints.

  • Single-container deployment β€” The current architecture is a single Docker container on Hugging Face Spaces. Production would require independent microservices, dedicated scaling, SSO/Active Directory authentication, and compliance-grade audit logging.

  • No auto-retraining β€” The Isolation Forest is trained on a fixed dataset. User behavioural drift over time would require periodic retraining pipelines in production.

  • No authentication β€” The SOC dashboard has no user login (acceptable for POC demonstration; not suitable for production deployment).


πŸ‘₯ Team

Name Role Responsibilities
Aditya Gupta ML Lead Isolation Forest training pipeline, synthetic dataset generation, model artefacts, anomaly scoring integration
Dev Parmar Backend Developer FastAPI architecture, MongoDB Atlas integration, XAI engine (Gemini + Groq), Docker multi-stage deployment
Yash Jani Frontend Developer React SPA (Vite), Simulated Banking Portal, SOC Investigation Hub, ForceGraph2D threat network visualisations
Het Patel Domain Research PS1 analysis, insider fraud typologies, banking compliance requirements, documentation (D1, D3, D4)

πŸ“¬ Contact

Team Name DHURANDHARS
Project ThreatLens
Institute ITM SLS Baroda University
Hackathon iDEA 2.0 β€” Phase 2 Submission
Problem Statement PS1: AI-Driven Early Warning System for Internal & Privileged User Fraud

Made with ❀️ by Team Dhurandhars for iDEA 2.0

Detect. Explain. Contain.

About

An AI-powered Early Warning System (EWS) that uses unsupervised machine learning and Explainable AI (XAI) to detect and neutralize insider threats within banking systems.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages