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

# Decision Tables — Integration

> Feature ID: FW-45 Status: ✅ Implemented Spec: FW-45-decision-tables.md Last Updated: 2026-03-16

**Feature ID:** FW-45\
**Status:** ✅ Implemented\
**Spec:** [FW-45-decision-tables.md](../../../specs/fw/archive/FW-45-decision-tables.md)\
**Last Updated:** 2026-03-16

***

## Overview

FW-45 introduces configurable decision tables for workflow and rule evaluation use cases. The feature integrates with Platform Foundation tenancy and permissions, and with existing Forms & Workflow modules for condition evaluation, workflow execution, and version-safe runtime behavior.

***

## Integration Points (from Spec)

| Dependency                         | Pattern                         | Purpose                                                                        |
| ---------------------------------- | ------------------------------- | ------------------------------------------------------------------------------ |
| PF-01 (Organizations)              | Platform dependency             | Enforce tenant isolation through `organization_id` on all records and queries. |
| PF-02 (Auth/Permissions)           | Platform dependency             | Gate access with `fw.decision_tables.view` and `fw.decision_tables.manage`.    |
| FW-17 (Advanced Condition Builder) | Intra-core registry integration | Register `decision_table` condition type for rule-based conditions.            |
| FW-06 (Advanced Workflow Builder)  | Intra-core registry integration | Register `decision` node type that evaluates table versions at runtime.        |
| FW-03 (Automation Engine)          | Intra-core runtime integration  | Execute table evaluation during automation sequences and record outputs.       |
| FW-07 (Workflow Versioning)        | Intra-core snapshot integration | Store decision table version bindings in workflow version snapshots.           |

***

## Scheduled Processing Contract

| Job                          | Schedule    | Input                                                       | Output                   | Notes                                                                   |
| ---------------------------- | ----------- | ----------------------------------------------------------- | ------------------------ | ----------------------------------------------------------------------- |
| `fw-rule-evaluation-cleanup` | `0 3 * * *` | `organization_id`, retention days from `fw_module_settings` | Deleted stale rows count | Cleanup is scoped by organization and uses configured retention limits. |

***

## Event / API Contracts

* **Edge Function:** `evaluate-decision-table` — ✅ Implemented
  * **Request:** `tableId`, `facts`, optional `versionId`, optional `evaluation_context` (`workflow_step` | `form_validation` | `api_request`), optional `source_execution_id`, `source_step_id`.
  * **Response:** `success`, `matched`, `matchedRuleCount`, `outputs`, `evaluationId`, `versionNumber`, `hitPolicy`, `correlationId`, optional `error`.
  * **Auth:** `validateAuth()` + `verifyOrgAccess()` via `_shared/auth.ts`.
  * **Audit:** Writes via `fw_log_decision_table_evaluation` RPC under user auth context. Failures are non-fatal (logged, not returned as errors).
* **Persistence Contract:**
  * Writes audit entries to `fw_rule_evaluations` for server-side evaluations only.
  * Client-side test mode does not write audit rows.

***

## Security and Tenant Isolation

* All mutations and reads are tenant-scoped with `organization_id`.
* RLS is enabled on `fw_decision_tables`, `fw_decision_table_versions`, and `fw_rule_evaluations`.
* Permission checks enforce least-privilege access for view/manage operations.

***

## Related Docs

* [CROSS\_CORE\_INTEGRATIONS.md](./CROSS_CORE_INTEGRATIONS.md)
* [PLATFORM\_INTEGRATION\_LAYERS.md](./PLATFORM_INTEGRATION_LAYERS.md)
* [API\_CONTRACTS.md](./API_CONTRACTS.md)
* [FW-45-decision-tables.md](../../../specs/fw/archive/FW-45-decision-tables.md)
