Skip to content
Audience view:

04 / 06·2026

Lead Compass

A research engine that finds real companies and explains why they are a lead.

Role
Architecture, pipelines, Next.js app
Source
Private repo
Lead Compass

01

Context & my role

Role: Architecture, pipelines, Next.js app

00

At a glance

Lead Compass: how it works
  1. Search providersInput

    Serper · Brave · Tavily

  2. Validate, crawl, extractProcess

    robots.txt · rate limits

  3. Evidence packProcess

    committed to Postgres first

  4. Deterministic lead scoreGuardrail

    pure function, not the model

  5. LLM writes the explanationAI step

    labelled fallback sentence

  6. Explained, scored leadOutput

How the system works, top to bottom. Accent steps call a model; dashed steps are rules enforced in code, so the model cannot override them.

AI step Guardrail enforced in code Processing

02

Problem

Lead lists bought from data vendors are stale and unexplained. A model asked “does this company need software?” will always say something — the value is entirely in what it refuses to say.

The design bias throughout is accurate companies over scraping volume: read six pages of one real business rather than a hundred pages of directories.

03

Approach

Two pipelines, each a chain of small modules that fail independently. Discovery: generate queries → search (Serper, Brave, Tavily or a keyless provider behind one interface) → normalise and de-duplicate → validate the website → crawl relevant pages with robots and rate limits → extract company facts → detect buying signals → store.

Intelligence runs only after the crawl is committed: build an evidence pack from the database → company profile → opportunity analysis → contact extraction and verification → data confidence → lead score → written explanation.

Because analysis reads from the database and never from a crawl in flight, a model outage costs an analysis, never a page — and a lead can be re-analysed months later without visiting anyone's website.

04

Architecture

commitevidence packResearch runNext.js routeSearchprovider-agnosticCrawlrobots · limitsExtract + signalscheerioPostgressources · signalsAnalysisprofile · contactsLead scorerpure · deterministicExplanationLLM w/ fallback

05

Implementation

  • 01Scores are computed, not asked for. `lead-scorer.ts` is a pure function; the model only turns the breakdown into the sentence at the top of the lead, and when that call fails a deterministic sentence is written and labelled as such.
  • 02Confidence is derived from source count, identity completeness, contact quality, signal checkability and freshness — never from the model's tone.
  • 03The lead pipeline `new → qualified → shortlisted → contacted → replied → meeting → proposal → won` (plus `lost`, `rejected`, `archived`) is enforced in Postgres; every move is written to `lead_status_history` by a trigger.
  • 04“Research again” is non-destructive: sources are upserted by URL, signals are inserted only when new, company fields are merged rather than blanked, and `lead_scores` is append-only so the previous score survives as history.
  • 05Vitest covers the scoring module; Zod validates every API boundary; four migrations define the schema, AI intelligence tables and the pipeline.

06

Outcome

  • Internal tool, not publicly deployed. The repo stays private.
  • The engineering docs (discovery engine, intelligence layer) are the kind of HLD/LLD written for every client engagement.

07

Stack

  • Next.js 15
  • TypeScript
  • Supabase
  • OpenAI-compatible API
  • Cheerio
  • Zod
  • Vitest

Skills evidenced: Next.js · React · TypeScript · Supabase · PostgreSQL · OpenAI API · Node.js · Workflow automation

Next case study

Doc Hangout →

A professional network for verified doctors — case discussions, real-time messaging, communities.