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

# Form & Workflow Dependency Graph - Integration

> Feature ID: FW-55 Status: 📋 Specification Spec Reference: FW-55-form-workflow-dependency-graph.md Last Updated: 2026-03-22 (audit action names aligned with sp…

**Feature ID:** FW-55\
**Status:** 📋 Specification\
**Spec Reference:** [FW-55-form-workflow-dependency-graph.md](../../../specs/fw/archive/FW-55-form-workflow-dependency-graph.md)\
**Last Updated:** 2026-03-22 (audit action names aligned with spec FR-5)

***

## Overview

FW-55 introduces **`fw_dependency_graph`**, a tenant-scoped edge store between FW configuration entities (forms, workflows, automation rules, decision tables, events, lookup configs). Scanners run on entity save (application hooks) to keep edges current; optional scheduled full rebuild reduces drift.

**Cross-core:** None in MVP—edges are FW-internal only. Platform dependencies: **PF-30** (permissions), **PF-04** / `pf_audit_logs` (audit for maintain actions).

***

## Integration Points (from Spec)

| Dependency                                            | Type        | Purpose                                                          |
| ----------------------------------------------------- | ----------- | ---------------------------------------------------------------- |
| FW-01 / FW-06 / FW-03 / FW-16 / FW-15 / FW-41 / FW-54 | FW internal | JSON/config sources for scanners                                 |
| PF-30                                                 | Platform    | `fw.dependencies.view`, `fw.dependencies.maintain`               |
| PF-04 / audit                                         | Platform    | `fw_dependency_force_delete`, `fw_dependency_graph_full_rebuild` |
| `@xyflow/react`                                       | UI library  | Graph visualization                                              |

***

## API / Contracts

* **Client:** Supabase client reads/writes `fw_dependency_graph` under RLS; server-side rebuild and optional `replaceEdgesForSource` batching use SECURITY DEFINER RPC(s) or documented service path (see spec **API Design**).
* **Routes:** `/fw/settings/dependency-graph`, `/fw/settings/unused-entities` (lazy in `src/routes/fw.tsx`; labels in `route-labels.ts`); Settings hub links from `FWSettings.tsx` when `fw.dependencies.view`.
* **Hooks:** `useDependencyImpact(targetType, targetId)` for entity under delete review (dependents = rows where **target** matches); `useDependencyGraph(filters)`, `useOrphanReport(filters)` (exact names in implementation).
* **Mutations:** `refreshDependenciesForSource(orgId, sourceType, sourceId)` (or RPC equivalent) invoked post-save from form/workflow/automation save flows—**must** run in same UX success path as entity persist (or compensating retry). Transitive impact count uses BFS with **500** unique `(source_type, source_id)` vertex cap (spec FR-3).

***

## Platform Integration Layer Usage

| Layer       | Location                 | Usage                                                                    |
| ----------- | ------------------------ | ------------------------------------------------------------------------ |
| Permissions | `@/platform/permissions` | `useHasPermission('fw.dependencies.view' \| 'fw.dependencies.maintain')` |
| Audit       | Platform audit helper    | Log maintain/force actions; no PHI in payload                            |

***

## Security and Tenant Isolation

* RLS: `fw_has_org_access(organization_id, auth.uid())` on all operations; UPDATE policies include **WITH CHECK**.
* Defense in depth: mutations that rewrite edges include `.eq('organization_id', orgId)`.
* Scanners read only FW tables already governed by org RLS; **do not** copy free-text field values into `metadata`.

***

## Event Contracts

* No new cross-core domain events in MVP.
* Optional: internal audit events only (see spec FR-5).

***

## Related Docs

* [FW-55 Spec](../../../specs/fw/archive/FW-55-form-workflow-dependency-graph.md)
* [FW-55 Plan](../../../specs/fw/archive/FW-55-form-workflow-dependency-graph-PLAN.md)
* [FW-06](../../../specs/fw/archive/FW-06-advanced-workflow-builder.md)
* [FW-03](../../../specs/fw/archive/FW-03-automation-engine.md)
* [FW-54](../../../specs/fw/archive/FW-54-conditional-approval-routing.md)
