Cuan Portal
Financial command center. Currently a single 1,715-line file in the main repo. Future state: separate team, separate repo, dedicated audit infrastructure for fraud prevention through Separation of Duties.
Module tree (current state)β
Dashboard, what's visibleβ
The cuan dashboard surfaces all financial KPIs in one view:
Top-line metricsβ
- Today's GMV: Gross Merchandise Value for the current day
- MTD Revenue: Month-to-date platform revenue
- Active Sellers: Sellers with active listings or recent activity
- Orders Today: Order volume for the day
Platform revenue breakdownβ
| Stream | What it tracks |
|---|---|
| Commission | BPF + shipping markup + payment markup |
| Boost | Boost product purchases |
| Premium | Future premium feature revenue |
Operational queuesβ
- Disbursement Queue: pending seller payouts awaiting maker-checker
- Fraud Alerts: flagged suspicious activity
- Recent Activity: real-time financial events
Reconciliationβ
- Net Revenue Reconciliation (MTD): Revenue minus expenses = net
Module groupsβ
Dashboardβ
The default landing page. Read-only summary of financial health.
Revenueβ
Detailed revenue analytics, by stream, by period, by seller cohort.
Ordersβ
Financial view of orders, every transaction's fee breakdown, escrow state, disbursement status.
Operationsβ
Day-to-day finance work.
| Module | Purpose |
|---|---|
| Payouts | Manage seller disbursements with maker-checker workflow |
| Expenses | Track operational expenses by category |
| Boost and Premium | Boost product transactions and analytics |
Securityβ
Fraud prevention and audit.
| Module | Purpose |
|---|---|
| Fraud and Integrity | Real-time fraud monitoring |
| Reports | Generate financial reports |
| Xero Sync | π‘ Placeholder, only flips boolean, no real API call yet |
| Audit Log | Complete record of every financial change |
Adminβ
| Module | Purpose |
|---|---|
| Settings | Cuan-specific configuration |
AI Help Botβ
π΅ Planned, not yet built. Future capability to query financial data conversationally.
Maker-checker workflowβ
Every disbursement β₯ IDR 500,000 requires two-person approval:
Rule: Maker and checker must be different finance admins. Same person cannot initiate and approve.
Audit trailβ
Every cuan action logged to fin_audit_log with:
- Actor user_id
- Action type
- Before/after JSONB snapshot
- Timestamp
- Optional reason
This enables full reconstruction of any financial change for dispute or audit.
Current limitationsβ
1. Single-file architectureβ
The entire cuan portal is currently src/app/pages/cuan/FinancesDashboard.tsx, 1,715 lines. This works but doesn't scale. Refactor planned to proper route tree:
cuan/
βββ routes.ts
βββ pages/
β βββ DashboardPage.tsx
β βββ RevenuePage.tsx
β βββ OrdersPage.tsx
β βββ PayoutsPage.tsx
β βββ ExpensesPage.tsx
β βββ BoostPremiumPage.tsx
β βββ FraudIntegrityPage.tsx
β βββ ReportsPage.tsx
β βββ XeroSyncPage.tsx
β βββ AuditLogPage.tsx
β βββ SettingsPage.tsx
βββ components/
βββ DisbursementQueue.tsx
βββ FraudAlertCard.tsx
βββ NetRevenueWidget.tsx
2. Xero sync is placeholderβ
Currently xero_synced boolean is flipped to true but no actual Xero API call happens. Real implementation needed:
3. AI bot not yet builtβ
Cuan AI bot is on the roadmap but not implemented. Future capabilities:
- "What was our MTD revenue from Boost?"
- "Show me disbursements pending approval over IDR 1M"
- "Reconcile this Xero discrepancy"
- "Audit trail for seller X"
Future separation planβ
The cuan module currently shares the main pasarseken repo and database. Future state separates it for fraud prevention.
Why separate finance?β
Separation of Duties (SoD)β
A core fraud prevention principle: the people who build the platform shouldn't have unilateral control over financial flows.
Risks of bundled finance:
- Founder with code access could modify finance data
- Bug in main repo could corrupt financial records
- Single point of failure for audit trail
Benefits of separated finance:
- Independent codebase reduces blast radius
- Dedicated finance team without code access to product
- Independent audit trail
- Cleaner Xero pipeline
- Better suited for compliance audits
When to migrate?β
Estimated post-launch month 6+, contingent on:
- Transaction volume justifying dedicated finance team
- Hiring finance lead
- Xero sync fully built and validated
- Migration plan reviewed with auditor
The deferred finances Postgres schema migration (2026-04-28 decision) is part of this trigger, not a separate concern, when cuan separates, the schema migration runs as part of the same transition.
Open questionsβ
| Question | Owner |
|---|---|
| When to refactor cuan from single file to route tree? | Engineer |
| Hire dedicated finance lead, when and what profile? | Founder |
Resolved 2026-04-28: finances schema migration, deferred to cuan separation; finance tables stay in public with fin_ prefix pre-launch.
Where to look in the codebaseβ
| What you want | Where it lives |
|---|---|
| Cuan frontend app shell | pasarseken-cuan/frontend/src/components/CuanApp.tsx |
| Finance domain entities | pasarseken-cuan/backend/server/domain/ |
| Finance repositories | pasarseken-cuan/backend/server/infrastructure/repositories/ |
| Route handlers | pasarseken-cuan/backend/server/interface/http/routes-*.ts |
| Comms monitor (CommsPage) | pasarseken-cuan/frontend/src/pages/CommsPage.tsx |
| Disputes UI | pasarseken-cuan/frontend/src/pages/DisputesPage.tsx |
| Outbox processor (cuanβmain) | pasarseken-cuan/backend/server/infrastructure/outbox/FinOutboxProcessor.ts |
| Command client | pasarseken-cuan/backend/server/infrastructure/commands/FinCommandClient.ts |
| Main ops comms monitor | pasarseken/src/app/components/admin/CuanOutboxMonitor.tsx |
Cross-service communicationβ
As of 2026-05-16, pasarseken-cuan has a fully deployed bidirectional communication layer with the SEKEN marketplace:
- Type 1 (events): Outbox pattern in both directions. Main β cuan delivers order lifecycle + boost events. Cuan β main delivers disbursement and fraud flag events.
- Type 2 (commands): Finance admin can resolve disputes from cuan's UI. Command executes synchronously in main's context.
- Type 3 (query proxy): Balance queries from sellers hit main's API but data is sourced live from cuan.
See Cuan Bidirectional Communication β for full route reference, sequence diagrams, secrets, failure modes, and monitoring surfaces.
Next: Integrations β