> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Contact Relationship Mapping - Integration Document

> Feature ID: CE-20 Status: ✅ Complete Created: 2026-03-31

**Feature ID:** CE-20\
**Status:** ✅ Complete\
**Created:** 2026-03-31

***

## Integration Summary

CE-20 introduces relationship mapping between CE contacts and renders a two-degree relationship graph on contact detail screens. The feature stays within CE and PF boundaries: it persists relationship edges, consumes CE-01 contact records, and writes CE-04 activity entries for relationship lifecycle actions.

## Integration Touchpoints

### CE-01: Contacts

* **Type:** Data (FK + SECURITY DEFINER helper)
* **Direction:** CE-20 -> CE-01
* **Contract:** `ce_contact_relationships.contact_id` and `ce_contact_relationships.related_contact_id` reference `ce_contacts.id`
* **Behavior:** Relationship create/update/delete operations are scoped by `ce_has_org_access(organization_id, auth.uid())`

### CE-04: Activities

* **Type:** Data / Application integration
* **Direction:** CE-20 -> CE-04
* **Contract:** Relationship CRUD operations create corresponding `ce_activities` timeline entries
* **Behavior:** Contact timelines reflect relationship creation, edits, and soft-delete actions

### PF-15: Picklists

* **Type:** Platform layer
* **Direction:** CE-20 -> PF-15
* **Contract:** Relationship type options are resolved from the PF-15 picklist, not hardcoded DB checks
* **Behavior:** Organizations can customize relationship labels without schema changes

## Database Objects

* `ce_contact_relationships` (table): Directed contact-to-contact relationship edges with soft-delete.
* `ce_has_org_access()` (existing SECURITY DEFINER function): Tenant-scoped RLS helper reused by CE-20 policies.

## Permissions

* `ce.contact_relationships.read`: View relationship list and network graph
* `ce.contact_relationships.manage`: Create, edit, and delete relationships

## RLS Strategy

* `ce_contact_relationships` enforces org isolation via `ce_has_org_access(organization_id, auth.uid())`
* Policy set includes SELECT, INSERT, UPDATE (`USING` + `WITH CHECK`), and DELETE
* Application mutations must include defense-in-depth `organization_id` filters

## Contract Notes

* No cross-core event contracts are introduced by CE-20.
* No external API contract is introduced by CE-20.
* CE-20 remains same-core integration and does not require changes to CL/PM/FA/HR/RH modules.
