Skip to content

chen-xiangrui/SentinelAI

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

152 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

SentinelAI ๐Ÿ›ก๏ธ

SentinelAI Logo

AI-Powered Email Fraud Detection System

SentinelAI is a comprehensive, multi-service fraud detection platform that uses advanced AI agents, RAG, and automation to identify and mitigate email-based security threats in real-time.

Deployed Webpage

Our product is live on this URL: https://sentinel-ai-seven.vercel.app/. Do note that only authorized users are granted permission to login due OAuth restrictions in development.

๐ŸŒŸ Key Features

  • ๐Ÿค– Agentic Workflow: Intelligent multi-agent system with dynamic routing based on confidence levels
  • ๐Ÿ“ง Real-time Email Monitoring: Live Gmail integration with automatic email triage and threat detection
  • ๐Ÿ“„ Multi-format Document Processing: Drag-and-drop support for PDF and image analysis with OCR
  • ๐Ÿ” Vector Search & RAG: Pinecone-powered similarity search for fraud pattern matching
  • ๏ฟฝ AI-Powered Chat Assistant: Context-aware chatbot for fraud analysis and cybersecurity guidance
  • ๐ŸŽฏ Interactive Dashboard: Three-panel interface with email list, report viewer, and chat integration
  • โšก Real-time Notifications: Live email listening with instant threat alerts and processing
  • ๐Ÿ“Š Comprehensive Reports: Detailed fraud analysis with confidence scores and explanations
  • ๐Ÿ”„ Scalable Architecture: Microservices with Celery workers and Redis queuing
  • ๏ฟฝ Modern UI/UX: Responsive React interface with custom color scheme and smooth animations

๐Ÿ—๏ธ Architecture Overview

Architecture Diagram

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.12+
  • Node.js 18+ (for frontend)
  • Redis Cloud (for Celery)
  • Google Cloud Project (for Gmail API & Firestore)
  • Pinecone Account (for vector database)
  • OpenAI API Key (for AI processing)
  • OCR API (for image and pdf parsing)

1. Clone Repository

git clone https://github.com/clarud/SentinelAI
cd SentinelAI

2. Backend Setup

# Install Python dependencies
cd services
pip install -r requirements.txt

# Set up environment variables
cp .env.example .env
# Edit .env with your API keys and credentials

# Start the API server
uvicorn api.app.main:app --host 0.0.0.0 --port 8000

# In another terminal, start MCP server
cd ../mcp
uvicorn server:app --reload --host 0.0.0.0 --port 7030

# In another terminal, start Celery worker
cd ../services
celery -A worker.worker.celery_app worker --loglevel=info

3. Frontend Setup

cd app
npm install
npm run dev

Visit http://localhost:8080 to access the web interface.

๐Ÿ“ Project Structure

