# CRM-002 Sales Command Center: schema mapping for CRM-001

**Task:** CRM-002 (Claude). **Depends on:** CRM-001 (Omni) schema acceptance. **Date:** 2026-11-30. **Status:** submitted for review, not self-approved.

Omni owns the CRM-001 schema and audit model. This file is the **contract** the CRM-002 interface reads. Accepting CRM-001 means filling in the Airtable table and field IDs in section 3. That is a config change in `crm.airtable_map`, not a code change. If Omni's schema differs from this contract, the mapping absorbs the difference. Fields Omni doesn't provide show as "not mapped" and are never filled with guesses.

## 1. What was checked on 2026-11-30 (base appKKKYKV482C7s1x)

| Item | Observed |
|---|---|
| CRM-001 assignment (AI Assignments `recsnHVt7FcGg74j5`) | Status **Submitted**. Not accepted. |
| Organizations / Contacts / Opportunities / Activities / Suppression / Observation / Verification tables | **None exist yet** |
| Leads `tblfxMbIUe58nlPc4` | Exists, 29 fields. COO audit reports 0 records. |
| Command Center v1 (`/command/`, Drive 1mE3_BDMSnmibgdnvrsrneDC_XlS73uXQ) | Read-only task dashboard, no Sales module. CRM-002 adds `/command/crm/` beside it and changes no v1 file. |

## 2. Storage split and capacity (verify before any bulk sync)

Airtable counts records across **every table in a base**. Published caps are 1,000 (Free), 50,000 (Team) and 125,000 (Business, self-serve). Sales-led Business and Enterprise plans aren't published. **This base's plan tier was not verified.** The owner or Omni needs to confirm it in Airtable → workspace settings → usage.

| Volume at the 22-day target | Estimate | Fits in Airtable? |
|---|---|---|
| Qualified contacts | 33,000 | Over Free. About two-thirds of a Team base by itself. |
| Organizations (Apollo ratio 654 orgs / 810 people ≈ 0.81) | up to ~26,600 | Contacts + orgs ≈ 59,600: **over Team**, about half of Business |
| Field observations (≈8 contact fields + ≈6 org fields, one row per provider per field) | ~424,000 or more | **No plan except Enterprise** |
| Verification events | grows with checks | No |

**Recommendation for Omni (no new spend):**
- Keep raw observations, verification events, the audit log and the outbox in **MySQL on the existing InboundGold cPanel VPS** (`crm_*` tables, `schema/crm_mysql.sql`).
- Airtable holds the qualified CRM entities, plus per-provider/batch/field **summaries** if Omni wants them visible there.
- Raw bulk acquisition (Lead Carrot's 25,000 raw rows) stays outside both until it is qualified, as CRM-001 already requires.

MySQL capacity, PHP version and disk on the VPS are recorded in the Infrastructure Capability Inventory table, but they aren't verified for this load. That's step 1 of the deploy.

## 3. Contract → CRM-001 Airtable mapping (Omni fills the right-hand column)

Every row carries `is_test` (1 = synthetic fixture). Production mode excludes those rows everywhere.

### organizations
| Contract column | Meaning | CRM-001 field ID |
|---|---|---|
| id | Airtable record id (stable) | (record id) |
| name, website, industry, size_band, revenue_band | Firmographics | ___ |
| org_type | prospect, client, nonprofit, sponsor, donor, referral_partner, certified_partner | ___ |
| city, state, country | Geography | ___ |
| nonprofit_ein, nonprofit_class | EIN (99-9999999) and IRS class, e.g. 501(c)(3) | ___ |
| owner | Account owner | ___ |
| is_test | Synthetic flag (checkbox) | ___ |

### contacts
| Contract column | Meaning | CRM-001 field ID |
|---|---|---|
| org_id | Link to organization (first linked id) | ___ |
| full_name, title, email, phone, linkedin | Canonical (current best) values | ___ |
| lifecycle_stage | raw, lead, mql, sql, customer, former_customer | ___ |
| suppressed, suppression_reason | Never cleared by CRM-002 | ___ |
| consent_status | unknown, opt_in, opt_out | ___ |
| duplicate_of | Surviving contact id when merged | ___ |
| acquisition_batch_id | First-touch attribution, links to batch | ___ |
| owner, is_test | | ___ |

### opportunities
| Contract column | Meaning | CRM-001 field ID |
|---|---|---|
| org_id, contact_id, name, offer | | ___ |
| stage | New lead, Contacted, Qualified, Proposal, Won, Lost (same as the admin portal) | ___ |
| amount_one_time, mrr | One-time value and monthly recurring value | ___ |
| next_action, next_action_date, owner | | ___ |
| opened_at, closed_at, renewal_date, churned_at | | ___ |

### stage_history, activities, payments, batches
| Table | Contract columns | Notes |
|---|---|---|
| stage_history | opportunity_id, from_stage, to_stage, changed_at | Needed for stage aging. Without it, aging is measured from opened_at. |
| activities | contact_id, org_id, opportunity_id, kind, outcome, summary, actor, occurred_at | outcome `no_answer` / `no_reply` is never treated as "inaccurate data" |
| payments | org_id, opportunity_id, amount, kind (one_time/recurring), status (paid/failed/refunded), paid_at, external_ref | external_ref = Stripe id once the Stripe webhook is authorized |
| batches | provider, label, acquired_at, raw_count, cost_usd, enrichment_cost_usd, permission_note | Leave cost **empty when unknown**: empty is reported as Unknown, 0 as $0 |

### Config shape (in `admin.inboundgold.com/config.php`, never in chat)
```php
'entity_source' => 'airtable',
'airtable_map' => [
  'organizations' => ['table' => 'tblXXXXXXXXXXXXXX', 'fields' => ['name' => 'fldXXXXXXXXXXXXXX', 'org_type' => 'fld…', 'is_test' => 'fld…' /* … */]],
  'contacts'      => ['table' => 'tbl…', 'fields' => [ /* contract column => field id */ ]],
  // opportunities, stage_history, activities, payments, batches
],
```

## 4. Existing Leads table (preserved, read-only)

CRM-002 reads Leads by **field ID**, so renaming a field can't break it. It never writes to Leads and never calls the Zapier or n8n intake endpoints. Mapping into the CRM-001 entities (for Omni's promotion rule):

