> ## 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.

# Business Process Registry — Integration

> Feature ID: PF-82 Status: ✅ Implemented Spec: PF-82-business-process-registry.md Last Updated: 2026-03-16

**Feature ID:** PF-82
**Status:** ✅ Implemented
**Spec:** [PF-82-business-process-registry.md](../../../specs/pf/specs/PF-82-business-process-registry.md)
**Last Updated:** 2026-03-16

***

## Overview

PF-82 (Business Process Registry) provides a centralized, auto-discovered catalog of business processes that aggregate automation rules (`fw_automation_rules`) and workflow definitions (`fw_workflow_definitions`) per organization. It calculates composite health scores, surfaces execution metrics, and publishes health-change events consumed by notifications and the system health dashboard.

***

## Integration Points (from Spec)

| Dependency                      | Pattern                       | Purpose                                                                                                                     |
| ------------------------------- | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| FW-03 (Automation Engine)       | Data (SECURITY DEFINER)       | Source of `fw_automation_rules` and `fw_automation_logs` for discovery and health metrics                                   |
| FW-06 (Workflow Builder)        | Data (SECURITY DEFINER)       | Source of `fw_workflow_definitions` and `fw_workflow_instances` for discovery and health metrics                            |
| PF-29 (Task System)             | Platform Layer / Impact Graph | Impact graph traces task creation actions from automation rules                                                             |
| PF-10 (Notifications)           | Platform Layer / Event        | Health status change notifications (degraded/critical/recovery)                                                             |
| PF-36 (System Health Dashboard) | Platform Layer / Event        | Process health summary widget; subscribes to `process_health_changed` event                                                 |
| PF-83 (SLA Management)          | Data (SECURITY DEFINER)       | `pf_sla_instances` queried for SLA compliance component of health score; defaults to 100% when PF-83 is not yet implemented |
| PF-04 (Audit Logging)           | Platform Layer                | Discovery and health refresh operations logged via PF-04                                                                    |

***

## Cross-Core Data Access

PF-82 reads from FW core tables (`fw_automation_rules`, `fw_automation_logs`, `fw_workflow_definitions`, `fw_workflow_instances`) via **PF-owned SECURITY DEFINER functions** (`pf_discover_business_processes`, `pf_refresh_process_health`). These functions run with `SET search_path = public` to prevent search-path injection.

> **Architecture note:** Direct cross-core table reads are normally prohibited by constitution §1. PF-82 mitigates this by routing all FW data access through SECURITY DEFINER database functions owned by the PF core, which is consistent with the pattern used by other platform-level health and observability features (e.g., PF-36, PF-52). No PF React code imports FW modules directly.

***

## Event Contracts

### `process_health_changed`

| Field                   | Type                                                 | Description                                |
| ----------------------- | ---------------------------------------------------- | ------------------------------------------ |
| `processId`             | `string` (UUID)                                      | The process that changed health status     |
| `organizationId`        | `string` (UUID)                                      | Tenant scoping                             |
| `processName`           | `string`                                             | Human-readable process name                |
| `previousStatus`        | `'healthy' \| 'degraded' \| 'critical' \| 'unknown'` | Prior health status                        |
| `newStatus`             | `'healthy' \| 'degraded' \| 'critical' \| 'unknown'` | New health status                          |
| `healthScore`           | `number`                                             | Composite score (0–100)                    |
| `topContributingFactor` | `string`                                             | Component with the largest negative impact |
| `changedAt`             | `string` (ISO 8601)                                  | Timestamp of status change                 |

**Publisher:** `pf_refresh_process_health()` (pg\_cron every 5 min + Database Webhook on `fw_automation_logs` INSERT)
**Subscribers:** PF-10 (Notifications), PF-36 (System Health Dashboard)
**Delivery:** `pg_notify('process_health_refresh', ...)` → Database Webhook → Edge Function → PF-10

***

### `process_discovered`

| Field                 | Type                | Description                           |
| --------------------- | ------------------- | ------------------------------------- |
| `processId`           | `string` (UUID)     | Newly created or updated process      |
| `organizationId`      | `string` (UUID)     | Tenant scoping                        |
| `processName`         | `string`            | Discovered process name               |
| `owningCore`          | `string`            | Inferred owning core                  |
| `processType`         | `string`            | Inferred process type                 |
| `linkedRuleCount`     | `number`            | Number of linked automation rules     |
| `linkedWorkflowCount` | `number`            | Number of linked workflow definitions |
| `discoveredAt`        | `string` (ISO 8601) | Discovery timestamp                   |

**Publisher:** `pf_discover_business_processes()` (pg\_cron daily + on-demand Edge Function)
**Subscribers:** PF-04 (Audit Logging)

***

## Consumers of PF-82

| Consumer                        | Pattern      | Purpose                                                                     |
| ------------------------------- | ------------ | --------------------------------------------------------------------------- |
| PF-36 (System Health Dashboard) | Event / Data | Process health summary widget — top degraded/critical processes             |
| PF-83 (SLA Management)          | Data         | SLA instances are correlated to processes via `correlation_id = process_id` |

***

## Edge Functions

| Function                       | Trigger                                         | Purpose                                                       |
| ------------------------------ | ----------------------------------------------- | ------------------------------------------------------------- |
| `pf-discover-processes`        | On-demand (UI or API)                           | Manual process discovery for a single organization            |
| `pf-refresh-health` (proposed) | Database Webhook on `fw_automation_logs` INSERT | Triggers `pf_refresh_process_health()` for the linked process |

***

## Tenant Isolation

All `pf_business_processes` and `pf_process_execution_snapshots` rows are scoped to `organization_id`. RLS policies enforce tenant isolation using existing platform helpers `pf_has_org_access()` and `pf_is_platform_admin()` (both SECURITY DEFINER).

***

## Permission Keys (PF-30)

| Key                              | Roles                                    |
| -------------------------------- | ---------------------------------------- |
| `pf.business_processes.view`     | `platform_admin`, `org_admin`, `manager` |
| `pf.business_processes.manage`   | `platform_admin`, `org_admin`            |
| `pf.business_processes.discover` | `platform_admin`, `org_admin`            |
| `pf.business_processes.settings` | `platform_admin`, `org_admin`            |

***

## Related Docs

* [Spec: PF-82-business-process-registry.md](../../../specs/pf/specs/PF-82-business-process-registry.md)
* [CROSS\_CORE\_INTEGRATIONS.md](./CROSS_CORE_INTEGRATIONS.md)
* [PF-36-system-health-dashboard-INTEGRATION.md](./system-health-dashboard-integration.md)
* [PLATFORM\_INTEGRATION\_LAYERS.md](./PLATFORM_INTEGRATION_LAYERS.md)
