Last Updated: 2025-01-12
Constitution Reference: Section 1.3 (Integration Patterns) This document provides concrete examples of each integration pattern used in the Encore OS Platform, demonstrating correct usage and common anti-patterns to avoid.
Pattern 1: Platform Integration Layer
When to Use: Cross-cutting capabilities needed by multiple cores (forms, notifications, file uploads) Structure: Shared utilities in/src/platform/<capability>/
Example: PF-08 Forms Integration Layer
Problem: Multiple cores need forms functionality, but cores cannot depend on each other. Solution: Platform Foundation provides integration layer that wraps FW core functionality. Implementation:- ✅ Cores remain isolated (no direct FW imports)
- ✅ Stable API contract (platform layer doesn’t change often)
- ✅ Single source of truth (all cores use same integration)
- ✅ Easy to test (mock platform layer, not FW core)
Example: PF-15 Data Lookup Integration Layer
Problem: Form fields need dynamic dropdowns populated from database tables, but cores cannot directly query each other’s tables. Solution: Platform Foundation providesuseTableLookup hook that safely queries whitelisted tables with automatic organization scoping.
Implementation:
- ✅ Table whitelist enforcement (security)
- ✅ Automatic organization scoping (multi-tenant safety)
- ✅ RLS policy compliance
- ✅ Reusable across all cores
Example: PF-14 Platform Workforce Integration Layer
Problem: Multiple cores need to select employees (RH for staff assignments, FW for form assignees, etc.), but cores cannot depend on HR core. Solution: Platform Foundation providesEmployeeSelector component and useEmployeeLookup hook.
Implementation:
- ✅ Consistent employee selection UI across all cores
- ✅ Automatic filtering by site, department, position
- ✅ Search functionality built-in
- ✅ No direct HR core dependency
Pattern 2: Event-Based Integration
When to Use: Asynchronous workflows, loose coupling between cores Structure: Domain events published viapg_notify, consumed via triggers or edge functions
Example: FW-03 Automation Engine
Problem: Automation engine needs to react to form submissions without tight coupling. Solution: Form submissions publish events, automation engine subscribes. Implementation:Example: RH-01 → FA-01 Integration (Planned)
Problem: When resident is admitted, billing account must be created automatically. Solution: RH publishesresident_admitted event, FA subscribes and creates account.
Publisher (RH Core):
- ✅ Loose coupling (cores don’t know about each other)
- ✅ Resilient (if FA is down, resident admission still succeeds)
- ✅ Scalable (events can be processed asynchronously)
- ✅ Testable (mock events, not direct calls)
Pattern 3: API Contracts
When to Use: Synchronous request-response interactions Structure: Versioned API endpoints (edge functions) with clear request/response schemasExample: FA-01 Billing Balance Query (Planned)
Problem: RH needs to query resident billing balance synchronously. Solution: FA provides versioned API endpoint, RH calls it. Provider (FA Core Edge Function):- ✅ Versioned APIs (can evolve without breaking consumers)
- ✅ Clear contracts (request/response schemas documented)
- ✅ RLS enforced (organization isolation at API level)
- ✅ Testable (mock API endpoints)
Pattern Selection Guide
When to Use Pattern 1 (Platform Integration Layer)
- ✅ Multiple cores need the same capability
- ✅ Capability is cross-cutting (forms, notifications, documents)
- ✅ Stable API surface (doesn’t change often)
- ✅ Examples: Forms, Notifications, Document Management
When to Use Pattern 2 (Event-Based)
- ✅ Asynchronous workflows
- ✅ Loose coupling desired
- ✅ Resilience important (consumer can be down)
- ✅ Examples: Resident admission → Billing, Payment → Status update
When to Use Pattern 3 (API Contracts)
- ✅ Synchronous request-response needed
- ✅ Real-time data required
- ✅ Versioning important for evolution
- ✅ Examples: Balance queries, Census lookups
Common Anti-Patterns Summary
❌ Direct Core Imports
❌ Shared Database Tables
❌ Hidden Dependencies
Testing Integration Patterns
Pattern 1 Testing
Pattern 2 Testing
Pattern 3 Testing
Last Updated: 2025-01-12
Next Review: Quarterly (Q2 2025)