Backend/Network

Network

Network is worked out from the records the app already has. This page covers the data model, how relationship strength is scored, and how to feed it real email, calendar and CRM activity.

What the demo does today

NetworkProvider (src/components/providers/network-provider.tsx) calls buildNetwork in src/lib/data/network.ts with the session's records: customer contacts, contacts on open leads, contract signers, meetings, message threads, notes, tasks and, once a mailbox is connected, synced email. It matches the same person across those records by email (within a company), then by name and company, and returns one NetworkPerson each, strongest first. Nothing about a person is stored apart from their contact record: change the records and Network follows.

buildNetwork is a pure function. You can call it on the server with records from your database, cache the result, and pass it to the provider, without changing a screen.

The data model

FieldWhat it holds
idThe contact id, the lead contact id, or px-… for someone only seen in email
sourceIdsEvery record this person was matched from
customerIds, leadIds, contractIdsWhat they're linked to; signerOf lists contracts they sign
touchesEvery meeting, email, message, note and task, with the teammate on our side and a link
score, strength, reasonThe relationship, and why, in plain words
knownByTeammates by number of contacts; the account owner is always listed
tagsChampion, Decision maker, Signer, Billing, Technical, Prospect

How strength is scored

The score only looks at the last 90 days. Each meeting counts 3, each email or message 1, each note or task ½. Anything in the last 7 days counts double, and anything 31 to 90 days old counts half. A score of 8 or more is Strong, 3 or more Good, anything above 0 Weak, and nothing in 90 days is Cold. "Going cold" means three or more past contacts and none in 14 days or more (COLD_AFTER_DAYS).

The rules are in scoreTouches, strengthReason and isGoingCold. Change the weights or thresholds there and every screen, dashboard card, Rune answer and workflow uses the new ones.

Use real activity

Store touches as they happen: a row per meeting attendee, email participant and message author, with the person's email, the time, the kind and the teammate.

Touches table (SQL, Supabase example)
create table touches (
  id bigint generated always as identity primary key,
  workspace_id uuid not null,
  person_email text not null,
  company_id bigint references customers(id),
  kind text not null check (kind in ('meeting','email','message','note','task')),
  at timestamptz not null,
  title text,
  teammate text,
  href text
);
create index on touches (workspace_id, person_email, at desc);

Fill it from the sources you connect: your calendar provider's events (attendees outside your domain), your mailbox sync (see Email), and the app's own meetings, messages, notes and tasks when they're saved.

Load the last 90 days of touches with the people and pass them to buildNetwork, or score in SQL with the same weights for large workspaces and send the provider the finished list.

Email from your own domain is a teammate, not a contact. The demo decides that with isTeammate; check the domain against your workspace's domains instead.

Store people and edits

People added in Network are contacts at a customer: addPerson, updatePerson and removePerson call addContact, updateContact and removeContact in CustomersProvider. Save those to your contacts table (see Database) and Network keeps up on its own. People from leads and email are read-only here, by design.

Who knows whom

knownBy counts past touches per teammate. With real data, use the teammate on each touch (the meeting organiser, the email sender) and the account owner. The map, the "Who knows them" list, Rune's warm-introduction answer and the "Relationship goes cold" workflow (which gives the task to the closest teammate) all read it.