Skip to content

Improvement: Merge Customers + Vendors into one Contacts entity #2618

Closed

Description

@Israeltheminer

What should be improved?

Tale has two Knowledge directories — Customers and Vendors — that are structurally near-identical contact records dressed in mismatched vocabulary. Neither carries real commercial semantics; both are functionally per-org address books. Consolidate them into a single Contacts entity.

This also fixes a correspondent-model defect: a conversation can only attach to a customerId, so every email correspondent (vendor, partner, colleague, anyone) is force-materialized as a "customer." The word is baked into the schema, not the result of any classification.

Current behavior

Customers (services/platform/convex/customers/schema.ts)

  • Fields are 100% identity / contact / provenance / governance: name, email, externalId, status, source, locale, address, metadata + soft-delete plumbing. No revenue, deals, orders, billing, owner, or pipeline — and no commercial tables (deals/orders/invoices/subscriptions) exist anywhere in the schema.
  • The only CRM-flavoured field, status (active|churned|potential), is written and displayed but never consumed — no branch, metric, automation, or view acts on its value. statusChangedAt is declared but never written for customers. The assess-customer-status workflow only writes it and no cron runs that workflow.
  • Records are auto-materialized: workflow_engine/action_defs/conversation/helpers/find_or_create_customer_from_email.ts mints a status:'potential' customer for any inbound/outbound email address. There is no intentional "this is a customer" flow.
  • Filed under the Knowledge nav, not Sales/CRM (app/features/knowledge/components/knowledge-navigation.tsx:51-54, route _knowledge/customers).

Vendors (services/platform/convex/vendors/schema.ts)

  • Same base fields as customers, plus phone, tags[], notes; minus the status enum. Same governance, RLS shape, list/table/import/edit/delete UI, parallel agent tools and workflow action — the tables were clearly copied from one another.
  • Nothing points at a vendor: no conversation or support_case FK, no email resolution, no domain events, not in global search. Created only via manual import / REST / agent / workflow.

The incoherence: the product already models a Customer/Vendor split, but the conversation layer ignores it — conversations/schema.ts:9 has only customerId: v.optional(v.id('customers')) (there is no vendorId anywhere), so a vendor's email is stored as a "customer."

Proposed change

Collapse Customers + Vendors into one Contacts entity — one contacts table, one feature dir, one nav item, one set of Convex functions / agent tools / workflow action / REST routes — and repoint conversations.customerId → contacts so any contact can be a correspondent. That last part is the actual fix for "every correspondent is a customer."

The only things that made "customers" different (the status enum, the conversation/case FKs, events, global search) are features that were only wired to that one table, not anything intrinsic to being a customer. So a flat Contacts model is clean — those features simply apply to all contacts.

Open decisions (needs discussion) — product calls, not mechanical:

  1. Flat vs discriminator. Recommended: flat contacts with an optional type/tag only if we still want to filter "customers" vs "vendors". A hard type:'customer'|'vendor' discriminator is only warranted if we deliberately keep FK/behaviour asymmetries; the audit suggests we don't need them.
  2. Fate of status. active|churned|potential is customer-lifecycle vocabulary that doesn't fit generic contacts and is never consumed today. Recommended: drop it (or replace with a neutral optional label).
  3. Vendor-only fields (phone, tags, notes) become standard optional contact fields.
  4. Search + events are customer-only today — decide whether all contacts become searchable / event-emitting (recommended: yes, uniform).

