Skip to content

SujaydRNSIT/2-Techies_Tech

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ RefundShield AI

Autonomous Refund Fraud Investigator

FastAPI Next.js OpenAI Razorpay

An intelligent multi-agent system that automatically investigates refund claims, detects fraud patterns using AI, and autonomously processes or rejects refunds via Razorpay.

Dashboard Preview Backend AI Model


πŸ“‹ Table of Contents


✨ Features

πŸ€– AI-Powered Investigation

  • Evidence Analysis: GPT-4 Vision analyzes damage evidence images
  • Fraud Detection: Detects AI-generated images, manipulation, and anomalies
  • Pattern Recognition: FAISS-based vector search for similar fraud cases

πŸ”’ Security & Verification

  • File Security: SafeDep-style file validation and scanning
  • URL Threat Detection: Gearsec-style malicious URL detection via VirusTotal
  • Merchant Verification: Crustdata API integration for company intelligence

πŸ’° Automated Refunds

  • Payment Processing: Razorpay API for instant refund execution
  • Risk-Based Decisions: Auto-approve (0-30), Manual review (31-70), Reject (71-100)
  • Customer Communication: Automated email responses via AI

πŸ“Š Observability

  • Event Streaming: S2.dev-style event logging
  • Multi-Agent Orchestration: Emergent AI-style agent coordination
  • Real-time Dashboard: Monitor all investigations

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           REFUNDSHIELD AI                                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚   Next.js    │───▢│   FastAPI        │───▢│   SQLite         β”‚          β”‚
β”‚  β”‚   Dashboard  │◀───│   Backend        │◀───│   Database       β”‚          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”‚                              β”‚                                              β”‚
β”‚           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                          β”‚
β”‚           β–Ό                  β–Ό                  β–Ό                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚  β”‚EvidenceAgent β”‚   β”‚SecurityAgent β”‚   β”‚MerchantAgent β”‚                   β”‚
β”‚  β”‚  (OpenAI)    β”‚   β”‚(SafeDep/VT)  β”‚   β”‚ (Crustdata)  β”‚                   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                   β”‚
β”‚         β”‚                  β”‚                  β”‚                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚  β”‚KnowledgeAgentβ”‚   β”‚  FraudAgent  β”‚   β”‚ RefundAgent  β”‚                   β”‚
β”‚  β”‚(Unsiloed AI) β”‚   β”‚(Risk Scorer) β”‚   β”‚  (Razorpay)  β”‚                   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                   β”‚
β”‚                             β”‚                                             β”‚
β”‚                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”                                    β”‚
β”‚                    β–Ό                 β–Ό                                    β”‚
β”‚            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                            β”‚
β”‚            β”‚ ReportAgent  β”‚  β”‚ResponseAgent β”‚                            β”‚
β”‚            β”‚              β”‚  β”‚ (Concierge)  β”‚                            β”‚
β”‚            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                            β”‚
β”‚                                                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Workflow

Claim Submission β†’ Evidence Analysis β†’ Image Search β†’ Security Scan β†’ 
Merchant Verification β†’ Knowledge Retrieval β†’ Fraud Scoring β†’ 
Refund Decision β†’ Payment Action β†’ Report Generation β†’ Customer Response

🎬 Demo

Fraud Score Gauge

Score Decision Color
0-30 βœ… APPROVED Green
31-70 ⏸ MANUAL REVIEW Yellow
71-100 ❌ REJECTED Red

Example Output

{
  "claim_id": "CLM_A1B2C3D4E5F6",
  "fraud_score": 12,
  "decision": "approved",
  "refund_id": "rfnd_FP8R8EGjGbPkVb",
  "risk_factors": [],
  "investigation_report": {
    "image_analysis": { "damage_detected": true, "ai_generated_probability": 5 },
    "security_scan": { "safe": true, "threats_found": [] },
    "merchant_verification": { "verified": true, "company_name": "Amazon" }
  }
}

πŸš€ Quick Start

