Skip to main content
Version: 2.0.0
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:
Usage in RH Core:
Usage in Other Cores:
Anti-Pattern (What NOT to Do):
Key Benefits:
  • ✅ 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 provides useTableLookup hook that safely queries whitelisted tables with automatic organization scoping. Implementation:
Usage in Form Fields:
Anti-Pattern (What NOT to Do):
Key Benefits:
  • ✅ 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 provides EmployeeSelector component and useEmployeeLookup hook. Implementation:
Usage in RH Core (Staff Assignment):
Anti-Pattern (What NOT to Do):
Key Benefits:
  • ✅ 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 via pg_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:
Consumer (Automation Engine Edge Function):

Example: RH-01 → FA-01 Integration (Planned)

Problem: When resident is admitted, billing account must be created automatically. Solution: RH publishes resident_admitted event, FA subscribes and creates account. Publisher (RH Core):
Subscriber (FA Core Edge Function):
Anti-Pattern (What NOT to Do):
Key Benefits:
  • ✅ 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 schemas

Example: 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):
Consumer (RH Core):
API Contract Documentation:
Anti-Pattern (What NOT to Do):
Key Benefits:
  • ✅ 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

Why Wrong: Violates Constitution Section 1.2 (cores cannot depend on each other) Correct Approach: Use Platform Integration Layer, Events, or API Contracts

❌ Shared Database Tables

Why Wrong: Table owned by multiple cores violates boundaries Correct Approach: Each core owns its tables, integrate via events/APIs

❌ Hidden Dependencies

Why Wrong: Hidden dependency makes testing and evolution difficult Correct Approach: Explicit integration contract (API, event, or Platform Layer)

Testing Integration Patterns

Pattern 1 Testing

Pattern 2 Testing

Pattern 3 Testing


Last Updated: 2025-01-12
Next Review: Quarterly (Q2 2025)