Skip to content

About

RazorMind AI — Intelligent Payment Risk & Merchant Intelligence Platform for Razorpay Ecosystem

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

⚡ RazorMind AI — Intelligent Payment Risk & Merchant Intelligence Platform

Python FastAPI Scikit-Learn Docker Razorpay

"I designed and deployed an AI-powered FinTech intelligence platform that analyzes transaction risk, predicts payment failures, and generates actionable insights for merchants through a conversational interface."


🌟 Executive Overview & Razorpay Alignment

At Razorpay scale, payment processing is far more than moving money between accounts—it is about maximizing merchant Gross Merchandise Value (GMV) while minimizing involuntary churn and fraud loss.

RazorMind AI unifies three critical pillars of modern payment gateway infrastructure:

  1. Fraud Detection Engine (Razorpay Thirdwatch Equivalent): Real-time evaluation of transaction velocity, behavioral baseline deviations, geolocation mismatches, and IP proxies to score fraud probability and halt unauthorized charges.
  2. Payment Success Prediction & Smart Routing (Razorpay Optimizer Equivalent): Pre-transaction latency and bank downtime forecasting that dynamically recommends optimal fallback payment channels (e.g., automatically routing around SBI UPI timeouts to ICICI UPI or Card checkout).
  3. Conversational AI Merchant Assistant: Natural language query engine that breaks down complex payment telemetry into actionable merchant business insights (e.g. root-cause revenue drop analysis, RFM customer churn scoring, and fraud audit trails).

🏗️ System Architecture

                    ┌───────────────────────────────┐
                    │ Realistic FinTech Data Stream │
                    │ (UPI, Cards, NetBanking, etc.)│
                    └───────────────┬───────────────┘
                                    │
                                    ▼
                    ┌───────────────────────────────┐
                    │    SQL Database (SQLite /     │
                    │         PostgreSQL)           │
                    └───────────────┬───────────────┘
                                    │
            ┌───────────────────────┼───────────────────────┐
            ▼                       ▼                       ▼
    ┌───────────────┐       ┌───────────────┐       ┌───────────────┐
    │  Fraud Model  │       │ Failure Model │       │   Analytics   │
    │ (RF + Scorer) │       │(GBM + Router) │       │    Engine     │
    └───────┬───────┘       └───────┬───────┘       └───────┬───────┘
            │                       │                       │
            └───────────────────────┼───────────────────────┘
                                    ▼
                    ┌───────────────────────────────┐
                    │        FastAPI Backend        │
                    │   (REST APIs + Explanations)  │
                    └───────────────┬───────────────┘
                                    │
                                    ▼
                    ┌───────────────────────────────┐
                    │ AI Merchant Assistant Engine  │
                    │ (NL to FinTech Insights / LLM)│
                    └───────────────┬───────────────┘
                                    │
            ┌───────────────────────┴───────────────────────┐
            ▼                                               ▼
    ┌───────────────────────────────┐       ┌───────────────────────────────┐
    │  Interactive Web Dashboard    │       │     Streamlit Dashboard       │
    │  (Glassmorphism, Live Charts, │       │  (Rapid ML Prototyping &      │
    │   Simulator, Merchant Chat)   │       │   Data Science Exploration)   │
    └───────────────────────────────┘       └───────────────────────────────┘

📁 Repository Structure

razormind-ai/
│
├── data/
│   ├── raw/
│   │   ├── transactions.csv          # 6,000+ realistic multi-bank transactions
│   │   ├── merchants.csv             # Merchant categories & risk thresholds
│   │   └── customers.csv             # Customer behavioral profiles
│   └── generate_data.py              # FinTech synthetic data generator
│
├── notebooks/
│   ├── fraud_detection.ipynb         # EDA, class balance, Random Forest, ROC-AUC, XAI
│   ├── revenue_prediction.ipynb      # Bank downtime modeling, smart routing, RFM churn
│   └── generate_notebooks.py         # Automated notebook generation pipeline
│
├── backend/
│   ├── main.py                       # FastAPI entrypoint, CORS & static file mounting
│   ├── config.py                     # App configuration & settings
│   ├── database.py                   # SQLAlchemy engine & session factory
│   ├── models/
│   │   ├── db_models.py              # ORM entities (Transactions, Merchants, Disputes)
│   │   ├── schemas.py                # Pydantic request/response schemas
│   │   ├── fraud_model.py            # Fraud ML engine with explainability
│   │   ├── failure_model.py          # Payment success & smart fallback router
│   │   └── analytics_engine.py       # SQL aggregation & churn metrics
│   ├── routes/
│   │   ├── fraud.py                  # /api/fraud/evaluate & /api/fraud/anomalies
│   │   ├── prediction.py             # /api/predict/success & /api/predict/banks
│   │   ├── analytics.py              # /api/analytics/overview, trends, churn
│   │   ├── assistant.py              # /api/assistant/chat
│   │   └── transactions.py           # /api/transactions (filter & paginate)
│   └── services/
│       ├── ai_assistant_service.py   # NLP intent classifier & merchant insights
│       └── model_registry.py         # Model loading, caching & training pipeline
│
├── database/
│   ├── schema.sql                    # Production DDL for PostgreSQL / SQLite
│   └── init_db.py                    # Database creation & seeder
│
├── frontend/
│   ├── index.html                    # Glassmorphism Web App (Razorpay Dark Theme)
│   ├── styles.css                    # Razorpay palette, micro-animations & layout
│   ├── app.js                        # Chart.js, Simulator, Router, & Assistant chat
│   └── streamlit_app.py              # Streamlit companion app
│
├── Dockerfile                        # Multi-stage production container
├── docker-compose.yml                # Full-stack container orchestration
├── requirements.txt                  # Python dependencies
├── .env.example                      # Template environment variables
└── README.md                         # Comprehensive documentation & interview guide

🔬 The Three Core Modules

1. Real-Time Fraud Detection (Razorpay Thirdwatch Equivalent)

  • Algorithm: Balanced Ensemble Random Forest Classifier + Feature-Engineered Risk Heuristics.
  • Key Risk Indicators:
    • velocity_1h & velocity_24h: Rapid card testing / brute force spikes.
    • amount_to_avg_ratio: Deviation from customer's 30-day baseline (e.g. 4.5x surge).
    • geo_distance_km: Cross-state / cross-border shipping vs. billing discrepancies.
    • is_vpn_or_proxy: Detection of residential proxies or anonymity services.
    • hour_of_day: Nocturnal attacks (1:00 AM – 5:00 AM).
  • Explainability (XAI): Every evaluation returns human-readable decision factors and a policy recommendation (APPROVE, CHALLENGE_2FA, REVIEW, DECLINE).

2. Payment Failure Prediction & Smart Routing (Razorpay Optimizer)

  • Algorithm: Gradient Boosting Classifier tuned on bank failure patterns and latency.
  • The Problem It Solves: When an issuer bank (e.g., SBI or HDFC) suffers a switch failure, merchants experience up to 30% drop in checkout conversion.
  • Dynamic Rerouting:
    • Predicts failure risk before gateway handoff.
    • If predicted failure $> 25%$, the optimizer scans alternate healthy channels (e.g., ICICI UPI or Card checkout) and recommends an immediate switch, generating up to +38% conversion uplift.

3. Conversational AI Merchant Assistant

  • Translates merchant business questions into quantitative insights with actionable recommendations:
    • "What caused my revenue to decrease this week?" $\rightarrow$ Decomposes drop into issuer bank outages, checkout drops, and fraud blocks.
    • "Which customers are most likely to stop purchasing?" $\rightarrow$ Computes Recency, Frequency, and Monetary (RFM) churn scoring.
    • "Show me unusual transactions." $\rightarrow$ Fetches real-time high-risk anomalies with risk scores and indicators.

📊 Machine Learning Benchmark Performance

Model Target Primary Metric Baseline RazorMind AI
Fraud Detection Engine is_fraud (0 or 1) ROC-AUC 0.74 (Logistic) 0.932 (RF Balanced)
Fraud Detection Engine is_fraud PR-AUC 0.31 0.841
Payment Success Predictor is_failed (0 or 1) ROC-AUC 0.68 0.895 (GBM)
Smart Routing Uplift Conversion Success % 71.4% (Degraded) 94.8% (+23.4% Uplift)

🚀 Quickstart Guide

Option 1: Running Locally with Python

# 1. Clone the repository
git clone https://github.com/your-username/razormind-ai.git
cd razormind-ai

# 2. Install dependencies
pip install -r requirements.txt

# 3. Generate data and seed database
python data/generate_data.py
python database/init_db.py

# 4. Generate Jupyter notebooks
python notebooks/generate_notebooks.py

# 5. Start the FastAPI Backend & Web Dashboard
python -m uvicorn backend.main:app --reload --port 8000
  • Open http://localhost:8000 in your browser for the Interactive Glassmorphism Dashboard.
  • Open http://localhost:8000/docs for the Interactive Swagger API Documentation.
  • (Optional) Launch the Streamlit dashboard:
    streamlit run frontend/streamlit_app.py

Option 2: Running with Docker Compose

# Build and start all services
docker-compose up --build
  • Web Dashboard: http://localhost:8000
  • Streamlit Companion: http://localhost:8501

📡 API Reference Summary

Method Endpoint Description
POST /api/fraud/evaluate Evaluates real-time fraud probability, risk tier, and explainability factors
GET /api/fraud/anomalies Surfaces current high-risk suspicious transactions
POST /api/predict/success Predicts failure risk and returns smart fallback route with conversion uplift
GET /api/predict/banks Live bank gateway health metrics and success rates
GET /api/analytics/overview High-level merchant KPIs (GMV, Success Rate, Prevented Fraud)
GET /api/analytics/trends 14-day revenue and network success rate timeline
GET /api/analytics/churn RFM customer churn prediction cohort
POST /api/assistant/chat Conversational Merchant Assistant natural language query interface
GET /api/transactions Filterable and paginated real-time transaction stream

🎯 Razorpay Internship Interview Talking Points

Use these pointers during technical and product interviews:

  1. "Why did you build RazorMind AI?"

    "I wanted to tackle the core engineering challenges of payment platforms like Razorpay: maximizing transaction conversion while minimizing fraud loss. Rather than just training an isolated model, I built a production-style architecture integrating fraud scoring, smart dynamic fallback routing (similar to Razorpay Optimizer), and a conversational assistant to empower merchants with instant financial analytics."

  2. "How do you handle severe class imbalance in fraud?"

    "In payment streams, fraud occurs in only 2-4% of transactions. Using raw accuracy is misleading. I applied stratified sampling, cost-sensitive class balancing (class_weight='balanced'), and evaluated models using Precision-Recall curves and ROC-AUC. I also tuned the decision threshold to 0.40 to capture over 92% of fraudulent attempts while avoiding excessive false declines on legitimate customers."

  3. "How does the Smart Fallback Router work?"

    "When an issuer bank's success rate degrades (for example, during an unscheduled downtime or latency spike), our Gradient Boosting engine identifies the elevated failure probability. The optimizer evaluates alternative payment rails (such as ICICI UPI or Card checkout) and recommends an automated switch, preventing cart abandonment and saving merchant GMV."

  4. "How does this scale to production?"

    "The backend uses asynchronous FastAPI endpoints with sub-25ms inference latency. Feature extraction pipelines use vectorized NumPy/Pandas transforms and pre-serialized Scikit-Learn pipelines. In high-scale production, models would be served via Triton or ONNX Runtime behind Redis cache clusters."


📄 License & Attribution

Designed and developed for the Razorpay Internship Assessment. Inspired by the architectures of Razorpay Thirdwatch, Razorpay Optimizer, and Razorpay Magic Checkout.

About

RazorMind AI — Intelligent Payment Risk & Merchant Intelligence Platform for Razorpay Ecosystem

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages