Skip to main content

Companies — how this works

In the app: /companies

How it works

Every lead is grouped by the SAME leadDedupeKey() HYGIENE-05 already uses to find duplicates (its website's apex domain, or a canonicalized name + jurisdiction when there's no website) — a duplicate-lead group and an account rollup are, by construction, the same partition. Rolling up is an EXPLICIT, admin-triggered action ("Group leads into companies") — never a page-load side effect and never a migration backfill: Lead.companyId stays null until a sync runs. The account score is the best-of the group's own Lead.score values (A beats B beats C), computed LIVE at read time — never cached on the Company row — so an erased (DSAR) lead simply stops contributing on the very next read, with no stale value to invalidate and no extra erasure step needed.

Data source

src/lib/crm/company.ts (pure rollup + scoring) + src/lib/crm/companyRepo.ts (the Lead scan, upsert, and read).

Troubleshooting

A lead you know exists isn't showing under any company? Click "Group leads into companies" — it only ever assigns companyId when it runs, so a lead created (or re-scored) since the last sync is simply not rolled up yet. Two businesses you'd expect to be separate merged into one company? Check their website domains — leadDedupeKey() groups on the apex domain, so two different storefronts sharing one domain (or two leads with no website and near-identical names) will roll up together; that's the same grouping HYGIENE-05's duplicates panel would flag.

Who can see this: admin, closer