The Revenue Risk Detection Platform forms the front door of the LeakGuard financial recovery engine. It is responsible for:
- Client SDK Telemetry Ingestion: Capturing fail-open telemetry streams (checkout opened, payment method selected, user drop-offs) directly from the merchant's checkout frontend.
- Unified Payment Session Management: Creating tracked payment sessions bound to Razorpay Orders and initializing durable
RevenueObligationrecords. - Authentic Razorpay Webhook Ingestion: Processing
payment.failed,payment.authorized,payment.captured, andorder.paidwebhooks with strict HMAC SHA-256 signature verification. - Outbox Event Emission: Persisting transactionally safe
PAYMENT_FAILURE_RISKoutbox events to trigger downstream diagnosis & orchestration workers. - Merchant Control Plane & Observability APIs: Serving live metrics (
/v1/recovery-metrics), recovery statuses (/v1/recoveries), merchant emergency stop kill-switches (/v1/recoveries/:riskEventId/stop), and audit timeline logs (/v1/audits). - Merchant Control Dashboard: A high-impact React portal providing real-time visibility into active recovery workflows, measured revenue recovered, and complete chronological audit trails.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FRONTEND / CLIENT SDK โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Client Checkout Browser โ โ LeakGuard Merchant Dashboard โ โ
โ โ (Fail-Open SDK Telemetry) โ โ (Live Controls & Audit Logs) โ โ
โ โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ
โ Telemetry Events โ Control & Metrics APIs
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PLATFORM API SERVER (Express / Node.js) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ Payment Session & โ โ Razorpay Webhook โ โ Merchant Control โ โ
โ โ Obligation Service โ โ HMAC Ingestion Engine โ โ Plane & Metrics โ โ
โ โโโโโโโโโโโโโฌโโโโโโโโโโโโ โโโโโโโโโโโโโฌโโโโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PERSISTENCE & EVENT BUS โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Cloud Neon PostgreSQL (Prisma ORM) โ โ Upstash Redis (BullMQ Queues) โ โ
โ โ - RevenueObligation (Truth) โ โ - risk-event-ingestion-queue โ โ
โ โ - RiskEvent & Outbox โ โ - execution-measure-queue โ โ
โ โ - RecoveryControl & RecoveryAudit โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
platform/: Production Express TypeScript REST API server, Prisma ORM schema, BullMQ queues, and route controllers.frontend/: Modern Vite + React 19 + Tailwind CSS merchant dashboard application.sdk/: Lightweight, fail-open TypeScript browser SDK package.
- Core Runtime: Node.js v20+, TypeScript (Strict ES2022)
- API Framework: Express.js
- Database & ORM: PostgreSQL (Neon Cloud with PgBouncer mode), Prisma ORM v5.22
- Queueing & Event Bus: BullMQ v5, Redis (Upstash)
- Frontend Dashboard: React 19, Vite 8, Tailwind CSS v4, Lucide Icons
- Security: HMAC SHA-256 signature verification, AES-256 credential encryption, CORS protection
POST /v1/merchantsโ Register merchant configuration, margin rates, and Razorpay API key references.GET /v1/merchants/:idโ Retrieve active merchant policies and economic configurations.
POST /v1/payments/sessionโ Create unified payment session, bind Razorpay order, and generatepaymentAttemptId.POST /v1/sdk/eventsโ Ingest asynchronous, fail-open browser telemetry events.
POST /v1/webhooks/razorpayโ Validatex-razorpay-signatureheader, updateRevenueObligationstate, and pushPAYMENT_FAILURE_RISKevents to the outbox queue.
GET /v1/recoveriesโ List active and historical recovery workflows for a merchant.GET /v1/recoveries/:riskEventIdโ Fetch detailed recovery inspection view (attempts, outcomes, control state, audit trail).POST /v1/recoveries/:riskEventId/stopโ Merchant Emergency Stop Kill-Switch. Halts recovery workflow in real-time.GET /v1/recovery-metricsโ Measured Revenue Metrics. Aggregate total revenue at risk, actual measured recovered revenue, recovery rate %, and channel breakdowns.GET /v1/auditsโ Fetch chronological, append-only audit trail logs.
- Node.js: v20.x or higher
- PostgreSQL: Neon cloud instance or local PostgreSQL (v14+)
- Redis: Upstash cloud instance or local Redis (v6+)
# Navigate to platform directory
cd RevenueRiskDetectionSDK/platform
# Install dependencies
npm install
# Configure Environment Variables (.env)
cp .env.example .envPORT=3000
NODE_ENV=development
DATABASE_URL="postgresql://user:password@ep-sample-neon.tech/neondb?sslmode=require"
INTERVENTION_REDIS_URL="redis://127.0.0.1:6379"
MASTER_SECRET_KEY="super_secret_master_key_for_aes_encryption"# Push Prisma Database Schema to PostgreSQL
npx prisma db push
# Generate Prisma Client
npx prisma generate
# Build TypeScript Code
npm run build
# Start Development Server
npm run devThe Platform API server will start on http://localhost:3000.
# Navigate to frontend directory
cd RevenueRiskDetectionSDK/frontend
# Install dependencies
npm install
# Build & Run Vite Dev Server
npm run devThe Merchant Dashboard will start on http://localhost:5173.
To run the end-to-end Railway production suite verifying session creation, HMAC signature verification, database persistence, and API routes:
cd RevenueRiskDetectionSDK/platform
npx tsx test_railway_production.ts