← All work03 / 03

ProtectPay

A platform for private car sales in Israel: a seller lists a vehicle, buyers send structured offers, and the chosen pair close the deal together in a shared realtime Trade Room.

Type
Car sale trust platform
Role
Development: architecture, API, data model, realtime delivery and the web client.
Status
In development · phases 0–15 built
Stack
NestJS · Fastify · Prisma · PostgreSQL · Socket.IO · React · Zod
01

Problem

Selling a used car between strangers runs on phone calls, screenshots and trust. Offers arrive in different shapes, vehicle facts are hard to check, and once two people agree there is no shared record of what they agreed to. ProtectPay gives the process a structure without claiming more than it can verify.

02

Architecture

A pnpm monorepo: a NestJS API on Fastify, a React web client, and a shared contracts package holding the Zod schemas, types and state machines both sides use. PostgreSQL through Prisma is the single source of truth. Every state change writes its domain event and an outbox row in the same transaction; a relay polls the outbox with retries and back-off and delivers to the Trade Room over Socket.IO and to in-app and push notifications, only after the commit. Vehicle facts come from the Israeli government open-data registry and are kept as snapshots that offers reference. Participants verify a phone number with a one-time code instead of creating an account.

shared contracts: Zod schemas · state machines · types, used by the API and the webone transactiondelivered after the commitWebReact, ViteAPINestJS, FastifyPostgreSQLstate, events, outboxOutbox relayretries, back-offTrade RoomSocket.IOVehicle datadata.gov.il registryNotificationsin-app, push
Simplified architecture, drawn from the code.

16 of 17 phases complete · select a phase

Phase 15 · Complete

Pilot measurement

Product events, the pilot dashboard, decision data.

03

Key decisions

  1. 01

    Commit first, notify after

    State, domain event and outbox row are written in one transaction. Realtime notices and notifications leave only from the outbox, so nobody is told about a change that did not commit.

  2. 02

    Offers are immutable

    A database trigger refuses to rewrite an offer's commercial content. A counteroffer is a new row with lineage, and a material change in the vehicle facts makes the buyer acknowledge it before a deal can exist.

  3. 03

    One selection at a time

    A unique index allows a single selection lock per sale, and selecting an offer does not create a trade yet: the buyer reconfirms the exact offer first.

  4. 04

    Facts, not scores

    A trust signal states what was observed ("phone ending 4821 verified"), never a rating of a person. The platform makes no identity or ownership claim, and a lint rule rejects the word "escrow" until a regulated layer exists.

04

Stack

Interface
React · Vite · React Router · TanStack Query · react-hook-form
Services
NestJS · Fastify · Socket.IO
Contracts
TypeScript · Zod · Shared state machines
Async
Transactional outbox · Relay with retries and back-off
Data
PostgreSQL 17 · Prisma · data.gov.il vehicle registry
Quality
Vitest · ESLint · Acceptance walks on a real database · GitHub Actions CI
05

Tradeoffs

  • Polling the outbox adds up to a second of latency and a table to sweep, in exchange for notices that can never describe an uncommitted change. Under load one batch per tick was too slow, so a full batch now keeps claiming more.
  • Verifying a phone instead of an identity keeps joining down to a one-time code, at the cost of a weaker identity signal; the product states exactly what was verified and claims nothing more.
06

Outcome

Phases 0–15 of the roadmap are built: vehicle lookup, offers and negotiation, the Trade Room, inspection, agreements and closing, dealer tools, attribution and pilot measurement. Phases are checked by scripted acceptance walks against a running API and a real PostgreSQL database.