Skip to content

Client CRM

The client record — profiles, consent, tags, notes, history, and duplicate management.

6 min read

Overview

The Client CRM is the record for every person a brand serves. Scheduling books against it, marketing segments it, retention tracks entitlements against it, and finance links invoices to it.

The front desk creates a client in seconds for a walk-in (name + phone). The profile is then enriched over time: consent, notes, tags, and a visit and purchase history that builds from appointments and invoices.

Client Profile Fields

The clients table holds one value per field:

Field Notes
display_name A single name field (no first/last split)
phone One number; unique per org (see below)
email One address; unique per org, case-insensitive
birthday Drives birthday segments and automation
gender Optional; also used for same-gender stylist matching in online booking
preferred_language Defaults to en
status active, lapsed, do_not_contact, blocked
notes A single free-text summary field (separate from the timestamped notes below)
tags Legacy text array; the Tags tab uses the controlled client_tags list instead
notification_prefs WhatsApp reminders, email reminders, promotional (set by the client in the portal)
registration_location_id The location the client was created at
visit_count, last_visit_at Maintained counters

There is no profile photo field, and no support for multiple phones or emails on one record.

Scope and Isolation

  • A client row carries both org_id and brand_id; staff and RLS see clients through their org membership, and store-scoped members only see clients tied to their store.
  • Phone and email uniqueness is enforced per org, not per brand (clients_phone_unique on (org_id, phone) and clients_email_unique on (org_id, lower(email))). Creating or editing a client with a phone or email already used by another client in the org fails with "A client with this phone number already exists." So the same phone number cannot be held by two records, even across brands of one org.

Staff capture consent on the client form. Only three consent rows exist in the UI (client_consents, unique per client, purpose and channel):

Form checkbox Purpose Channel
Transactional WhatsApp transactional whatsapp
Marketing email marketing email
Data use data_use all

Each row stores granted, granted_at, the acting user, and source (always staff from this form). Saving upserts the row, so only the current state is kept: a change overwrites the previous timestamp and actor, and there is no append-only consent history. On the edit form an unticked box is saved as a withdrawal, and only changed consents are written.

How consent is enforced:

  • Marketing journeys and campaigns skip a client who has an explicit granted = false row for marketing or transactional consent on the channel (or all). No row means no refusal, so the client is allowed. If consent cannot be read, everyone is treated as opted out.
  • A client who replies STOP on WhatsApp is recorded as a refusal by the AI agent's opt-out handling (lib/ai/whatsapp-opt-out.ts).
  • Consent older than 180 days can be detected with isConsentExpired, but this is a helper, not an automatic re-consent flow.

India DPDP

There is no in-app data-subject tooling: no per-client data export, no anonymise or erasure action, and no correction-request workflow. What exists today:

  • The public /data-deletion page tells people to email support; Kagami confirms identity, passes the request to the salon, and replies within 30 days. The deletion itself is carried out manually.
  • Owners can download a full org export (/api/org/export) and a client CSV (name, phone, email, notes) from Data Import.
  • deleteClientAction hard-deletes a client and writes an audit log entry, but it is refused if the client has appointments or invoices (it advises deactivating instead). It does not anonymise.

Tags and Segments

Tags: managed on the client's Tags tab. A brand defines a tag list (name + colour, unique per brand) and staff assign or remove tags. Assignments record only when they were made, not who made them.

Segments exist in two places:

  • Client list quick filters (client-side, computed over the loaded clients): All, VIP (carries a vip tag), Lapsed (status lapsed or no visit in 90 days), Birthdays (birthday this month).
  • Marketing segments (segments, see marketing.md): saved rule-based audiences of type vip, lapsed, birthday, by_service, rfm or manual, with filters such as minimum visits, spend, lapsed days, service ids, RFM score or an explicit client list.

Notes

The client detail page has seven tabs: Notes, Tags, AI Styling, Visit History, Packages, Memberships, Wallets.

Timestamped notes (client_notes) have a type (general, formula, allergy, preference, appointment), content, a private flag, and the author. Notes can be added and deleted; there is no edit action and no edit history. A private note can only be deleted by its author. Allergy and formula are note types, not separate structured fields; there is no dedicated allergy or contraindication record.

Visit and Purchase History

The Visit History tab shows billed visits as clickable invoice rows, with unbilled bookings listed below. Packages, Memberships and Wallets tabs show the client's active entitlements. The record also carries visit_count and last_visit_at. The AI Styling tab generates style suggestions that can be saved to notes.

Duplicate Handling and Merge

At creation and edit, the only duplicate check is an exact match on phone or email within the org, which blocks the save with an error. There is no name-similarity matching and no "open the existing record" prompt.

Merge is a single bulk action on the Clients page ("N duplicate clients found (same phone number)" with a Merge All button), restricted to roles with the clients.merge permission:

  1. Clients in the org are grouped by identical phone. The oldest record in each group survives; there is no choosing a survivor.
  2. Appointments, invoices, queue entries, gift cards, messages, notes, packages, memberships, loyalty and store-credit ledgers, wallets, referrals, journey enrollments, tag assignments and consents are re-pointed to the survivor. Where both records have the same tag or the same consent purpose and channel, the survivor's row wins (so a withdrawal on the discarded record is lost, not applied).
  3. visit_count is summed and last_visit_at takes the later value.
  4. The duplicate rows are deleted. There is no merge audit record and no undo; the confirmation dialog says it cannot be undone.

Merging by email or name is not supported. The database function is merge_client_duplicates, now callable only with the service role (migration 0184).

Quick-Create vs Full Profile

Quick-create (createClientDirectAction, used from billing and booking pickers): name + phone. Full form: name, brand, status, phone, email, birthday, gender, language, notes and the three consent boxes. A sparse profile never blocks booking or checkout. Store-scoped staff get the active store set as registration_location_id so the new row stays visible to them.

Client Self-Service (Portal)

After OTP login (see client-surfaces.md), a client can edit their display name, email and notification preferences (WhatsApp reminders, email reminders, promotional). They cannot change their phone number, status, staff notes or consent rows, and see no financial data beyond their own wallet, vouchers and receipts.

Key Data Entities

  • clients — identity, contact, status, brand and org scope
  • client_consents — purpose, channel, current state, timestamp, actor, source (one row per combination)
  • client_tags / client_tag_assignments — controlled labels per brand and their assignments
  • segments — marketing audience rules
  • client_notes — typed, optionally private notes (no versioning)