An end-to-end agentic e-commerce shopping assistant built with LangGraph, FastAPI, Google Gemini AI, High-Performance MongoDB MCP Connector, and RazorpayX Composite Payout API. Featuring real-time intent routing, multithreaded fast-path database execution, deterministic rate-limit fallbacks, dynamic merchant bank resolution, and a luxury obsidian dark-mode web UI.
- π€ Multi-Agent LangGraph Pipeline: Intelligent multi-turn routing across
intent_classifier,buy_pipeline,inquiry_pipeline, andpolite_rejectnodes. - β‘ Sub-Millisecond Recommendation Engine: High-throughput Item-to-Item recommendation system (
< 0.5 msSLA) backed by precomputed co-occurrence matrices and MongoDB catalog hydration. - ποΈ Pre-Checkout "Frequently Bought Together" Upsell: Interactive pre-payment modal that presents personalized add-ons with direct "Add to Order" options before finalizing Razorpay payments.
- β‘ High-Performance Multithreaded Database MCP:
mongodb_connector.pypowered by a dedicatedThreadPoolExecutorfast-path executing sub-5ms PyMongo queries with full stdio MCP protocol fallback. - π‘οΈ Deterministic Rate-Limit Resilience: Fallback keyword/regex extractors, multi-tier search logic, and default intro formatting that keep the pipeline 100% continuous during LLM rate limits (
429 RESOURCE_EXHAUSTED). - π¦ Dynamic RazorpayX Vendor Payouts: Real-time resolution of merchant banking details (Account Number, IFSC, Merchant Name, Email, Phone) from MongoDB
Merchant_Infocollections to trigger automated IMPS payouts. - π³ Complete Merchant Payout Summary: Detailed transaction cards displaying complete merchant credentials, order title, INR amount, Payout ID, UTR, and status upon payment completion.
- π Full-Stack Observability & Audit Trail: Structured logging across all pipeline nodes (
[NODE: intent_classifier],[NODE: buy_pipeline],[RECOMMENDATIONS API],[RAZORPAY MCP],[PAYMENT API]). - π¨ Modern Obsidian & Metallic UI: Luxury dark-mode theme with white typography, vibrant brand accents, real-time SSE token streaming, and an authentic RazorpayX Checkout Modal.
- π Offline Evaluation Suite: Integrated
DeepEvaltesting framework with CSV-formatted golden datasets (evals/golden_dataset/).
flowchart TD
UI[Frontend Web UI / User Input] -->|POST /api/chat| API[FastAPI Application]
API -->|SSE Stream| Graph[LangGraph Orchestrator]
Graph --> NodeIntent[Intent Classifier]
NodeIntent -->|intent = buy| NodeBuy[Buy Pipeline]
NodeIntent -->|intent = inquiry| NodeInquiry[Inquiry Pipeline]
NodeIntent -->|intent = general| NodeReject[Polite Reject Node]
NodeBuy -->|Multithreaded PyMongo / MCP| DB[(MongoDB: Products Catalog)]
NodeInquiry -->|Multithreaded PyMongo / MCP| DB
UI -->|Click Pay via Razorpay| RecModal[Pre-Checkout Upsell Modal]
RecModal -->|GET /api/recommendations| RecEngine[Item-to-Item Recommender <0.5ms]
RecEngine -->|Hydrate Catalog| DB
RecModal -->|Proceed to Checkout| RazorpayUI[RazorpayX Checkout Modal]
RazorpayUI -->|GET /api/merchant/info| API
RazorpayUI -->|POST /api/payment/create-order| RazorpayMCP[RazorpayX Payout MCP]
RazorpayMCP -->|Resolve Merchant Credentials| DB
RazorpayMCP -->|Execute Composite Payout| RazorpayAPI[RazorpayX API]
RazorpayMCP -->|Log Transaction| DB
To optimize responsiveness, accuracy, and API quota usage, tasks are tiered by complexity across Google Gemini models (GOOGLE_API_KEY):
| Task Tier | Model | Pipeline Component |
|---|---|---|
| Lite | gemini-3.5-flash-lite |
Intent classification, MongoDB MQL generation |
| Balanced | gemini-3.6-flash |
Preference extraction, general fallback handling |
| Pro | gemini-3.7-flash |
Product reranking, detailed inquiry Q&A response generation |
Razorpay_Demo/
βββ backend/
β βββ app.py # FastAPI web server, recommendation & payment endpoints
β βββ main.py # LangGraph state machine & thread checkpointer
β βββ agents/
β β βββ state.py # TypedDict shared state definition (ChatState)
β β βββ intent.py # Intent classifier node (LLM + Regex Fallback)
β β βββ buy.py # Product preference gatherer, query generator, executor & reranker
β β βββ inquery.py # Product inquiry resolver node
β β βββ reject.py # Out-of-domain & order confirmation handler
β β βββ llm.py # Gemini LLM tiering configuration
β βββ mcp/
β βββ database/
β β βββ mongodb_connector.py # Multithreaded fast-path PyMongo + stdio MCP client
β βββ payment/
β βββ razorpay_mcp.py # RazorpayX payout connector & merchant bank resolver
βββ recommendation_engine/
β βββ model/
β β βββ recommender.py # Sub-millisecond Item-to-Item recommender module
β β βββ train_model.py # Co-occurrence index training script
β β βββ model_artifacts.pkl # Pre-computed lookup index
β βββ dataset/
β βββ raw_transactions.csv # Market basket transactions dataset
βββ frontend/
β βββ index.html # Main web interface
β βββ style.css # Luxury obsidian black & grey design system
β βββ app.js # Pre-checkout recommendation modal, streaming, & Razorpay UI
βββ evals/
β βββ golden_dataset/ # CSV evaluation benchmark datasets
β βββ evals_pipelines/ # DeepEval automated test runners
β βββ conftest.py # Pytest fixtures & dataset loaders
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
Clone the repository and set up a Python 3.12+ virtual environment:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtCreate a .env file in the root directory:
GOOGLE_API_KEY=your_gemini_api_key
MDB_MCP_CONNECTION_STRING=your_mongodb_connection_string
MONGODB_DATABASE=Merchant_1
RAZORPAY_KEY_ID=your_razorpay_key_id
RAZORPAY_KEY_SECRET=your_razorpay_key_secret
RAZORPAY_ACCOUNT_NUMBER=your_razorpay_account_numberStart the FastAPI application with Uvicorn:
.venv/bin/python -m uvicorn backend.app:app --reload --port 8000Access the application in your browser:
- Web UI:
http://localhost:8000 - API Documentation:
http://localhost:8000/docs
- Product Recommendation: Products returned from MongoDB catalog queries carry associated
merchant_idmetadata. - Merchant Detail Resolution: When a user clicks Proceed to Checkout, the frontend queries
/api/merchant/info?merchant_id=.... The backend dynamically fetches the merchant's business name, bank account number, IFSC code, email, and phone from theMerchant_Infocollection. - RazorpayX Checkout Modal: An authentic RazorpayX interface renders beneficiary credentials, product title, and INR amount.
- Payout Execution: Clicking Pay via Razorpay triggers
/api/payment/create-order, invokingRazorpayMCPConnector.create_payout()to execute an instant IMPS transfer via RazorpayX APIs. - Sanitized Narration: Narration text is automatically sanitized and truncated to max 30 alphanumeric characters (
clean_narration), satisfying Razorpay API constraints. - Detailed Payout Summary: Payment completion renders a comprehensive card displaying product title, transferred amount (βΉ), Payout ID, UTR, status, merchant name, account number, IFSC code, email, and phone.
Run automated offline evaluation metrics using DeepEval and pytest:
pytest evals/evals_pipelines/ -vBuilt for Demonstration & Development β ShopSmart AI Pipeline.