| Leads field (ID) | → Contract |
|---|---|
| Lead Key `fldTc3cK7CTdvQWbL` | dedupe key; stays the intake idempotency key |
| Contact Name `fldFBPdMScIwhHAdB` | contacts.full_name, plus observation `full_name`, provider rosie/website |
| Organization `fldMRycnOliDLreuf` | organizations.name, plus observation `employer` |
| Email `fldGEiKg8elki6Mkf` / Phone `fldlRaencUv5unhxt` | contacts.email / phone, plus observations |
| Source `fldVaj7Jff70wRy0f` | observations.provider (rosie, website) and the batch provider |
| Source Event ID `fld5F5ykfwqVoxXG6` | observations.external_id (the Rosie call or booking id is kept) |
| Organization Type `fld2HixMQZtPuRetq` | organizations.org_type |
| Pipeline Stage `fldB8Ewi5LXW9586s` | opportunities.stage when an opportunity is opened |
| Duplicate Of `fld3KOSPEm4twLTre` | contacts.duplicate_of |
| First Seen / Last Seen / Touch Count | activities (one per touch) |
| UTM Source / UTM Campaign | batch label / campaign attribution |
| Test Record `fldNGmISUJN8g7AtY` | is_test |

## 5. Lead Data Quality model

**Observation** (`crm_observations`, append-only): one row per provider × batch × external id × field.
- Keeps the original value exactly as acquired, plus the acquired timestamp and the provider's own claim (for example "verified").
- Links to the canonical contact or organization.
- A field the provider was expected to supply but didn't is stored as a row with `original_value = NULL, expected_missing = 1`, so missingness is measurable.
- Conflicting values from different providers are all kept.

**Verification event** (`crm_verification_events`, append-only) records:
- observation id
- verdict (accurate, inaccurate, unverified, inconclusive, stale), or `undo` pointing at an earlier event
- reason code and free-text reason
- method (call, email, sms, web_lookup, linkedin, registry, provider_check, other)
- `check_kind`: provider_check counts as a **provider claim**; every other method counts as an **independent** check
- actor and role, timestamp (microseconds), corrected value, evidence link, minutes spent
- a unique **idempotency key**

**Rules enforced on the server:**
1. No answer, no reply, voicemail and busy can only be recorded as `inconclusive`.
2. A correction appends a new `manual_correction` observation. The original observation is never updated.
3. Undo is a new event. Nothing is ever deleted.
4. Undoing a correction withdraws its observation.
5. Verifiers can undo only their own events. Admins can undo anyone's.
6. Suppression and consent are never read for write and never changed.

**Metric definitions** (code: `lib/metrics.php`; tests A20–A24 re-derive them independently):
- **Current status** of an observation = verdict of its latest event that hasn't been undone. No event = unchecked.
- **Latest conclusive observation** for a contact field = the active observation whose current status is accurate. A manual correction counts if its creating event hasn't been undone.
- **Accuracy** = accurate ÷ (accurate + inaccurate), over observations whose *current* status is conclusive. Each observation counts once however many times it was checked, so repeat checks can't double-count. A Wilson 95% interval is shown with sample size n.
- **Completeness** = rows with a value ÷ all rows (including expected-missing). **Missingness** = 1 − completeness. **Coverage** = checked ÷ rows with a value.
- **Usable unique lead (verified)** = a contact that meets all of these:
  - not a duplicate, not suppressed, not opted out
  - has an email or phone observation whose current status is accurate from an independent check
- **Usable (provider claim only)** is reported separately.
- **Cost per usable lead** = (list cost + enrichment cost + rework minutes × `rework_hourly_rate_usd`) ÷ verified usable leads.
  - Unknown if any component is unknown, or if there are zero usable leads.
  - Minutes count even when a verdict is later undone: the time was really spent.
- **Duplicate rate** = contacts with `duplicate_of` ÷ contacts in the batch.
- **Conversion and revenue by source** are first-touch: the contact's acquisition batch, then opportunities, then Won and paid payments.
- **Cohorts** = acquisition week of the contact's batch. **Stage aging** = days since the last stage change.
- **Distinct contacts, organizations and events** are counted separately. Unknown is always shown as "Unknown", never as 0.

## 6. Open questions for Omni / COO
1. The Airtable plan tier and current base record count. This decides whether summaries can live in Airtable at all.
2. Accept the MySQL-on-VPS raw layer (section 2), or name another zero-cost store.
3. CRM-001 table and field IDs for section 3.
4. The `rework_hourly_rate_usd` value for human verification time. It's unset in production until decided, so rework cost shows Unknown.
5. Who gets which role: viewer, verifier or admin.
