How femzy123/settlehq works
Purpose and Runtime
SettleHQ is a Next.js/TypeScript payment-collection system for organizations: manage payers and collections, create payer-specific invoices, accept Nomba transfer/card payments, reconcile outcomes, and expose receipts. It runs as a Next.js App Router application, with server-rendered pages, server actions, and route handlers. Primary entry points are src/app/layout.tsx, src/app/page.tsx, and src/proxy.ts.
Identity, Workspace, and Persistence Boundary
Clerk authentication gates organization-scoped workspaces; onboarding establishes the organization context used by all business records. Database access is Neon Postgres through Drizzle, with schema/migrations defining the durable model.
• src/app/onboarding/actions.ts
• src/server/current-workspace.ts
• src/db/schema.ts
• src/db/index.ts
• drizzle/0000_amazing_grey_gargoyle.sql
Organization Operations: Payers and Collections
Authenticated operators create payers, create collections, and assign payers to a collection. This assignment is the invoice-generation boundary: a collection becomes a set of payer-specific obligations rather than a shared payment request.
• src/app/payers/actions.ts
• src/server/payers.ts
• src/app/collections/actions.ts
• src/server/collections.ts
Invoice Lifecycle and Public Payment Surface
Internal invoice pages provide organization visibility, while tokenized public invoice routes provide the payer-facing payment surface. A public invoice loads its obligation and supports payment initiation/status verification without exposing organization dashboard access.
• src/app/invoices/[invoiceId]/page.tsx
• src/app/invoice/[token]/page.tsx
• src/app/invoice/[token]/actions.ts
• src/app/api/invoices/public/[token]/status/route.ts
• src/app/api/invoices/public/[token]/verify/route.ts
Nomba Payment Integration
Nomba is the financial-infrastructure boundary. Invoice opening/payment actions create or retrieve virtual accounts for bank transfers and initiate checkout for card payments; payment utilities encapsulate provider-specific request/response behavior. Provider callbacks enter through a dedicated webhook endpoint, then payment verification determines authoritative status.
• src/server/nomba.ts
• src/lib/nomba-virtual-account.ts
• src/lib/nomba-checkout.ts
• src/lib/nomba-payment.ts
• src/app/api/webhooks/nomba/route.ts
Reconciliation and Receipt Flow
A Nomba event or explicit verification resolves a provider transaction to its invoice through virtual-account or checkout references. The system records actual received amount, compares it with invoice expectation, and derives paid/underpaid/overpaid/pending outcomes. Updated invoice/payment records drive dashboard, invoice, payer, and payment views; successful verified payments enable payer receipt rendering/printing.
• src/server/invoices.ts
• src/server/payments.ts
• src/server/payment-records.ts
• src/app/payments/page.tsx
• src/components/receipt-viewer.tsx
Presentation and Deployment
Dashboard pages are organized around authenticated operational views, with shared application shell/sidebar components. Public invoice pages remain a distinct payer experience. Styling uses Tailwind/shadcn conventions. Deployment targets Vercel; external dependencies are Clerk, Neon Postgres, Drizzle, and Nomba. Health checking is exposed at src/app/api/health/route.ts.
• src/components/dashboard-shell.tsx
• src/components/app-sidebar.tsx
• src/components/auth-shell.tsx
• src/app/dashboard/page.tsx
Main entry points: payments.ts Payment reconciliation · invoices.ts Invoice lifecycle · index.ts Neon Postgres · collections.ts Collection service
Components 20
Next.js application
Authenticated operations and public payer routes.
- App entry
src/app/layout.tsx - Auth proxy · Gates organization workspace access.
src/proxy.ts - Dashboard
src/app/dashboard/page.tsx - Payer management
src/app/payers/actions.ts - Collection management · Assigning payers creates invoice obligations.
src/app/collections/actions.ts - Internal invoice view
src/app/invoices/[invoiceId]/page.tsx - Public invoice · Tokenized payer payment surface.
src/app/invoice/[token]/page.tsx - Public verification API
src/app/api/invoices/public/[token]/verify/route.ts - Payments and receipts · Shows reconciled payment outcomes and receipts.
src/app/payments/page.tsx - Receipt viewer · Renders printable receipts for verified payments.
src/components/receipt-viewer.tsx
Business services
Organization-scoped lifecycle and reconciliation logic.
- Payer service
src/server/payers.ts - Collection service
src/server/collections.ts - Invoice lifecycle · Loads obligations and derives invoice state.
src/server/invoices.ts - Payment reconciliation · Matches provider references and records paid, underpaid, overpaid, or pending outcomes.
src/server/payments.ts
Payment integration
Nomba-facing account, checkout, and event handling.
- Nomba payment initiation · Creates virtual accounts and card checkouts.
src/server/nomba.ts - Nomba webhook · Receives provider callbacks.
src/app/api/webhooks/nomba/route.ts - Nomba · Transfer and card payment infrastructure.
Identity and persistence
Workspace identity and durable records.
- Current workspace · Resolves the Clerk organization context.
src/server/current-workspace.ts - Neon Postgres · Durable organizations, invoices, and payment records.
src/db/index.ts - Schema and migrations
src/db/schema.ts
Connections 21
- App entry → Auth proxy: routes through
- Auth proxy → Current workspace: authenticates
- Dashboard → Current workspace: uses
- Payer management → Payer service: calls
- Collection management → Collection service: calls
- Payer service → Neon Postgres: persists
- Collection service → Neon Postgres: persists
- Collection service → Invoice lifecycle: creates obligations
- Internal invoice view → Invoice lifecycle: reads
- Public invoice → Invoice lifecycle: loads by token
- Public invoice → Nomba payment initiation: initiates payment
- Public verification API → Payment reconciliation: verifies transaction
- Nomba webhook → Payment reconciliation: submits event
- Nomba payment initiation → Nomba: creates accounts / checkout
- Nomba → Nomba webhook: payment callback
- Payment reconciliation → Invoice lifecycle: updates outcome
- Payment reconciliation → Neon Postgres: records payment
- Invoice lifecycle → Neon Postgres: reads and updates
- Payments and receipts → Payment reconciliation: shows outcomes
- Receipt viewer → Payment reconciliation: renders verified payment
- Schema and migrations → Neon Postgres: defines model