10 KiB
Database Schema and Root API Spec_ Founder CRM Canonical Domains
Date: 2026-04-18
Status: Draft
Owner: Sagnik
Reviewers: Sayan, Sourik
Scope: Canonical target tables, route families, repository expectations, and migration posture for founder-owned CRM and client graph work
Purpose: Define the database schema, root repository behavior, and API surface required for the future CRM-centered Project Velocity architecture.
Decision Boundary: This spec defines the target persistence and route truth for approval. It does not itself execute schema or API changes.
1. Purpose
This spec exists because the current repo contains multiple overlapping data surfaces that are real but not yet canonical. Future implementation needs one agreed target.
2. Design Principles
- canonical domains are namespaced by responsibility
- raw evidence and normalized projections both exist
- current tables are migration feeders, not ignored
- root API families should reflect ownership, not accidental code layout
- read models such as client 360 are derived, not primary truth
3. Schema Files
Future implementation should likely introduce:
- canonical CRM schema or migration unit
- canonical interaction/evidence schema or migration unit
- canonical inventory schema or migration unit
- workflow/governance schema or migration unit
- read-model or materialized-view support where needed
4. Required Tables
CRM core domain
crm_peoplecrm_accountscrm_householdscrm_relationshipscrm_leadscrm_opportunitiescrm_property_interestscrm_stage_history
Interaction and evidence graph domain
intel_interactionsintel_messagesintel_callsintel_call_recordingsintel_transcriptsintel_emailsintel_whatsapp_threadsintel_visitsintel_remindersintel_qd_scoresintel_qd_timeseriesintel_vehicle_eventsintel_perception_eventsintel_cctv_linksintel_blob_store_index
Inventory domain
inventory_projectsinventory_unitsinventory_pricing_historyinventory_availabilityinventory_mediainventory_location_indexinventory_import_jobs
Oracle component/template domain
oracle_component_familiesoracle_component_chaptersoracle_component_templatesoracle_component_examplesoracle_component_tagsoracle_component_lineage
Identity and access domain
core_userscore_rolescore_permissionscore_role_assignmentscore_sessionscore_audit_events
AI workflow and governance domain
workflow_actionsworkflow_branchesworkflow_approvalsworkflow_writebacksworkflow_agent_runsworkflow_policy_decisions
5. Detailed Table Plan
crm_people
- purpose: canonical person-level contact identity
- recommended columns:
person_idfull_nameprimary_emailprimary_phonelinkedin_urlpersona_labelssource_confidencecreated_atupdated_at
- indexes:
- phone
- normalized name
crm_accounts
- purpose: company, developer, brokerage, or client organization record
- recommended columns:
account_idaccount_nameparent_account_idaccount_typeindustrylocation_refmetadata_json
crm_leads
- purpose: funnel-stage commercial qualification layer
- note: distinct from
crm_people; one person may have one or more lead/opportunity contexts - recommended columns:
lead_idperson_idaccount_idsource_systemstatusstagebudget_bandurgencyassigned_user_idcreated_at
crm_opportunities
- purpose: deal pipeline objects
- recommended columns:
opportunity_idlead_idproject_idunit_idstagevalueprobabilityexpected_close_datenext_action
intel_interactions
- purpose: umbrella interaction event record
- recommended columns:
interaction_idperson_idchannelinteraction_typehappened_atsummarysource_ref
intel_messages
- purpose: text-level message records
- recommended columns:
message_idinteraction_idsender_rolemessage_textdelivered_atmetadata_json
intel_calls
- purpose: call-level records
- recommended columns:
call_idinteraction_idcall_directionduration_secondsrecording_reftranscript_ref
intel_transcripts
- purpose: transcript and speaker segmentation storage
- recommended columns:
transcript_idcall_idlanguagefull_textspeaker_segments_jsonconfidence
intel_visits
- purpose: site visits and meeting records
- recommended columns:
visit_idperson_idproject_idunit_idvisited_atvisit_noteshost_user_id
intel_qd_scores
- purpose: latest meaningful QD summary by client or interaction context
- recommended columns:
qd_idperson_idscore_typecurrent_valuecomputed_atevidence_refs_json
intel_qd_timeseries
- purpose: time-series view of QD propagation and shifts
- recommended columns:
timeseries_idperson_idsignal_sourcetimestampvalueevidence_ref
inventory_projects
- purpose: project-level inventory master
- recommended columns:
project_idproject_namedeveloper_namecitymicro_marketlocation_json
inventory_units
- purpose: unit-level availability and attributes
- recommended columns:
unit_idproject_idunit_labelconfigurationarea_sqftprice_currentstatusfacingfloor
core_users
- purpose: canonical user identity
- note: future target wrapper over current
users_and_roles
workflow_writebacks
- purpose: track AI-suggested and approved mutations
- recommended columns:
writeback_idproposal_reftarget_domaintarget_entity_refstatusapproved_byexecuted_at
6. Root Modules
Future root/backend layers should include:
- CRM repository module
- import gateway module
- client graph aggregation gateway
- workflow/policy bridge
- route modules grouped by route family
7. Root API Surface
/api/crm/contacts
- method family:
GET,POST,PUT - purpose: browse and update person/contact records
- access control: authenticated CRM roles
/api/crm/accounts
- method family:
GET,POST,PUT - purpose: browse and update account/company records
/api/crm/opportunities
- method family:
GET,POST,PUT - purpose: pipeline/deal records
/api/crm/tasks
- method family:
GET,POST,PUT - purpose: reminders, follow-ups, and assigned work
/api/crm/interactions
- method family:
GET,POST - purpose: unified interaction timeline access
/api/crm/imports
- method family:
POST,GET - purpose: import batch submission, review, and status
/api/crm/client-360/{client_id}
- method family:
GET - purpose: aggregated client dossier read model
/api/crm/qd/{client_id}
- method family:
GET - purpose: QD summary and timeline access
/api/oracle/templates
- method family:
GET,POST,PUT - purpose: template family and example management
/api/oracle/canvas/*
- method family: mixed
- purpose: Oracle canvas runtime and CRM-adjacent intelligence views
8. Lifecycle States
Suggested lifecycle families:
- import:
uploaded -> parsed -> mapped -> proposed -> approved -> committed -> failed - writeback:
draft -> review_required -> approved -> executed -> rejected - opportunity: stage-based commercial pipeline states
9. Writeback Release Flow
- Oracle or import intelligence proposes a change
- proposal is stored under workflow domain
- operator approves or rejects
- approved change writes into canonical domain
- audit event is stored
10. Repository Contract
Minimum future repository methods:
- fetch contact list
- fetch account list
- fetch client 360
- list unresolved import proposals
- apply approved writeback
- list interaction timeline by client
- fetch QD history by client
- fetch property interests by client
11. Query Shapes
- summary query
- client list with last activity, active opportunity count, and QD summary
- artifact query
- full interaction or transcript artifact by ID
- replay query
- import batch with mapping and approval history
- operator inbox query
- unresolved proposals, reminders, and high-risk merges
12. Concurrency and Idempotency Rules
- import retries must not duplicate canonical rows blindly
- repeated writeback execution must be idempotent
- merges require conflict-safe guards
13. Security and Access Control
- authenticated access required
- role-based access over CRM and admin functions
- sensitive communication artifacts subject to least-privilege access
- high-risk writes require approval
14. Migration and Rollout Plan
Legacy-to-canonical mapping posture:
leadsandleads_intelligencefeed CRM corechat_logsandomnichannel_logsfeed interaction graphconsent_logfeeds governance/compliancevelocity_vault_assets,cctv_events,perception_sessions, andvideo_scene_mapsfeed evidence graphusers_and_rolesbecomes the input to futurecore_*identity design
Rollout should occur in this order:
- canonical schema approval
- import layer and CRM route family
- client 360 read model
- Oracle/CRM writeback flow
15. Acceptance Criteria
- target domains and route families are complete
- old tables are explicitly mapped, not ignored
- route family ownership is explicit
- schema design is detailed enough for implementation planning
16. Ticket Breakdown
- canonical schema design
- import batch ingestion
- mapping review flow
- CRM contact/account/opportunity routes
- client 360 aggregation
- writeback governance
- Oracle template DB
17. Bottom Line
The repo does not need more unnamed tables or more accidental route growth. It needs one canonical model that the rest of Project Velocity can finally build against.