Blast radius (code pointers) — mirrored customer/vendor pairs at every layer:

  • Schema + migration: customers/schema.ts, vendors/schema.ts, schema.ts:154,299; repoint conversations/schema.ts:9,37 and support_cases/schema.ts FKs. Ships a versioned, reversible migration (migrations:check gate) that creates contacts, backfills both tables, and rewrites FKs.
  • Convex fns: convex/customers/* (~28 files, incl. find_or_create_customer.ts, get_customer_by_email.ts, search_customers.ts) + convex/vendors/* (~12) → one convex/contacts/*.
  • Conversation consumers: create_conversation*.ts, list_conversations_paginated.ts:111,118, transform_conversation.ts:42,48-49,80,160-168,198, reply_to_conversation.ts:85, find_or_create_customer_from_email.ts, conversation_action.ts:160.
  • Events: workflows/triggers/event_types.ts:64-79 (customer.* → contact.*; vendors emit none today).
  • REST: http.ts:1179-1214 (customers, 8 routes) + :1220-1250 (vendors, 6) → one /api/v1/contacts set.
  • Agent tools: agent_tools/customers/*, agent_tools/vendors/*; tool_names.ts:19,43,47-48; tool_registry.ts:13-14,48-49,73,97,101-102.
  • Workflow engine: action_defs/customer/customer_action.ts, action_defs/vendor/vendor_action.ts; action_registry.ts:6,19,44,48.
  • Governance / retention: governance/internal_mutations_retention.ts (customer + vendor deletes), builtin-configs/governance/retention.json, retention-policy.json, lib/shared/schemas/retention.ts:22, schemas/governance.ts:324.
  • RLS / permissions: lib/rls/helpers/access_control.ts, rls_rules.ts:224-248, auth.ts (per-role), lib/permissions/ability.ts:22,90.
  • Search: lib/search/strategies/customers.ts, lib/search/index.ts:12 (vendors not indexed today).
  • Frontend: app/features/customers/* (~23 files) + app/features/vendors/* (~16) → one app/features/contacts/*; routes _knowledge/customers.tsx + vendors.tsx → contacts.tsx; nav knowledge-navigation.tsx:13-59, use-navigation-items.ts:112-122.
  • i18n: messages/en.json customer + vendor blocks (e.g. :1935,1992,2034,2080-2139,2166-2167,4049,4079-4081,7621-7670) and the parallel de.json / fr.json blocks (native voice, not literal — see write-translations).

Acceptance criteria

  • A single contacts table replaces customers and vendors, with a versioned, reversible migration that backfills existing rows and passes migrations:check.
  • conversations (and support_cases) reference a contact; a correspondent from any source is no longer labelled "customer" in schema or copy.
  • Open decisions 1–4 resolved and reflected in the schema (discriminator/tag, status fate, vendor fields, search/events).
  • One Contacts feature (list / view / edit / import / delete), one nav item under Knowledge, one route.
  • Convex fns, agent tools, workflow action, REST routes, events, RLS/permissions, retention consolidated to contacts; no dangling customers/vendors symbols.
  • All user-visible "Customer"/"Vendor" strings reframed to "Contact" across en, de, fr (native voice, not word-for-word).
  • bun run check green; conversation correspondent display verified end-to-end.

Related (closed) — all symptoms of the parallel-but-divergent customer/vendor duplication this consolidates: #2060 (customer/vendor name-parity), #1993 (dup website/customer/vendor add), #1978 ("Unknown Customer" i18n), #1996 (conversation search misses customer name).


Grounded in a full read of the customers/ and vendors/ domains (schema, Convex functions, agent tools, workflow actions, REST, governance, i18n); the file:line anchors above are from that audit. Deduped against open and closed issues — no open duplicate.

Activity

  1. added
    needs discussion
    improvement
    service: platform
    on Jul 9, 2026
  2. yannickmonney commented on Jul 11, 2026

    @yannickmonney
    Contributor

    Verification (2026-07-12): the merge's code-level ACs are met on main + PR #2674. Evidence: convex/customers and convex/vendors are gone; one flat convex/contacts/schema.ts (no type discriminator, no status enum — matching all four open decisions: flat model, status dropped, vendor fields standard, uniform contact.* events + search strategy); REST is /api/v1/contacts only; agent tools, workflow actions, RLS reference only contacts; migrations:check green.

    Two loose ends, neither a functional bug: (1) conversations/support_cases schemas still carry the transitional customerId field documented as expand-contract leftover — the contract phase (dropping it) hasn't landed; (2) settings.logs.audit.actionLabels.customer/vendor locale keys are deliberately kept for historical audit rows (the orphaned trash-tab keys were removed in PR #2674).

    Recommend closing this epic once #2674 merges, or keeping it open only to track the customerId contract phase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    improvementneeds discussionservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions