📌 Objective
Build a financial-grade revenue distribution infrastructure for CommDesk where:
Any community can earn revenue
Revenue automatically splits across community roles
CommDesk platform fee is deducted automatically
Cashfree payment gateway charges are deducted
GST calculations are handled properly
Settlement accounting is audit-safe
Community members receive net earnings
Payout-ready internal wallets are maintained
This system should behave similar to:
🎯 Core Goals
The system must support:
Platform fee deduction
GST calculations
Cashfree charge deduction
Dynamic revenue splitting
Role-based earnings
Community settlements
Internal earning wallets
Financial-safe accounting
Tax-ready ledger system
Audit-safe payout infrastructure
💰 Financial Flow
Before ANY community distribution:
Customer Payment
↓
GST Deduction
↓
Cashfree Charges
↓
Platform Fee
↓
Net Community Revenue
↓
Role-Based Split
↓
Wallet Distribution
🧠 Example Revenue Calculation
Example 1 — Event Revenue
Customer Pays = ₹10,000
GST (18%) = ₹1,800
Remaining = ₹8,200
Cashfree Charges:
2% + GST = ₹193
Remaining = ₹8,007
CommDesk Platform Fee:
10% = ₹800
Net Community Revenue:
₹7,207
Role Distribution
Owner = 50% = ₹3,603.5
Admin Team = 20% = ₹1,441.4
Moderator Team = 10% = ₹720.7
Event Team = 20% = ₹1,441.4
Example 2 — Sponsor Revenue
Sponsor Payment = ₹50,000
GST = ₹9,000
Remaining = ₹41,000
Cashfree Fee = ₹968
Remaining = ₹40,032
Platform Fee (12%) = ₹4,803
Community Pool = ₹35,229
🏗️ Revenue Split Architecture
Customer Payment
↓
Cashfree Verification
↓
Financial Calculation Engine
↓
GST Deduction
↓
Gateway Charge Deduction
↓
Platform Fee Deduction
↓
Net Revenue Pool
↓
Role Distribution Engine
↓
Role Wallet Credit
↓
Settlement Queue
🧱 Backend Stack
Runtime
Framework
Preferred:
Database
Preferred:
ORM
Preferred:
Queue
Preferred:
Cache
Payment Provider
📦 Required Packages
Core
npm install @prisma/client prisma
npm install zod uuid dotenv dayjs
npm install helmet cors compression
npm install pino pino-pretty
Queue
npm install amqplib bullmq ioredis
Cashfree
Security
npm install express-rate-limit
npm install rate-limiter-flexible
npm install csurf hpp
🗄️ Core Database Schemas
Community Wallet
model CommunityWallet {
id String @id @default(uuid())
communityId String @unique
availableBalance Int @default(0)
lockedBalance Int @default(0)
pendingSettlement Int @default(0)
totalGrossRevenue BigInt @default(0)
totalPlatformFees BigInt @default(0)
totalGatewayFees BigInt @default(0)
totalGSTCollected BigInt @default(0)
totalNetRevenue BigInt @default(0)
totalWithdrawn BigInt @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Revenue Transaction Ledger
model RevenueTransaction {
id String @id @default(uuid())
communityId String
sourceType RevenueSourceType
sourceId String
grossAmount Int
gstAmount Int
paymentGatewayFee Int
paymentGatewayGST Int
platformFee Int
platformFeeGST Int
netRevenue Int
metadata Json?
idempotencyKey String @unique
createdAt DateTime @default(now())
@@index([communityId])
@@index([createdAt])
}
Role Distribution Table
model RevenueDistribution {
id String @id @default(uuid())
transactionId String
userId String
roleId String
roleName String
percentage Float
amount Int
createdAt DateTime @default(now())
@@index([transactionId])
@@index([userId])
}
Platform Revenue Table
model PlatformRevenue {
id String @id @default(uuid())
transactionId String
amount Int
gstAmount Int
feePercentage Float
createdAt DateTime @default(now())
}
💸 Financial Calculation Engine
Required Flow
Gross Revenue
↓
GST Extraction
↓
Cashfree Charges
↓
Cashfree GST
↓
CommDesk Platform Fee
↓
Platform GST
↓
Net Revenue Pool
↓
Role Distribution
Required Service Methods
calculateGST()
calculateGatewayFees()
calculatePlatformFee()
calculateNetRevenue()
splitRevenueAcrossRoles()
creditRoleWallets()
createLedgerEntries()
⚡ Dynamic Fee System
Admin Configurable
| Setting |
Example |
| Platform Fee |
5–20% |
| Sponsor Fee |
Custom |
| Event Fee |
Custom |
| Premium Community Fee |
Custom |
| GST Percentage |
18% |
Queue Rules
Required:
Retry support
Exponential backoff
Dead-letter queues
Delayed retries
Idempotent consumers
📊 Analytics Requirements
Track:
Gross revenue
Net revenue
Platform earnings
Gateway charges
GST collected
Community earnings
Top earning communities
Payout volume
📈 Dashboard Features
Users should see:
Gross revenue
Platform fee breakdown
Cashfree fee breakdown
GST deductions
Net earnings
Revenue split analytics
Wallet history
Monthly reports
🧪 Testing Requirements
Unit Tests
Test:
Integration Tests
Test:
Cashfree integration
Revenue distribution
Wallet synchronization
Queue processing
Failure Tests
Test:
Load Testing
Simulate:
100K financial split events/min
📈 Monitoring & Alerts
Metrics
Track:
Revenue throughput
Settlement delays
Failed payouts
Fraud attempts
Queue lag
Wallet inconsistencies
Alerts
Trigger alerts for:
Failed settlements
High fraud activity
Queue failures
Negative balances
Payment inconsistencies
🗂️ Suggested Folder Structure
src/
├── modules/
│ ├── revenue-engine/
│ ├── gst-engine/
│ ├── gateway-fees/
│ ├── settlements/
│ ├── payouts/
│ ├── role-wallets/
│ ├── fraud-detection/
│ └── finance-analytics/
│
├── queues/
├── telemetry/
├── middleware/
├── prisma/
├── common/
└── tests/
✅ Acceptance Criteria
Platform fee deduction implemented
GST calculations implemented
Cashfree charge deduction implemented
Role-based revenue splitting implemented
Immutable ledger implemented
Settlement system implemented
Cashfree payout integration working
Queue-driven architecture enabled
Fraud prevention active
Full observability setup
Production-grade testing completed
Horizontally scalable architecture supported
📌 Priority
P0 — Financial Infrastructure Core
📌 Objective
Build a financial-grade revenue distribution infrastructure for CommDesk where:
Any community can earn revenue
Revenue automatically splits across community roles
CommDesk platform fee is deducted automatically
Cashfree payment gateway charges are deducted
GST calculations are handled properly
Settlement accounting is audit-safe
Community members receive net earnings
Payout-ready internal wallets are maintained
This system should behave similar to:
Stripe Connect
Razorpay Route
Shopify Partner Payouts
🎯 Core Goals
The system must support:
Platform fee deduction
GST calculations
Cashfree charge deduction
Dynamic revenue splitting
Role-based earnings
Community settlements
Internal earning wallets
Financial-safe accounting
Tax-ready ledger system
Audit-safe payout infrastructure
💰 Financial Flow
Before ANY community distribution:
🧠 Example Revenue Calculation
Example 1 — Event Revenue
Role Distribution
Example 2 — Sponsor Revenue
🏗️ Revenue Split Architecture
🧱 Backend Stack
Runtime
Framework
Preferred:
NestJS
Database
Preferred:
PostgreSQL
ORM
Preferred:
Prisma
Queue
Preferred:
RabbitMQ
Cache
Redis
Payment Provider
Cashfree Payments
📦 Required Packages
Core
Queue
Cashfree
Security
🗄️ Core Database Schemas
Community Wallet
Revenue Transaction Ledger
Role Distribution Table
Platform Revenue Table
💸 Financial Calculation Engine
Required Flow
Required Service Methods
⚡ Dynamic Fee System
Admin Configurable
Queue Rules
Required:
Retry support
Exponential backoff
Dead-letter queues
Delayed retries
Idempotent consumers
📊 Analytics Requirements
Track:
Gross revenue
Net revenue
Platform earnings
Gateway charges
GST collected
Community earnings
Top earning communities
Payout volume
📈 Dashboard Features
Users should see:
Gross revenue
Platform fee breakdown
Cashfree fee breakdown
GST deductions
Net earnings
Revenue split analytics
Wallet history
Monthly reports
🧪 Testing Requirements
Unit Tests
Test:
GST calculations
Platform fee calculations
Gateway fee calculations
Revenue splitting
Settlement generation
Integration Tests
Test:
Cashfree integration
Revenue distribution
Wallet synchronization
Queue processing
Failure Tests
Test:
Duplicate payouts
Queue crash
DB deadlock
Cashfree downtime
Partial transaction failures
Load Testing
Simulate:
📈 Monitoring & Alerts
Metrics
Track:
Revenue throughput
Settlement delays
Failed payouts
Fraud attempts
Queue lag
Wallet inconsistencies
Alerts
Trigger alerts for:
Failed settlements
High fraud activity
Queue failures
Negative balances
Payment inconsistencies
🗂️ Suggested Folder Structure
✅ Acceptance Criteria
Platform fee deduction implemented
GST calculations implemented
Cashfree charge deduction implemented
Role-based revenue splitting implemented
Immutable ledger implemented
Settlement system implemented
Cashfree payout integration working
Queue-driven architecture enabled
Fraud prevention active
Full observability setup
Production-grade testing completed
Horizontally scalable architecture supported
📌 Priority