SentinelAI/
โ”œโ”€โ”€ app/                          # React Frontend (Vite + TypeScript)
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/           # UI Components (shadcn/ui)
โ”‚   โ”‚   โ”œโ”€โ”€ pages/               # Application pages
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/               # Custom React hooks
โ”‚   โ”‚   โ””โ”€โ”€ lib/                 # Utilities and configurations
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ”œโ”€โ”€ services/                     # Backend Services
โ”‚   โ”œโ”€โ”€ api/                     # FastAPI Application
โ”‚   โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ api/routers/     # API endpoints
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ gmail_oauth.py   # Gmail OAuth flow
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ gmail_watch.py   # Gmail webhook handling
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ jobs.py          # Job management
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ health.py        # Health checks
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ services/        # Business logic
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ firestore_services.py  # Database operations
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ file_service.py        # File processing
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ main.py          # FastAPI app entry point
โ”‚   โ”‚   โ””โ”€โ”€ requirements.txt
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ worker/                  # Background Processing
โ”‚       โ”œโ”€โ”€ worker/
โ”‚       โ”‚   โ”œโ”€โ”€ agents/          # AI Agent System
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ orchestrator.py    # Main workflow orchestrator
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ prompts.py          # Agent prompts
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ schemas.py          # Pydantic models
โ”‚       โ”‚   โ”œโ”€โ”€ tasks/           # Celery tasks
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ email_task.py       # Email processing tasks
โ”‚       โ”‚   โ”œโ”€โ”€ tools/           # MCP Client Tools
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ mcp_client.py       # MCP protocol client
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ registry.py         # Tool registry
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ selector.py         # Tool selection logic
โ”‚       โ”‚   โ””โ”€โ”€ celery_app.py    # Celery configuration
โ”‚       โ””โ”€โ”€ requirements.txt
โ”‚
โ”œโ”€โ”€ mcp/                         # Model Context Protocol Servers
โ”‚   โ”œโ”€โ”€ server.py               # Centralized MCP server
โ”‚   โ”œโ”€โ”€ mcp/
โ”‚   โ”‚   โ”œโ”€โ”€ data_processor/     # Document processing tools
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ server.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ tools/
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ process_email.py
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ process_pdf.py
โ”‚   โ”‚   โ”œโ”€โ”€ extraction_tools/   # Data extraction tools
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ server.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ tools/
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ extract_link.py
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ extract_number.py
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ extract_organisation.py
โ”‚   โ”‚   โ”œโ”€โ”€ gmail_tools/        # Gmail & Google Drive tools
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ server.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ tools/
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ gmail_tools.py
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ google_drive_tool.py
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ classify_email.py
โ”‚   โ”‚   โ””โ”€โ”€ rag_tools/          # Vector search & storage
โ”‚   โ”‚       โ”œโ”€โ”€ server.py
โ”‚   โ”‚       โ””โ”€โ”€ tools/
โ”‚   โ”‚           โ”œโ”€โ”€ call_rag.py
โ”‚   โ”‚           โ””โ”€โ”€ store_rag.py
โ”‚   โ””โ”€โ”€ requirements.txt
โ”‚
โ”œโ”€โ”€ database/                    # Document Processing Pipeline
โ”‚   โ”œโ”€โ”€ document_parser.py      # Multi-format document parsing
โ”‚   โ”œโ”€โ”€ data_normalizer.py      # Text cleaning & normalization
โ”‚   โ”œโ”€โ”€ document_chunker.py     # Intelligent text chunking
โ”‚   โ”œโ”€โ”€ metadata_tagger.py      # Risk assessment & tagging
โ”‚   โ”œโ”€โ”€ vector_indexer.py       # Pinecone vector operations
โ”‚   โ”œโ”€โ”€ fraud_detection_pipeline.py  # Main processing pipeline
โ”‚   โ”œโ”€โ”€ documents/              # Input documents
โ”‚   โ””โ”€โ”€ requirements.txt
โ”‚
โ”œโ”€โ”€ test/                       # Testing Suite
โ”‚   โ”œโ”€โ”€ worker/                 # Worker tests
โ”‚   โ”œโ”€โ”€ mcp/                    # MCP server tests
โ”‚   โ””โ”€โ”€ database/               # Database pipeline tests
โ”‚
โ”œโ”€โ”€ render.yaml                 # Deployment configuration
โ””โ”€โ”€ README.md                   # This file

๐Ÿง  Agentic Workflow System

SentinelAI implements a sophisticated multi-agent workflow that dynamically adapts based on confidence levels:

Agentic Workflow

Agent Types

  1. ๐Ÿ”„ ROUTER Agent - Intelligent workflow orchestrator

    • Analyzes initial confidence and decides optimal path
    • Routes to fast-track or full analysis based on evidence
  2. ๐Ÿ“‹ PLANNER Agent - Tool selection strategist

    • Determines which extraction tools to use
    • Optimizes evidence gathering strategy
  3. ๐Ÿ“Š ANALYST Agent - Evidence interpreter

    • Processes all tool outputs and document content
    • Calculates risk metrics and confidence scores
  4. โš–๏ธ SUPERVISOR Agent - Final decision maker

    • Makes classification decisions based on analysis
    • Provides explainable reasoning for decisions
  5. โšก EXECUTER Agent - Action performer

    • Executes appropriate actions based on classification
    • Handles Gmail labeling, reporting, and data storage

Workflow Routes

๐Ÿš€ Fast Scam (95%+ confidence, 80%+ scam probability)

Document โ†’ Processing โ†’ RAG โ†’ ROUTER โ†’ EXECUTER
โฑ๏ธ ~8 seconds

โœ… Fast Legitimate (95%+ confidence, <20% scam probability)

Document โ†’ Processing โ†’ RAG โ†’ ROUTER โ†’ EXECUTER
โฑ๏ธ ~6 seconds

๐Ÿ” Full Analysis (50-95% confidence)

Document โ†’ Processing โ†’ RAG โ†’ ROUTER โ†’ PLANNER โ†’ ANALYST โ†’ SUPERVISOR โ†’ EXECUTER
โฑ๏ธ ~25 seconds

๐Ÿ•ต๏ธ Deep Analysis (<50% confidence)

Document โ†’ Processing โ†’ RAG โ†’ ROUTER โ†’ PLANNER โ†’ ANALYST โ†’ SUPERVISOR โ†’ EXECUTER
โฑ๏ธ ~35 seconds (enhanced caution mode)

๐Ÿ› ๏ธ Core Technologies

Backend

  • FastAPI - High-performance async API framework
  • Celery - Distributed task queue for background processing
  • Redis - Message broker and caching
  • WebSockets - Real-time MCP protocol communication
  • Pydantic - Data validation and settings management

AI & ML

  • Bedrock - Large language models for analysis
  • Pinecone - Vector database for similarity search
  • ReportLab - PDF generation for reports
  • OCR API - Optical character recognition

Integrations

  • Gmail API - Email access and manipulation
  • Google Drive API - Document storage and sharing
  • Google Cloud Firestore - NoSQL database
  • OAuth2 - Secure authentication

Frontend

  • React - Modern UI framework
  • TypeScript - Type-safe JavaScript
  • Vite - Fast build tool
  • shadcn/ui - Beautiful UI components
  • Tailwind CSS - Utility-first styling
  • Tanstack Query - Server state management

๐ŸŽจ User Interface Features

๐Ÿ” Authentication Flow

  • OAuth Integration: Seamless Google account login with branded interface
  • Logo Branding: SentinelAI logo and "Always Watching, Always Protecting" tagline
  • Secure Redirect: Automatic redirection to dashboard after authentication

๐Ÿ“ฑ Three-Panel Dashboard

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Email List    โ”‚  Report Viewer  โ”‚   AI Assistant  โ”‚
โ”‚   (Left Panel)  โ”‚ (Center Panel)  โ”‚  (Right Panel)  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ โ€ข Email Listen  โ”‚ โ€ข Live/Upload   โ”‚ โ€ข Context Chat  โ”‚
โ”‚ โ€ข Email IDs     โ”‚ โ€ข Fraud Report  โ”‚ โ€ข Conversation  โ”‚
โ”‚ โ€ข File Upload   โ”‚ โ€ข Risk Scores   โ”‚ โ€ข Help & Guide  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ง Left Panel - Email Management

  • ๐Ÿ”„ Email Listening Toggle: Real-time email monitoring activation
  • ๐Ÿ“‹ Dynamic Email List: Auto-updating list of incoming emails (every 10s)
  • ๐ŸŽฏ Clickable Email Buttons: Instant report generation on email selection
  • ๐Ÿ“Ž Drag & Drop Upload: Support for PDF and image file analysis
  • โฌ†๏ธ Upload Button: Manual file selection with progress indicators

๐Ÿ“Š Center Panel - Report Display

  • ๐Ÿ”€ Live/Upload Toggle: Switch between real-time emails and uploaded documents
  • ๐Ÿ“ง Email Details: Complete email metadata display (sender, subject, date, body)
  • ๐Ÿšจ Fraud Analysis:
    • Scam Label: Clear classification (Scam/Not Scam/Suspicious)
    • Confidence Level: Numerical confidence score (0.0-1.0)
    • Scam Probability: Percentage risk assessment (0-100%)
    • Detailed Explanation: AI-generated reasoning and analysis

๐Ÿ’ฌ Right Panel - AI Chat Assistant

  • ๐Ÿค– Context-Aware Responses: Uses current report as conversation context
  • ๐Ÿ“ Message History: Persistent conversation tracking
  • ๐ŸŽฏ Cybersecurity Expertise: Specialized fraud detection and security guidance
  • โšก Real-time Interaction: Instant responses with typing indicators

๐ŸŽจ Design System

  • Custom Color Palette:
    • Primary: #d4eaf7 (Light Blue), #b6ccd8 (Medium Blue), #3b3c3d (Dark Gray)
    • Accent: #71c4ef (Bright Blue), #00668c (Deep Blue)
    • Text: #1d1c1c (Primary), #313d44 (Secondary)
    • Background: #fffefb (Primary), #f5f4f1 (Secondary), #cccbc8 (Tertiary)
  • Smooth Animations: Loading states, transitions, and micro-interactions
  • Light and Dark Mode: Improves visibility in different environments.

โšก Real-time Updates

  • Live Email Feed: Automatic polling for new emails
  • Toast Notifications: Success, error, and warning alerts
  • Loading States: Spinners and skeleton screens
  • Progress Tracking: File upload and analysis progress bars

๐Ÿ” Security Features

  • ๐Ÿ›ก๏ธ OAuth2 Authentication - Secure Google account integration
  • ๐Ÿšจ Real-time Monitoring - Gmail webhook notifications
  • ๐Ÿ“Š Audit Trails - Comprehensive logging and assessment tracking
  • ๐ŸŽฏ Risk Scoring - Multi-factor fraud probability calculation
  • โšก Automated Actions - Instant scam labeling and quarantine

๐Ÿ“Š Fraud Detection Capabilities

Document Types Supported

  • ๐Ÿ“ง Email Messages - Headers, body, etc
  • ๐Ÿ“„ PDF Documents and Images - OCR and text extraction

Detection Features

  • ๐Ÿ”— URL Analysis - Suspicious link detection
  • ๐Ÿ“ฑ Phone Number Extraction - Contact information analysis
  • ๐Ÿข Organization Recognition - Entity verification
  • ๐Ÿ“ˆ Pattern Matching - Vector similarity search
  • ๐Ÿงฎ Probability Scoring - AI-driven risk assessment

Email Monitoring

  • Real-time Email Polling: Frontend polls for new email IDs every minute
  • Email Report Generation: Dynamic report creation based on selected email ID
  • Live Dashboard Updates: Automatic UI updates for incoming threats

๐Ÿ“ˆ Performance Metrics

  • โšก Fast Response: 95%+ confidence cases processed in <10 seconds
  • ๐ŸŽฏ High Accuracy: Multi-agent validation for complex cases
  • ๐Ÿ“Š Scalable: Horizontal scaling with Celery workers
  • ๐Ÿ”„ Real-time: WebSocket MCP protocol for instant tool communication
  • ๐Ÿ’พ Efficient: Vector search for O(log n) similarity matching

๐Ÿš€ Deployment

  • Front End
  • API
  • Celery Background Task
  • MCP Server Deployed on Render

๐Ÿ“Š Future Improvements

These are some aspects we didn't manage to implement due to time constraints

Security

  • Better OAuth and Token handling
  • Protection of endpoints

Features

  • Scaling to other platforms such as messages, phone calling
  • Inclusion of more advanced tools to extend functionality

๐Ÿ”— Links


Built with โค๏ธ by the SentinelAI Team Protecting inboxes, one email at a time ๐Ÿ›ก๏ธโœจ

About

Protect yourself

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 94.4%
  • Cython 2.2%
  • C 1.7%
  • C++ 1.4%
  • TypeScript 0.2%
  • XSLT 0.1%