Prerequisites

  • Python 3.9+
  • Node.js 18+
  • API Keys (optional - works in simulation mode):
    • OpenAI API Key (for image analysis)
    • Razorpay API Keys (for live refunds)
    • VirusTotal API Key (for URL scanning)

1-Minute Setup

# Clone repository
git clone <repository-url>
cd refundshield-ai

# Start Backend
cd backend
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt
# Edit .env with your OPENAI_API_KEY
cp .env.example .env
uvicorn main:app --reload

# Start Frontend (new terminal)
cd frontend
npm install
npm run dev

Access the application:


πŸ“¦ Installation

Backend Setup

cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Environment variables
cp .env.example .env
# Edit .env and add your API keys

# Run server
uvicorn main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup

cd frontend

# Install dependencies
npm install

# Run development server
npm run dev

# Build for production
npm run build
npm start

Environment Variables

Create backend/.env:

# Required for AI Analysis
OPENAI_API_KEY=sk-your_openai_api_key_here

# Optional - System simulates if not provided
RAZORPAY_KEY_ID=rzp_test_your_key_id
RAZORPAY_KEY_SECRET=your_key_secret
VIRUSTOTAL_API_KEY=your_virustotal_api_key
SERPAPI_API_KEY=your_serpapi_key
CRUSTDATA_API_KEY=your_crustdata_api_key

πŸ“‘ API Documentation

Submit Refund Claim

POST /submit-claim
Content-Type: multipart/form-data

order_id=ORDER123
merchant_name=Amazon
payment_id=pay_xxx
refund_amount=1000.00
claim_reason=Product damaged on delivery
image=<file>

Response:

{
  "claim_id": "CLM_A1B2C3D4E5F6",
  "fraud_score": 12,
  "decision": "approved",
  "refund_status": "processed",
  "refund_id": "rfnd_xxx",
  "investigation_report": { ... },
  "customer_response": "Dear Customer, Your refund..."
}

Get All Claims

GET /claims?limit=50

Get Event Logs (S2.dev Style)

GET /events?claim_id=xxx&event_type=xxx

Health Check

GET /health

Response:

{
  "status": "healthy",
  "agents": ["EvidenceAgent", "SecurityAgent", "MerchantAgent", ...]
}

πŸ§ͺ Testing

Using the Test File

A comprehensive test file with 10 scenarios is provided:

# View test cases
cat backend/test_inputs.txt

Quick Test via curl

# Test 1: Low Risk (Approved)
curl -X POST http://localhost:8000/submit-claim \
  -F "order_id=ORDER_001_LEGIT" \
  -F "merchant_name=Amazon" \
  -F "payment_id=pay_Amazon123" \
  -F "refund_amount=1299.00" \
  -F "claim_reason=Received damaged smartphone" \
  -F "image=@/path/to/photo.jpg"

# Test 2: High Risk (Rejected) - with suspicious URL
curl -X POST http://localhost:8000/submit-claim \
  -F "order_id=ORDER_002_FAKE" \
  -F "merchant_name=UnknownShop" \
  -F "payment_id=pay_Fraud999" \
  -F "refund_amount=4999.00" \
  -F "claim_reason=Visit http://bit.ly/suspicious for details" \
  -F "image=@/path/to/stock_photo.jpg"

Test Scenarios

# Scenario Expected Score Decision
1 Amazon + Real damage 10-25 βœ… APPROVED
2 AI-generated image 70-95 ❌ REJECTED
3 Suspicious URL 35-55 ⏸ MANUAL
4 Flipkart + Valid claim 10-20 βœ… APPROVED
5 Reused stock image 75-90 ❌ REJECTED

🀝 Sponsor Integrations

Sponsor Integration Status Description
Razorpay Payment Gateway βœ… Live + Simulated Execute refunds via Razorpay API
SafeDep File Security βœ… Simulated Validate file types and scan for threats
Gearsec URL Threat Detection βœ… Via VirusTotal Check URLs for malicious content
Crustdata Company Intelligence βœ… Simulated Verify merchant legitimacy
S2.dev Event Streaming βœ… Simulated Log all system events
Emergent AI Agent Orchestration βœ… Implemented Multi-agent coordination
Unsiloed AI Knowledge Retrieval βœ… FAISS-based Vector search for fraud patterns
Concierge Response Automation βœ… OpenAI-powered Generate customer emails

