Simprio Platform Integration Plan
Overview
This document outlines the comprehensive integration plan for MongoDB, PostgreSQL, Razorpay, Deployment Strategy, and Pending Work across the three applications:
- simprio-backend - Node.js/Express API (Port 4000)
- Admin-app - Next.js Admin Panel (Port 3000)
- Partener-app - React Native/Expo Partner App
- Customer-app - React Native/Expo Customer App
Table of Contents
- Database Architecture
- Razorpay Integration
- Backend Missing Integrations
- Admin-app Integration Status
- Partener-app Integration Status
- Deployment Strategy
- Implementation Roadmap
1. Database Architecture
1.1 PostgreSQL (Primary Database) ✅ DONE
Status: Fully Configured via Prisma
Prisma Schema Coverage (46 Models):
| Category | Models |
|---|---|
| Auth/Users | User, Address, AdminRole, AdminStaff |
| Partners | Partner |
| Food | Restaurant, Dish |
| Products | Category, Brand, Product, WishlistItem |
| Health | Doctor, Appointment |
| Ride | Driver, RideBooking |
| Travel | TravelBooking |
| Events | Event, Ticket |
| Services | ServiceProvider, ServiceBooking |
| Digital | DigitalBiller, DigitalTransaction |
| Orders | Order, OrderItem |
| Payments | WalletTransaction, CoinTransaction |
| Content | Banner, Campaign, Coupon |
| Loyalty | WalletBonus, LoyaltyConfig |
| Subscriptions | SubscriptionPlan, PartnerSubscription |
| Zoning | Zone, BusinessModule, ZoneModule |
| Reviews | Review |
| Notifications | Notification |
| Chat | ChatMessage |
| Payouts | Payout |
1.2 MongoDB (Secondary Database) - TODO
Recommended Use Cases:
- Audit Logs storage
- Session/Token storage
- Analytics & Logs (non-relational data)
- Chat/Message history
- API request/response logs
- Error tracking
Implementation:
yaml
# docker-compose.yml
mongo:
image: mongo:7
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
environment:
MONGO_INITDB_ROOT_USERNAME: simprio
MONGO_INITDB_ROOT_PASSWORD: mongo_dev_pass
Connection String:
mongodb://simprio:mongo_dev_pass@localhost:27017/simprio_analytics
1.3 Redis (Caching) - TODO
Use Cases:
- Session caching (express-session)
- API response caching
- Rate limiting storage
- Real-time data (driver locations, live orders)
- Pub/Sub for real-time features
yaml
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis_data:/data
2. Razorpay Integration
2.1 Current Implementation Status ✅ PARTIAL
✅ Already Implemented (Backend):
| Endpoint | Method | Status |
|---|---|---|
/api/v1/payments/razorpay/create-order | POST | ✅ Done |
/api/v1/payments/razorpay/verify | POST | ✅ Done |
/api/v1/payments/razorpay/refund | POST | ✅ Done |
/api/v1/payments/wallet/add | POST | ✅ Done |
/api/v1/payments/wallet/pay | POST | ✅ Done |
/api/v1/payments/history/:userId | GET | ✅ Done |
/api/v1/wallet/bonus | GET/POST | ✅ Done |
/api/v1/wallet/loyalty | GET/PATCH | ✅ Done |
2.2 Pending Implementation
| Feature | Priority | Status | Notes |
|---|---|---|---|
| Webhook Handler | HIGH | TODO | Critical for production payment sync |
| UPI Integration | MEDIUM | TODO | Additional payment method |
| Split Payments (Partner Payouts) | HIGH | TODO | Transfer to partner bank accounts |
| Saved Cards | LOW | TODO | Tokenization for repeat customers |
| Recurring Payments | MEDIUM | TODO | Subscription model |
2.3 Webhook Handler Implementation (TODO)
typescript
// src/routes/webhooks.routes.ts
import { Router } from 'express'
import crypto from 'crypto'
import { env } from '../config/env'
import { prisma } from '../config/db'
const router = Router()
// Razorpay Webhook
router.post('/razorpay', async (req, res) => {
const signature = req.headers['x-razorpay-signature']
const payload = JSON.stringify(req.body)
// Verify webhook signature
const expectedSignature = crypto
.createHmac('sha256', env.razorpay.keySecret)
.update(payload)
.digest('hex')
if (signature !== expectedSignature) {
return res.status(400).json({ error: 'Invalid signature' })
}
const event = req.body.event
const payment = req.body.payload.payment.entity
switch (event) {
case 'payment.captured':
// Find order by razorpayOrderId and update paymentStatus to success
await prisma.order.updateMany({
where: { razorpayOrderId: payment.order_id },
data: { paymentStatus: 'success', razorpayPaymentId: payment.id }
})
break
case 'payment.failed':
// Handle failed payment - notify user, log event
await prisma.order.updateMany({
where: { razorpayOrderId: payment.order_id },
data: { paymentStatus: 'failed' }
})
break
case 'refund.created':
// Update refund status in order
const refund = req.body.payload.refund.entity
await prisma.order.updateMany({
where: { razorpayPaymentId: refund.payment_id },
data: { paymentStatus: 'refunded' }
})
break
case 'order.paid':
// Additional order processing
break
}
res.json({ received: true })
})
export default router
2.4 Partner Payouts Implementation (TODO)
typescript
// src/routes/payouts.routes.ts
import { Router } from 'express'
import Razorpay from 'razorpay'
import { authenticate, requireAdmin, AuthRequest } from '../middleware/auth'
import { prisma } from '../config/db'
import { env } from '../config/env'
const router = Router()
router.use(authenticate)
const razorpay = new Razorpay({
key_id: env.razorpay.keyId,
key_secret: env.razorpay.keySecret
})
// Create bank account for partner (one-time)
router.post('/accounts', requireAdmin, async (req: AuthRequest, res, next) => {
try {
const { partnerId, bankCode, accountNumber, accountName, ifscCode } = req.body
const bankAccount = await razorpay.fundAccounts.create({
account_type: 'bank_account',
bank_account: {
ifsc_code: ifscCode,
name: accountName,
account_number: accountNumber
},
notes: { partner_id: partnerId }
})
// Store fundAccountId in partner record
await prisma.partner.update({
where: { id: partnerId },
data: { bankAccount: { fundId: bankAccount.id, ...req.body } }
})
res.json({ fundAccountId: bankAccount.id })
} catch (err) { next(err) }
})
// Create payout to partner
router.post('/create', requireAdmin, async (req: AuthRequest, res, next) => {
try {
const { partnerId, amount, orderId, description } = req.body
const partner = await prisma.partner.findUnique({ where: { id: partnerId } })
if (!partner?.bankAccount) {
return res.status(400).json({ error: 'Partner bank account not configured' })
}
const fundAccountId = partner.bankAccount.fundId
const transfer = await razorpay.transfers.create({
amount: Math.round(amount * 100),
currency: 'INR',
account: fundAccountId,
settled_at: Math.floor(Date.now() / 1000) + 86400, // Next day
notes: {
order_id: orderId,
partner_id: partnerId,
description
}
})
// Create payout record
await prisma.payout.create({
data: {
partnerId,
amount,
status: 'pending',
reference: transfer.id
}
})
res.json(transfer)
} catch (err) { next(err) }
})
// List all payouts
router.get('/list', requireAdmin, async (req: AuthRequest, res, next) => {
try {
const payouts = await prisma.payout.findMany({
include: { partner: { include: { user: true } } },
orderBy: { createdAt: 'desc' }
})
res.json(payouts)
} catch (err) { next(err) }
})
// Partner withdrawal request
router.post('/withdraw', async (req: AuthRequest, res, next) => {
try {
const { amount } = req.body
const partner = await prisma.partner.findUnique({ where: { userId: req.user!.userId } })
if (!partner) {
return res.status(404).json({ error: 'Partner not found' })
}
if (!partner.bankAccount) {
return res.status(400).json({ error: 'Bank account not configured' })
}
// Create withdrawal request (admin will process)
await prisma.payout.create({
data: {
partnerId: partner.id,
amount,
status: 'requested'
}
})
res.json({ message: 'Withdrawal request submitted' })
} catch (err) { next(err) }
})
export default router
3. Backend Missing Integrations
3.1 API Routes - Current vs Missing
Current Backend Routes (23 route files):
| Route File | Status | Endpoints Count |
|---|---|---|
| auth.routes.ts | ✅ Complete | ~5 |
| users.routes.ts | ✅ Complete | ~8 |
| orders.routes.ts | ✅ Complete | ~6 |
| payments.routes.ts | ⚠️ Partial | 7 (missing webhook, payouts) |
| wallet.routes.ts | ✅ Complete | ~10 |
| notifications.routes.ts | ✅ Complete | ~5 |
| partner.routes.ts | ⚠️ Partial | ~8 |
| food.routes.ts | ⚠️ Partial | ~6 |
| products.routes.ts | ⚠️ Partial | ~5 |
| shopping.routes.ts | ⚠️ Partial | ~4 |
| health.routes.ts | ⚠️ Partial | ~5 |
| ride.routes.ts | ⚠️ Partial | ~6 |
| travel.routes.ts | ⚠️ Partial | ~4 |
| events.routes.ts | ⚠️ Partial | ~4 |
| services.routes.ts | ⚠️ Partial | ~4 |
| digital.routes.ts | ⚠️ Partial | ~3 |
| wishlist.routes.ts | ✅ Complete | ~3 |
| admin.routes.ts | ⚠️ Partial | ~10 |
| zones.routes.ts | ✅ Complete | ~5 |
| modules.routes.ts | ✅ Complete | ~4 |
| campaigns.routes.ts | ✅ Complete | ~5 |
| dispatch.routes.ts | ⚠️ Partial | ~4 |
| platform.routes.ts | ⚠️ Partial | ~4 |
| uploads.routes.ts | ✅ Complete | ~2 |
3.2 Missing Backend Routes
| Route | Method | Description | Status |
|---|---|---|---|
/webhooks/razorpay | POST | Payment webhook handler | TODO |
/webhooks/payment | POST | Generic payment events | TODO |
/payouts | * | Partner payout management | TODO |
/payouts/accounts | POST | Create partner bank account | TODO |
/payouts/create | POST | Initiate transfer to partner | TODO |
/payouts/list | GET | List all payouts | TODO |
/payouts/withdraw | POST | Partner withdrawal request | TODO |
/reports/orders | GET | Order reports with filters | TODO |
/reports/revenue | GET | Revenue reports | TODO |
/reports/partners | GET | Partner performance reports | TODO |
/reports/users | GET | User analytics reports | TODO |
/chat/messages | GET/POST | Chat message history | TODO |
/chat/send | POST | Send new message | TODO |
/search/orders | POST | Advanced order search | TODO |
/search/products | POST | Product search with filters | TODO |
/search/partners | POST | Partner search | TODO |
/analytics/dashboard | GET | Dashboard analytics data | TODO |
/analytics/realtime | GET | Real-time metrics | TODO |
/notifications/send | POST | Send push notification | TODO |
/settings/app | GET/PATCH | App configuration | TODO |
/settings/payment | GET/PATCH | Payment gateway settings | TODO |
3.3 Backend Services - Missing
| Service | Description | Status |
|---|---|---|
analytics.service.ts | Analytics calculations | TODO |
payout.service.ts | Payout processing logic | TODO |
report.service.ts | Report generation | TODO |
chat.service.ts | Chat message handling | TODO |
search.service.ts | Advanced search logic | TODO |
geo.service.ts | Geolocation calculations | TODO |
4. Admin-app Integration Status
4.1 Pages Created vs API Connected
| Page | Path | API Connected | Status |
|---|---|---|---|
| Dashboard | (dashboard)/page.tsx | ⚠️ Partial | Mock data |
| Users | (dashboard)/users/page.tsx | ❌ | No API |
| User Details | (dashboard)/users/[id]/page.tsx | ❌ | No API |
| Orders | (dashboard)/orders/page.tsx | ⚠️ Partial | GET only |
| Order Details | (dashboard)/orders/[id]/page.tsx | ❌ | No API |
| Partners | (dashboard)/partners/page.tsx | ⚠️ Partial | GET only |
| Partner Details | (dashboard)/partners/[id]/page.tsx | ❌ | No API |
| Delivery Men | (dashboard)/partners/deliverymen/page.tsx | ❌ | No API |
| Catalog - Products | (dashboard)/catalog/products/page.tsx | ❌ | No API |
| Catalog - Categories | (dashboard)/catalog/categories/page.tsx | ❌ | No API |
| Finance - Overview | (dashboard)/finance/page.tsx | ❌ | No API |
| Finance - Payouts | (dashboard)/finance/payouts/page.tsx | ❌ | No API |
| Finance - Reports | (dashboard)/finance/reports/page.tsx | ❌ | No API |
| Analytics | (dashboard)/analytics/page.tsx | ❌ | No API |
| Marketing - Campaigns | (dashboard)/marketing/campaigns/page.tsx | ❌ | No API |
| Marketing - Coupons | (dashboard)/marketing/coupons/page.tsx | ❌ | No API |
| Marketing - Banners | (dashboard)/marketing/banners/page.tsx | ❌ | No API |
| Platform - Roles | (dashboard)/platform/roles/page.tsx | ❌ | No API |
| Platform - Modules | (dashboard)/settings/modules/page.tsx | ❌ | No API |
| Platform - Commission | (dashboard)/platform/commission/page.tsx | ❌ | No API |
| Platform - Subscriptions | (dashboard)/platform/subscriptions/page.tsx | ❌ | No API |
| Zones | (dashboard)/settings/zones/page.tsx | ❌ | No API |
| Notifications | (dashboard)/notifications/page.tsx | ❌ | No API |
| Settings - Business | (dashboard)/settings/business/page.tsx | ❌ | No API |
| Settings - Third Party | (dashboard)/settings/third-party/page.tsx | ❌ | No API |
4.2 Admin-app Missing Integrations
| Feature | Priority | Frontend Status | Backend Status |
|---|---|---|---|
| Orders CRUD | HIGH | ⚠️ GET only | ✅ Done |
| Partner Approval | HIGH | ⚠️ Partial | ✅ Done |
| Partner Details View | HIGH | ❌ Missing | ✅ Done |
| Payment Management | HIGH | ❌ Missing | ⚠️ Partial |
| Analytics Charts | MEDIUM | ⚠️ Mock data | ❌ Missing |
| Banner Management | MEDIUM | ⚠️ Page exists | ✅ Done |
| Coupon Management | MEDIUM | ⚠️ Page exists | ✅ Done |
| Payout Management | HIGH | ❌ Missing | ❌ Missing |
| Reports Export | LOW | ❌ Missing | ❌ Missing |
| Settings CRUD | MEDIUM | ❌ Missing | ❌ Missing |
| Zone Management | MEDIUM | ⚠️ Page exists | ✅ Done |
| Module Toggle | MEDIUM | ⚠️ Page exists | ✅ Done |
| Commission Config | MEDIUM | ❌ Missing | ✅ Done |
| Subscription Plans | MEDIUM | ❌ Missing | ✅ Done |
| User Wallet Management | MEDIUM | ❌ Missing | ✅ Done |
| Loyalty Config | MEDIUM | ❌ Missing | ✅ Done |
| Staff Management | LOW | ❌ Missing | ✅ Done |
| Role Permissions | LOW | ❌ Missing | ✅ Done |
4.3 Admin-app API Calls Needed
typescript
// Example API integration pattern needed
// Orders - Full CRUD
GET /api/v1/orders?page=1&limit=20&status=pending
GET /api/v1/orders/:id
PATCH /api/v1/orders/:id/status
DELETE /api/v1/orders/:id
// Partners - Full Management
GET /api/v1/admin/partners?status=pending
GET /api/v1/admin/partners/:id
PATCH /api/v1/admin/partners/:id/status (approve/reject)
PATCH /api/v1/admin/partners/:id (update details)
// Payments
GET /api/v1/admin/payments?status=pending
GET /api/v1/admin/payments/:id
POST /api/v1/admin/payments/:id/refund
// Payouts
GET /api/v1/payouts/list
POST /api/v1/payouts/create
PATCH /api/v1/payouts/:id/status
// Analytics
GET /api/v1/analytics/dashboard
GET /api/v1/analytics/revenue?from=&to=
GET /api/v1/analytics/orders?module=food
GET /api/v1/analytics/users
// Reports
GET /api/v1/reports/orders?format=csv&from=&to=
GET /api/v1/reports/revenue?format=csv
GET /api/v1/reports/partners?format=csv
5. Partener-app Integration Status
5.1 Current Implementation
Existing Files:
src/api/client.ts- Axios setup with retry logicsrc/store/partnerApi.ts- API client exportsrc/store/partnerStore.ts- State managementsrc/features/CatalogManager.tsx- Product catalogsrc/features/AvailabilityGrid.tsx- Working hourssrc/features/LogisticsConsole.tsx- Delivery management
5.2 Partener-app Missing Integrations
| Feature | Priority | Frontend Status | Backend Status |
|---|---|---|---|
| Order List | HIGH | ⚠️ Mock data | ✅ Done |
| Order Accept/Reject | HIGH | ❌ Missing | ✅ Done |
| Order Details | HIGH | ❌ Missing | ✅ Done |
| Earnings Dashboard | HIGH | ❌ Missing | ❌ Missing |
| Payout History | HIGH | ❌ Missing | ❌ Missing |
| Withdrawal Request | HIGH | ❌ Missing | ❌ Missing |
| Product Add/Edit | HIGH | ❌ Missing | ✅ Done |
| Product Delete | HIGH | ❌ Missing | ✅ Done |
| Restaurant Details | MEDIUM | ❌ Missing | ✅ Done |
| Profile Update | MEDIUM | ⚠️ Partial | ✅ Done |
| Availability Toggle | MEDIUM | ⚠️ Partial | ✅ Done |
| Working Hours | MEDIUM | ⚠️ Partial | ✅ Done |
| Notification Preferences | LOW | ❌ Missing | ❌ Missing |
| Bank Account Setup | MEDIUM | ❌ Missing | ❌ Missing |
| Driver Management | LOW | ❌ Missing | ✅ Done |
| Analytics/Stats | MEDIUM | ❌ Missing | ❌ Missing |
| Chat with Customer | LOW | ❌ Missing | ❌ Missing |
5.3 Partener-app API Calls Needed
typescript
// Orders
GET /api/v1/partner/orders?status=pending&module=food
GET /api/v1/partner/orders/:id
PATCH /api/v1/partner/orders/:id/status (confirm/preparing/ready/cancel)
// Products (Food)
GET /api/v1/partner/restaurant/:id/dishes
POST /api/v1/partner/restaurant/:id/dishes
PATCH /api/v1/partner/dishes/:id
DELETE /api/v1/partner/dishes/:id
// Products (Shopping/Quick/Grocery)
GET /api/v1/partner/products
POST /api/v1/partner/products
PATCH /api/v1/partner/products/:id
DELETE /api/v1/partner/products/:id
// Earnings & Payouts
GET /api/v1/partner/earnings
GET /api/v1/partner/payouts
POST /api/v1/payouts/withdraw
// Profile
GET /api/v1/partner/profile
PATCH /api/v1/partner/profile
// Availability
PATCH /api/v1/partner/availability
PATCH /api/v1/partner/working-hours
// Bank Account
POST /api/v1/partner/bank-account
GET /api/v1/partner/bank-account
// Analytics
GET /api/v1/partner/analytics/orders
GET /api/v1/partner/analytics/revenue
GET /api/v1/partner/analytics/customers
6. Deployment Strategy
6.1 Current State
Docker Compose (Development Only):
yaml
services:
postgres:
image: postgres:16-alpine
ports:
- '5432:5432'
api:
build: .
ports:
- '4000:4000'
6.2 Infrastructure Missing
| Component | Status | Priority |
|---|---|---|
| MongoDB container | TODO | MEDIUM |
| Redis container | TODO | MEDIUM |
| Nginx reverse proxy | TODO | HIGH |
| SSL/TLS setup | TODO | HIGH |
| CI/CD pipeline | TODO | HIGH |
| Health check endpoints | ⚠️ Partial | MEDIUM |
| Log aggregation | TODO | MEDIUM |
| Monitoring/Alerting | TODO | LOW |
6.3 Recommended Deployment Architecture
Staging (Week 3-4)
Render / Railway / Vercel
├── Backend API (Node.js)
├── PostgreSQL (Railway/RDS)
├── S3 Storage (Uploads)
└── CDN (CloudFront)
Production (Month 2)
AWS / GCP
├── Load Balancer (ALB)
├── Kubernetes Cluster (EKS/GKE)
│ ├── API Pods (3+ replicas)
│ ├── HPA (auto-scaling)
│ └── ConfigMaps/Secrets
├── PostgreSQL (RDS Aurora)
├── Redis (ElastiCache)
├── S3 (Files)
├── CloudFront (CDN)
├── Route53 (DNS)
└── ACM (SSL)
7. Implementation Roadmap
Phase 1: Critical Fixes (Week 1-2)
| Task | App | Effort | Dependencies |
|---|---|---|---|
| Razorpay Webhook Handler | Backend | 2 days | - |
| Payment Status Sync | Backend | 1 day | Webhook |
| Partner Payout API | Backend | 3 days | - |
| Admin Order Management | Admin-app | 2 days | Backend ready |
| Partner Order Actions | Partener-app | 2 days | Backend ready |
| Total | 10 days |
Phase 2: Core Features (Week 3-4)
| Task | App | Effort | Dependencies |
|---|---|---|---|
| Partner Earnings Dashboard | Partener-app | 2 days | Payout API |
| Admin Payout Management | Admin-app | 2 days | Payout API |
| Partner Bank Account Setup | Backend+App | 2 days | - |
| Withdrawal Request Flow | Partener-app | 1 day | Bank Account |
| Analytics Endpoints | Backend | 3 days | - |
| Analytics Dashboard | Admin-app | 2 days | Analytics API |
| Total | 12 days |
Phase 3: Data Layer (Week 5-6)
| Task | App | Effort | Dependencies |
|---|---|---|---|
| MongoDB Setup | Backend | 2 days | Infrastructure |
| Audit Log Migration | Backend | 3 days | MongoDB |
| Redis Caching | Backend | 3 days | Infrastructure |
| Session Store | Backend | 1 day | Redis |
| Report Generation API | Backend | 3 days | MongoDB |
| Report Export | Admin-app | 2 days | Report API |
| Total | 14 days |
Phase 4: Production Prep (Week 7-8)
| Task | App | Effort | Dependencies |
|---|---|---|---|
| Nginx Setup | DevOps | 1 day | - |
| SSL/TLS Config | DevOps | 1 day | Domain |
| CI/CD Pipeline | DevOps | 3 days | GitHub Actions |
| Load Testing | DevOps | 2 days | Deployed system |
| Staging Deployment | DevOps | 2 days | CI/CD |
| Documentation | All | 2 days | - |
| Total | 11 days |
Phase 5: Launch & Beyond (Month 3+)
| Task | Priority | Notes |
|---|---|---|
| Production Deployment | HIGH | Go live |
| UPI Integration | MEDIUM | Additional payment option |
| Real-time Features (WebSocket) | MEDIUM | Chat, Live tracking |
| Performance Optimization | MEDIUM | Caching, Query optimization |
| Mobile App (Customer) | HIGH | Complete ride booking |
| Multi-region Support | LOW | Future scaling |
Summary
What's Done ✅
- PostgreSQL + Prisma (46 models)
- Basic Razorpay integration (orders, verify, wallet)
- Backend routes (~80% endpoints)
- Admin-app pages (80% UI)
- Partner-app base structure
What's Missing ❌
Backend:
- Webhooks (Razorpay)
- Payouts/Transfers
- Reports/Analytics endpoints
- Search endpoints
- Chat endpoints
Admin-app:
- Full CRUD for most resources
- Analytics data connection
- Payment management
- Reports export
Partener-app:
- Order actions (accept/reject)
- Earnings dashboard
- Product management
- Withdrawal requests
Infrastructure:
- MongoDB
- Redis
- Nginx
- CI/CD
- Production deployment
Document Info
- Created: 2026-04-29
- Version: 2.0
- Last Updated: 2026-04-29