Inspiration

Every lending product we saw was rebuilt from scratch: a BNPL checkout here, a corporate card there, each with its own schedule maths, its own ledger, and its own bugs. But the core is always the same: disburse, schedule, accrue, collect, reverse, write off. We wanted one skeleton lending engine that any product can stand on, and to prove it by building two very different apps on top of it.

What it does

crediq.id is lending-as-a-service: a Go core engine plus an ops console and two demo apps that share it.

  • KiraPay (apps/bnpl-checkout): consumer Buy Now Pay Later: pay in 30 days (bullet) or in 3 or 6 monthly installments.
  • VaultCard (apps/vcc-corporate): a revolving corporate virtual card with two-phase authorize and settle, monthly statements, and freeze and unfreeze.
  • Ops console (lending-engine-ui): products, accounts, schedules, payments and a GL inspector, with role-based access (ADMIN, OPS, RISK, AUDITOR).

The engine handles:

  • Installment, bullet, mortgage-style and statement-based products
  • Amortization (flat and declining balance) and a FIFO repayment waterfall (penalty, fee, interest, principal)
  • A double-entry ledger: every financial event posts a balanced journal, and corrections are reversals, never edits
  • End-of-day processing through RabbitMQ: interest recognition, lateness, penalties, statements
  • The Indonesian OJK cap: interest plus penalties can never exceed a set share of the principal

$$\text{interest} + \text{penalties} \le c \times \text{principal}, \quad c = 1.0 \text{ (100\%) by default}$$

  • Multi-tenancy by company, idempotent mutations, and JWT auth with shared token revocation

How we built it

  • Backend: Go with Chi, Uber Fx, sqlx, PostgreSQL 16 and RabbitMQ, organised with DDD and CQRS. Aggregates own every state change, and a transactional outbox carries domain events to RabbitMQ and webhooks.
  • Money: exact decimals (shopspring/decimal), stored at 4 places and rounded half-up. The last installment absorbs the rounding remainder, so schedules always sum exactly to the principal.
  • Frontend: React, TypeScript, Vite and Tailwind behind Nginx. The demo apps are plain HTML and JavaScript talking to the same API.
  • Deploy: Docker Compose with Caddy for TLS on crediq.id.

We built it with Kiro using spec-driven development: three specs (security-fixes, ledger-and-eod, decimal-migration), each with requirements, a design and a task list. A task was ticked only with a commit and a test as evidence. Steering files kept Kiro aware of business invariants, such as "the ledger is immutable" and "every query is scoped by company", so its changes respected them.

Challenges we ran into

An audit register of 53 findings drove the work. Some of the hardest:

  • Floating-point money. Golden tests showed a flat 10,000,000 loan over 12 months summing to 9,999,999.9996. We migrated all stored money to exact decimals, with a test that fails if float maths creeps back in.
  • Principal counted twice. A 3,000,000 loan showed 6,000,000 after the first end-of-day run. The balance now moves only when the event happens.
  • Reversals that reversed nothing. Repayments weren't linked to their payment, so a reversal changed no balances.
  • Cross-tenant access. One company could read another's accounts. Every repository is now scoped by company, and a test calls every route that takes an id as another company and expects 404.
  • Lost money in edge cases. A ledger-reconciliation test, which runs a loan through its whole life and checks the GL against the account after every step, caught overpayments beyond the remaining principal silently disappearing.

Accomplishments that we're proud of

  • One core, two very different products (consumer BNPL and corporate revolving credit), with no product-specific forks.
  • The GL reconciles with account balances at every step of installment, bullet and card lifecycles, including reversals.
  • 129 test files: unit, golden, property-based, integration against real Postgres, and race tests.

What we learned

Reconciliation tests find bugs that unit tests miss: each part can be correct while the whole drifts. Specs with evidence-based tasks kept a large fix pass honest: no task was "done" without a commit and a passing test.

What's next for crediq.id

  • Penalty routing for CHARITY products
  • Connecting the ops console to the live API end to end
  • More product templates on the same skeleton

Built With

Share this project:

Updates

Submission history