πŸ“Š Fraud Scoring System

Risk Factors

Factor Score Impact
AI-generated image detected +40
Image found online (reuse) +30
Suspicious URL detected +20
Unverified merchant +20
Similar fraud pattern found +20
Security threat detected +25
Image manipulation detected +35
Metadata anomaly +15

Decision Matrix

Score 0-30:   🟒 APPROVE  β†’ Process refund via Razorpay
Score 31-70:  🟑 MANUAL   β†’ Flag for human review
Score 71-100: πŸ”΄ REJECT   β†’ Deny refund, log fraud attempt

πŸ›‘οΈ Security Features

  • βœ… File type validation using magic numbers
  • βœ… Malicious file detection
  • βœ… URL reputation checking (VirusTotal API)
  • βœ… Suspicious pattern detection
  • βœ… Metadata anomaly detection
  • βœ… Image perceptual hashing
  • βœ… Reverse image search (SerpAPI)

πŸ›οΈ Project Structure

refundshield-ai/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py                    # FastAPI application
β”‚   β”œβ”€β”€ requirements.txt           # Python dependencies
β”‚   β”œβ”€β”€ .env.example              # Environment template
β”‚   β”œβ”€β”€ test_inputs.txt           # 10 test scenarios
β”‚   β”œβ”€β”€ agents/                   # 8 AI Agents
β”‚   β”‚   β”œβ”€β”€ base_agent.py         # Agent orchestration (Emergent AI)
β”‚   β”‚   β”œβ”€β”€ evidence_agent.py     # OpenAI Vision analysis
β”‚   β”‚   β”œβ”€β”€ security_agent.py     # SafeDep/Gearsec scanning
β”‚   β”‚   β”œβ”€β”€ merchant_agent.py     # Crustdata verification
β”‚   β”‚   β”œβ”€β”€ fraud_agent.py        # Risk scoring engine
β”‚   β”‚   β”œβ”€β”€ refund_agent.py       # Razorpay integration
β”‚   β”‚   β”œβ”€β”€ knowledge_agent.py    # Unsiloed AI (FAISS)
β”‚   β”‚   β”œβ”€β”€ report_agent.py       # Investigation reports
β”‚   β”‚   └── response_agent.py     # Concierge automation
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ event_logger.py       # S2.dev event streaming
β”‚   β”‚   └── image_search.py       # SerpAPI integration
β”‚   └── database/
β”‚       └── models.py             # SQLite models
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ pages/index.js            # Main dashboard
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ SponsorBadges.js      # Integration badges
β”‚   β”‚   β”œβ”€β”€ FraudScoreGauge.js    # Animated score display
β”‚   β”‚   β”œβ”€β”€ InvestigationReport.js # Report viewer
β”‚   β”‚   └── RecentClaims.js       # Claims history
β”‚   └── styles/globals.css        # Tailwind CSS
β”‚
└── README.md                     # This file

πŸ› οΈ Technologies Used

Backend

  • FastAPI - High-performance web framework
  • SQLAlchemy - ORM for database operations
  • OpenAI GPT-4 Vision - Image analysis
  • FAISS - Vector similarity search
  • Razorpay SDK - Payment processing

Frontend

  • Next.js 14 - React framework
  • Tailwind CSS - Utility-first styling
  • Axios - HTTP client
  • Lucide React - Icon library

AI/ML

  • GPT-4 Vision - Evidence analysis
  • ImageHash - Perceptual hashing
  • FAISS - Vector search
  • TikToken - Token counting

πŸ“ License

MIT License - See LICENSE file for details.


πŸ™ Acknowledgments

Built for the hackathon with:


πŸ“§ Contact

For questions or support, please open an issue on GitHub.

RefundShield AI - Making refund processing smarter, faster, and safer with AI. πŸš€

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors