LeadFlow PM
System Design Document
Three-portal platform for managing channel partner onboarding, lead flow, commission tracking, and platform fee settlement — built for scale.
Three portals, one unified backend
Each portal serves a distinct role in the lead and commission lifecycle. All portals share a single API and database — access is enforced by role-based guards.
Recommended tech stack
Chosen for enterprise reliability, TypeScript-first type safety across every layer, and developer velocity.
app. / admin. / super.admin.leadflowpm.com → Admin Portal
super.leadflowpm.com → Super Admin Portal
api.leadflowpm.com → NestJS API (shared by all portals)
Channel Partner portal
Signup & onboarding flow
CP signs up with email + password. Account created with status pending. Portal shows "Approval Pending" screen — no further access until approved.
Admin portal shows the signup in the Pending Approval tab. Admin can approve or reject with an optional note.
On approval, system sends a branded welcome email with a login link. CP status changes to active. Portal unlocks full access.
CP fills in company name, logo, bank details, and submits category-specific content for admin to review and publish in the customer view.
Sidebar navigation
| Section | Description | Special behaviour |
|---|---|---|
| Dashboard | KPI cards: active leads, total commission earned, pending settlements, platform fees deducted | — |
| Categories | Full-page customer-facing showcase of all categories with descriptions and images — used to pitch to prospects and submit leads | Sidebar hides on enter; hamburger to reopen |
| Leads | Two sub-sections: Originated Leads and Assigned Leads. Two views: List and Kanban | — |
| Commissions | Full commission analysis, settlement history, payment initiation, received transactions | — |
| Company Profile | Company info, logo, bank account details, category content submission form | — |
Lead section — two sub-sections
Kanban pipeline stages
Commission section
Admin portal
Sidebar navigation
| Section | Key capabilities |
|---|---|
| Dashboard | Overview metrics, recent leads, pending approvals, outstanding commissions, platform fee summary. Announcements panel — create, target CPs, broadcast. |
| Channel Partners | Three tabs: Approved, Pending Approval, Manually Add. View full company profile including bank details. Approve/reject with email trigger. Send welcome email button for manual adds. |
| Categories | Create, edit, delete categories. Upload and reorder images. Review and approve/reject CP-submitted category content. Publish approved content to customer view. |
| Leads | All leads in one view. Allocate any lead to a CP. Set per-lead platform fee override. Full list + kanban view. Update status, upload evidence, add notes. Cannot delete leads — super admin only. |
| Commissions | Settle net commission to CP — select transaction, upload bank slip PDF, mark settled. Full settlement history per CP. CP bank details shown from their profile for manual transfer reference. |
| Platform Fees | Configure global fee (% or fixed). View platform fee amount for every lead. Batch or individual settle platform fees to Super Admin. Upload bank slip PDF per settlement. Full settled + outstanding history. |
| Announcements | Compose announcement, choose target (all CPs or specific ones), send. Delivered as in-app notification and optional email via BullMQ queue. |
Manual CP creation flow
must_change_password: true flag).Two settlement types admin performs
| Settlement type | From | To | Evidence | Visible to |
|---|---|---|---|---|
| CP Commission Settlement | Admin | Channel Partner | Bank slip PDF/image uploaded by admin | CP — received transactions section |
| Platform Fee Settlement | Admin | Super Admin (you) | Bank slip PDF/image uploaded by admin | Super Admin — income dashboard + settlement history |
Platform fee configuration
Super Admin portal (you)
Analytics and oversight portal. Full read access to all data. The only destructive action available is lead deletion. Everything financial is read-only — settlements are initiated by admin and visible here.
Sidebar sections
| Section | What you see | Actions |
|---|---|---|
| Income Dashboard | Total platform fee generated, total received (settled by admin), total outstanding. Month-by-month chart. Per-lead fee breakdown. | Read-only |
| Platform Fee Settlements | Every settlement admin has made to you. Date, amount, leads covered, bank slip PDF attached by admin. | View/download receipts |
| Outstanding Fees | All platform fees not yet settled by admin. Grouped by lead with lead value and commission context. Overdue indicators. | Read-only |
| All Leads | Complete lead database across all CPs. Filter by status, date, CP, category. Full detail view. | Delete lead (only role) |
| Channel Partners | All CP profiles, approval status, commission history, bank details. | Read-only |
| Commission Reports | Full commission flow: gross → platform fee → net CP payment. Filterable by date, CP, lead status. | Export CSV/PDF |
| Analytics | Lead volume over time, win rate, top-performing CPs, category performance, revenue trends. | Export charts |
Income summary view (example)
Core data models
PostgreSQL relational schema. PK primary key FK foreign key enum enumerated type computed derived field.
Commission & platform fee flow
CP drags lead to Won on kanban or updates status in list view. System creates a commission_transaction record automatically.
CP enters the deal size and their commission amount. Platform fee and net commission are calculated instantly using the active fee rule (per-lead override if set, otherwise global default).
Client pays admin outside the system via bank transfer or other means. Admin manually records this against the lead if needed.
Admin opens Commissions panel, selects the transaction, marks as paid, uploads bank transfer slip PDF. CP receives in-app notification + email. Shows in CP's Received Transactions.
Admin opens Platform Fees panel, selects outstanding fee(s) (can batch multiple leads), transfers to Super Admin's bank account, uploads bank slip PDF. Super Admin income dashboard updates in real time.
Fee calculation logic
fee_rule = lead.fee_override ?? active_global_platform_fee_config
// Calculate platform fee amount
if fee_rule.type === 'percentage':
platform_fee = commission_amount × (fee_rule.value / 100)
else: // fixed
platform_fee = fee_rule.value
// Net commission paid to CP
net_commission = commission_amount − platform_fee
Example
Lead lifecycle & pipeline stages
| Stage | Who sets it | Description | Notifies |
|---|---|---|---|
| New | System (on allocation) | Default starting stage when admin allocates the lead to CP | CP → "Lead assigned" |
| Contacted | CP / Admin | First contact made with the prospect | — |
| Qualified | CP / Admin | Prospect confirmed as a real opportunity | — |
| Proposal Sent | CP / Admin | Formal proposal or quote submitted | — |
| Negotiation | CP / Admin | Active discussion on terms and pricing | — |
| Won | CP / Admin | Deal closed. Commission record created automatically | Admin → "Lead won" |
| Lost | CP / Admin | Deal did not proceed. CP can add reason note | Admin → "Lead lost" |
Role & permission matrix
| Action | CP | Admin | Super Admin |
|---|---|---|---|
| AUTH | |||
| Self-register via email | ✓ | — | — |
| Login (including forced password change) | ✓ | ✓ | ✓ |
| CHANNEL PARTNERS | |||
| Edit own profile + bank details | ✓ | — | — |
| View all CP profiles + bank details | — | ✓ | ✓ |
| Approve / reject CPs | — | ✓ | — |
| Manually add CP with temp password + welcome email | — | ✓ | — |
| CATEGORIES | |||
| View customer-facing categories | ✓ | ✓ | ✓ |
| Submit category content (description + images) | ✓ | — | — |
| Create / edit / delete categories | — | ✓ | — |
| Approve / publish CP category content | — | ✓ | — |
| LEADS | |||
| Submit lead from customer view | ✓ | — | — |
| View own originated leads | ✓ | ✓ | ✓ |
| View all leads | — | ✓ | ✓ |
| Allocate lead to CP | — | ✓ | — |
| Update pipeline stage | assigned only | ✓ | — |
| Update lead value + commission | assigned only | ✓ | — |
| Upload evidence photos / files | assigned only | ✓ | — |
| Set per-lead platform fee override | — | ✓ | — |
| Delete lead | — | ✗ blocked | ✓ only role |
| COMMISSIONS & FEES | |||
| View own commission analysis | ✓ | ✓ | ✓ |
| View all commission transactions | — | ✓ | ✓ |
| Settle commission to CP (upload slip) | — | ✓ | — |
| Initiate payment request (card / bank transfer) | ✓ | — | — |
| Configure global platform fee | — | ✓ | — |
| Settle platform fee to super admin (upload slip) | — | ✓ | — |
| View platform fee income + settlement history | — | own actions | ✓ full |
| ANNOUNCEMENTS & REPORTS | |||
| Create & broadcast announcements | — | ✓ | — |
| Receive notifications | ✓ | ✓ | ✓ |
| Export reports (CSV / PDF) | — | limited | ✓ full |
Notification events
All notifications delivered in-app via Socket.io (real-time) and optionally via email through a BullMQ queue. Bell icon in header shows unread count.
API route structure
RESTful NestJS API. All routes prefixed /api/v1. JWT bearer token auth. Role guards applied at controller level.
| Module | Key endpoints | Guard |
|---|---|---|
auth | POST /auth/register POST /auth/login POST /auth/refresh POST /auth/change-password | Public / JWT |
channel-partners | GET /channel-partners POST /channel-partners/approve/:id POST /channel-partners/manual-add PATCH /channel-partners/:id/bank-details | Admin / CP |
categories | GET /categories POST /categories PATCH /categories/:id DELETE /categories/:id POST /categories/:id/content PATCH /categories/:id/content/approve | Admin / JWT |
leads | GET /leads POST /leads GET /leads/:id PATCH /leads/:id POST /leads/:id/allocate PATCH /leads/:id/stage POST /leads/:id/evidence DELETE /leads/:id | JWT (role-filtered) / SuperAdmin only for DELETE |
platform-fees | GET /platform-fees/config POST /platform-fees/config GET /platform-fees/summary GET /platform-fees/settlements POST /platform-fees/settle | Admin / Super Admin |
commissions | GET /commissions GET /commissions/analysis POST /commissions/:id/settle GET /commissions/:id/receipt | Admin / CP |
payments | POST /payments/card POST /payments/bank-transfer POST /payments/:id/receipt GET /payments/history | CP |
announcements | GET /announcements POST /announcements POST /announcements/:id/send | Admin / CP |
notifications | GET /notifications PATCH /notifications/:id/read PATCH /notifications/read-all | JWT |
uploads | POST /uploads/presign → returns S3 presigned URL for direct browser-to-S3 upload | JWT |
analytics | GET /analytics/overview GET /analytics/leads GET /analytics/commissions GET /analytics/platform-fees GET /analytics/export | Super Admin |
Phased development plan
5 phases, each delivering a working deployable increment. Estimated at 14 weeks for full production launch.