loader
Ibai Fernández

Active Context: Corporate View

DebTracker dashboard

Full-Stack Financial Architecture / Next.js 15 PWA

DebTracker: Zero-Trust Financial Ledger

DebTracker is a modern web application built for type safety, performance, and serverless scalability. I engineered this platform to compete directly with industry incumbents like Splitwise by offering a "Purist's Choice" - respecting user time and data by eliminating ad interruptions, artificial transaction limits, and "monetization by friction".

The Architectural Paradigm

To ensure the absolute integrity of financial data, I deployed a strict Zero-Trust, Server-Authoritative write model. In this architecture, the client SDK is entirely read-only. Every financial mutation is routed through Next.js Server Actions, centralizing validation and enforcing complex business logic natively on the server. By implementing a snapshot strategy and denormalizing data at write-time, I eradicated the N+1 query problem, replacing iterative fetching with highly efficient collection group queries.

zero-trust-security.log


						

Implacable Business Logic

Code is useless if the business logic is flawed. DebTracker operates under three unbreakable systemic protocols:

Demo visualization uses deterministic iteration so you can track the extra cent. Production logic uses the Fisher-Yates randomization shown above.

The Penny Perfect Protocol

The system adheres to the Law of Conservation of Money. Instead of standard division, it utilizes a randomized distribution (Fisher-Yates Shuffle) to handle algorithmic remainders, ensuring that not a single cent is ever lost or created out of thin air when splitting complex bills.

The Liar Filter (Settlement Handshake)

A zero-trust approach to debt clearance. When a debtor claims to have paid, the transaction is marked solely as pending. The debt remains visible in the system balances until the Creditor explicitly confirms receipt of the funds.

The No-Escape Integrity Rule

A systemic blockade preventing users from abandoning groups or deleting their accounts if their calculated liability is not exactly zero (with a 0.01 floating-point tolerance).

penny-perfect-protocol.ts

export function distributeAmount(totalAmount: number, numberOfSplits: number): number[] {
  if (numberOfSplits <= 0) return [];
  if (numberOfSplits === 1) return [Number(totalAmount.toFixed(2))];

  // Work in cents to avoid precision loss
  const cleanTotal = Math.round(totalAmount * 100);

  // Integer division + remainder
  const baseAmountInt = Math.floor(cleanTotal / numberOfSplits);
  const remainderInt = cleanTotal % numberOfSplits;

  // Base amount for all participants
  const splits: number[] = new Array(numberOfSplits).fill(baseAmountInt);

  // Participant indexes
  const indices = Array.from({ length: numberOfSplits }, (_, i) => i);

  // Fisher-Yates: randomize who gets the extra cents
  for (let i = indices.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [indices[i], indices[j]] = [indices[j], indices[i]];
  }

  // Assign +1 cent to the first "remainderInt" participants from random order
  for (let i = 0; i < remainderInt; i++) {
    splits[indices[i]] += 1;
  }

  // Convert back to currency units
  return splits.map((s) => s / 100);
}

Native PWA & Device Integration

Beyond database architecture, DebTracker is built as a first-class citizen on mobile devices. By leveraging the Web Share Target API, I engineered a service worker interception protocol that allows users to seamlessly share receipt images directly from their native OS gallery into the application's file storage, bypassing traditional browser upload friction.

Break the Ice

Let's Get In Touch

Contact Me

Translate Button