Created: 2025-12-18Documentation Index
Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
Use this file to discover all available pages before exploring further.
Status: Architecture Decision Record
Related Specs: RH-06 (Compliance & Staff Operations)
Overview
This document explains the architectural decision regarding the integration between the Recovery Housing (RH) core and Human Resources (HR) core, specifically around staff employee references.Architecture Decision: No Foreign Key Constraints for staff_employee_id
Context
RH-06 introduces several tables that reference staff employees:rh_staff_assignments.staff_employee_idrh_staff_trainings.staff_employee_idrh_shift_notes.staff_employee_id
Decision
Thesestaff_employee_id columns intentionally do not have foreign key constraints to HR tables (hr_employees).
Rationale
Per the Encore Health OS Platform constitution (§1.2, §1.3):- Core Isolation Principle: Cores depend ONLY on Platform Foundation (PF), never on each other directly. Foreign key constraints would create a direct database-level dependency between RH and HR.
- Deployment Independence: Each core should be deployable and testable independently. FK constraints would require HR schema to exist for RH migrations to succeed.
-
Cross-Core Integration Patterns: The constitution mandates that cross-core communication use one of:
- Platform Integration Layer (hooks, components in
@/platform/) - Event-based integration (pg_notify/webhooks)
- API contracts (edge functions)
- Platform Integration Layer (hooks, components in
Implementation Details
Data Integrity Approach
Instead of FK constraints, RH-06 uses:-
Application-Level Validation: UI components use
@/platform/workforcehooks to look up and validate employee IDs before saving. -
UUID Type Enforcement: The
staff_employee_idcolumns are typed asUUID, ensuring only valid UUIDs can be stored. - RLS Policies: Access control is enforced via organization-scoped RLS policies, not FK relationships.
Employee Lookup Pattern
Implications
-
Orphaned References: If an employee is deleted from HR, RH records referencing that employee will have orphaned
staff_employee_idvalues. This is acceptable because:- Historical records should be preserved
- Soft-delete is the standard pattern (HR uses
deleted_at) - UI can gracefully handle “Unknown Employee” display
- Data Migration: When migrating data, ensure employee IDs exist in HR before creating RH staff records.
-
Testing: RLS tests can create test users directly in
auth.userswithout needing HR employee records.
Alternative Considered
Option: Add FK constraint topf_profiles
Rejected because:
- Not all staff may have platform profiles (contractors, external auditors)
- Would still create cross-table dependency issues in tests
pf_profilesis for platform users, not necessarily all staff
Related Documentation
Last Updated: 2025-12-18