Pure Inbounds
Written byWill Pei YuanPureInbounds runs a pay-per-call network for insurance agencies: it buys the media and routes inbound Final Expense calls, and an agency’s licensed agents answer them. I designed and built the platform the business runs on — the public site and its lead forms, agency and agent onboarding with a certification gate, a browser softphone, call routing that holds a licensed, available agent for each call, reporting on every call and the money behind it, and an AI review of call transcripts. First commit to production release took thirty-three days.
- Role —
- Design and build, end to end, as the sole engineer under a fixed-scope contract: product design, the data model, every integration, the public website, testing, deployment and the runbook. The client owns the code.
- Timeline —
- October 2026 — ongoing. Foundation, admin and call ingestion October 15–17; integrations and AI call review by October 22; the app on its own domain October 24; multi-agency onboarding November 4–6; the browser softphone November 11–15; production release and the platform’s own call routing on November 16.
- Stack —
- Next.js 16 (App Router), React 19, TypeScript, PostgreSQL (Neon), Drizzle ORM, Better Auth (two-factor), Tailwind CSS, Vercel, Vercel AI SDK via AI Gateway, Telnyx (WebRTC softphone), Ringba API, Resend, Didit (ID verification), Rollbar, Vitest with PGlite, GitHub Actions
The problem
A pay-per-call network sits between publishers who send phone calls and agents who answer them, and it earns on the difference. PureInbounds had the calls and the buyers and was running on a third-party call platform, with no system of its own to manage agencies, agents, campaigns and publishers, to see each call and what it cost and earned, or to control who is allowed to pick up. The product goal was written down in one line: users sign in, add their agents, and focus on taking calls. Because the calls are insurance sales, an agent has to be licensed in the caller’s state and cleared before the phone ever rings.
What I built
The public site at pureinbounds.com explains the offer in four steps and takes two kinds of enquiry: an agency asking for access and a publisher offering traffic. Each form saves to the database first, with the consent text the visitor agreed to and where they came from, then emails the team and pushes the contact into the client’s CRM pipeline. The save comes first so that a CRM outage can never lose a submission.
Behind sign-in is the platform itself, with six roles from super admin to agent and every query filtered on the server by what that person may see. An agency is invited, takes a leadership quiz, accepts an agreement and waits for approval. Each of its agents records an NPN and at least ten licensed states, watches every training video, passes a certification quiz graded on the server, verifies their identity by scanning a licence and a selfie, and accepts an agreement. Until all of that is true, the call station stays locked. Nobody is sent a password: sign-in and invitations are one-time links, and two-factor is required for anyone who administers an agency.
An agent takes calls in the browser. They pick a campaign, set themselves available, and a softphone built on WebRTC rings when a call is theirs; afterwards a wrap-up step asks for the outcome, and a sale needs its annual premium. A caller’s number stays hidden from the agent until the call is billable. Two missed calls in a day takes an agent out of rotation for half an hour.
Routing is the centre of it. When a publisher’s system asks whether a call can be taken, the platform works out the caller’s state, finds an agent who is live, licensed there, onboarded and free, holds that agent for the call, and answers. The first version answered a third-party call platform’s pings; on the day of the production release the platform began routing calls itself, with a key per publisher per campaign, a test endpoint for publishers setting up, and a cascade to as many as three agents before a call is declined.
Every call lands in a log with its recording, its campaign, publisher, buyer and agent, and its money in whole cents. Dashboards break that down by day, week or month into premium sold, call spend, net profit, close rate, cost per acquisition and return. A scheduled job reconciles the platform’s daily totals against the call platform’s own. An AI review reads each call’s transcript and returns a short summary, a score and flags for calls that are not genuine or raise a compliance concern; it is built and switched off by default until the client turns it on.
Design decisions
How it looks and moves, and why.
Two products, two front doors
The marketing site and the app share a codebase and a database but not a look. The site has its own layout, type (Inter and Space Grotesk) and scroll-led motion, and lives on the bare domain; the app is a dark, dense working tool on its own subdomain. One deploy serves both, and the host decides which a visitor sees.
The call station shows why you cannot go live
An agent who is not yet cleared does not meet a disabled button. "Start here" lists each requirement — licence number, states, videos, quiz, ID check, agreement, agency approval — with what is done and what is left. The same checklist is what the routing query uses, and a test fails the build if the screen and the router ever disagree about who is ready.
Publishers stay anonymous to the people answering
Agencies and agents see call quality without ever seeing who sent the call. Publisher names never reach them, and a super admin who needs to see what an agency sees can open its portal read-only, with each use recorded in the audit log.
Decisions worth explaining
The engineering, for anyone who wants it.
Holding an agent with a row lock, not a queue
Two calls must never be promised the same agent. Each availability request runs one query that selects a free, licensed agent and locks that row, skipping any row another request already holds. Holds and presence stay in Postgres; there is no Redis and no queue to keep in step with the database. In a load test the endpoint answered 2,500 requests a minute with a 99th percentile of 59 milliseconds.
A softphone, so the caller’s number can stay hidden
Hiding a caller’s number until a call is billable only works if the call never reaches the agent’s own phone. So calls ring in the browser. Presence is an HTTP heartbeat every fifteen seconds, because serverless functions do not hold sockets open, and when an agent has two tabs open the newest one wins.
Webhooks that are safe to receive twice
Telephony events arrive signed, sometimes late and sometimes twice. Each is verified, checked against a five-minute clock window, and recorded before any command is sent back, so a repeated event can never ring or bridge a call a second time. Once an event is accepted the platform answers success even if handling fails, because an error would make the provider retry and run the commands again.
An AI review priced per call
A fast model screens every transcript; only calls it flags or scores poorly go to a stronger one. Silence is measured from word timings, not left to the model’s judgement, and the transcript is treated as untrusted text that cannot give the model instructions. The client’s own API key is used per request, so the model provider bills them directly. The documented estimate is about a quarter of a cent a call.
The database only moves forward
The app can be rolled back in a moment; the database cannot. Migrations are additive only and run as part of the build, so a failed migration stops the deploy. Nothing is deleted, only deactivated, and important changes are written to an audit log.
Tests against a real Postgres
Each server function takes the database and the acting user, checks permission itself, and is tested against an in-process Postgres with every migration applied. Some ninety test files and seven hundred cases run in CI with the typecheck, lint and build on every pull request. A watchdog runs every five minutes in production and emails when agents are available but no calls are being offered: uptime says the site answers, this says calls can flow.
The stack, and why
Each layer, what it runs on, and what it was picked over.
- Framework
Next.js on Vercel
One codebase serves the public site, the app and the webhooks, and scheduled jobs handle sync, reconciliation and the watchdog.
- Database
Postgres on Neon, with Drizzle
Money, holds and presence need transactions and row locks. Staging and production are separate databases, and a restore was rehearsed before launch.
- Auth
Better Auth
Email sign-in with open sign-up disabled, roles, and required two-factor for anyone administering an agency.
- Telephony
Telnyx WebRTC
A number and credential per agent, so an arriving call maps to exactly one person, and the browser signs in with a short-lived token minted by the server.
- AI
Vercel AI SDK through AI Gateway
Structured output from two model tiers, with the models, thresholds and a daily limit editable by an admin.
- Identity
Didit
A licence and selfie check from a QR code. The platform keeps the result and its date, never the images.