Skip to main content

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.

Module: Forms & Workflow Engine
Prefix: fw_
Table Count: 54
Last Updated: 2026-01-10

Overview

The FW module provides a comprehensive form builder and workflow automation engine, including form design, submissions, approval workflows, automation rules, and analytics.

Table Categories

1. Form Builder (6 tables)

TableColumnsDescription
fw_forms26Form definitions
fw_form_fields24Field definitions
fw_form_versions14Form version history
fw_form_templates18Shareable form templates
fw_form_template_ratings10Template ratings
fw_form_permissions10Form access control
Form Status:
  • draftpublishedarchived
Field Types:
type FieldType = 
  | 'text' | 'textarea' | 'number' | 'email' | 'phone'
  | 'date' | 'datetime' | 'time'
  | 'select' | 'multiselect' | 'radio' | 'checkbox'
  | 'file' | 'image' | 'signature'
  | 'address' | 'lookup' | 'calculated'
  | 'section' | 'repeater' | 'table';
Form Schema Example:
interface FormField {
  id: string;
  name: string;
  label: string;
  type: FieldType;
  required: boolean;
  validation?: ValidationRule[];
  options?: SelectOption[];      // For select/radio/checkbox
  lookup_config?: LookupConfig;  // For lookup fields
  calculated_formula?: string;   // For calculated fields
  conditional_logic?: ConditionalRule[];
}

2. Form Submissions (5 tables)

TableColumnsDescription
fw_form_submissions22Submission records
fw_submission_attachments12File attachments
fw_submission_notes10Internal notes
fw_form_submission_signatures14E-signature records
fw_portal_submissions16Public portal submissions
Submission Data Storage:
interface Submission {
  id: string;
  form_id: string;
  form_version_id: string;
  data: Record<string, any>;  // JSONB field data
  status: 'draft' | 'submitted' | 'processing' | 'completed';
  submitted_at?: string;
  submitted_by?: string;
}

3. Workflow Engine (8 tables)

TableColumnsDescription
fw_workflow_definitions24Workflow definitions
fw_workflow_versions16Version history
fw_workflow_templates18Shareable templates
fw_workflow_template_versions14Template versions
fw_workflow_template_ratings10Template ratings
fw_workflow_template_usage8Usage tracking
fw_workflow_version_comparisons12Version diffs
fw_subflows16Reusable subflows
Workflow Definition Schema:
interface WorkflowDefinition {
  id: string;
  name: string;
  trigger_type: 'form_submission' | 'schedule' | 'event' | 'manual';
  trigger_config: TriggerConfig;
  steps: WorkflowStep[];
  variables: WorkflowVariable[];
}

interface WorkflowStep {
  id: string;
  type: 'action' | 'condition' | 'approval' | 'delay' | 'subflow';
  config: StepConfig;
  next_steps: string[];  // Step IDs
  on_error?: string;     // Error handler step
}

4. Workflow Execution (4 tables)

TableColumnsDescription
fw_workflow_executions22Active workflow instances
fw_execution_logs14Step execution logs
fw_domain_events16Event bus records
fw_workflow_events12Workflow-specific events
Execution Status:
  • pendingrunningcompleted
  • failed, cancelled, paused

5. Approvals (7 tables)

TableColumnsDescription
fw_approval_chains16Approval chain definitions
fw_approval_steps14Steps within chains
fw_approval_requests20Active approval requests
fw_approval_assignments12Approver assignments
fw_approval_delegations14Delegation rules
fw_approval_history14Approval decision log
fw_workflow_approvals12Workflow-specific approvals
Approval Step Types:
  • single - One approver required
  • all - All approvers must approve
  • any - Any approver can approve
  • percentage - X% must approve
Approval Decision Flow:
fw_approval_requests (pending)

fw_approval_assignments (assigned to approvers)

fw_approval_history (decision recorded)

fw_approval_requests (approved/rejected)

6. Automation Rules (4 tables)

TableColumnsDescription
fw_automation_rules20Automation definitions
fw_automation_actions16Action configurations
fw_automation_logs14Execution logs
fw_action_templates14Reusable action templates
Action Types:
type ActionType = 
  | 'send_email' | 'send_notification'
  | 'create_record' | 'update_record' | 'delete_record'
  | 'call_api' | 'call_webhook'
  | 'assign_task' | 'start_workflow'
  | 'calculate' | 'transform';

7. Alerts & Notifications (5 tables)

TableColumnsDescription
fw_workflow_alert_rules16Alert rule definitions
fw_workflow_alerts14Active alerts
fw_workflow_notification_rules14Notification configs
fw_workflow_notification_preferences12User preferences
fw_template_update_notifications10Template change alerts

8. Analytics (2 tables)

TableColumnsDescription
fw_workflow_path_analytics14Path analysis data
fw_workflow_performance_metrics16Performance KPIs
Tracked Metrics:
  • Execution time per step
  • Bottleneck identification
  • Approval turnaround time
  • Error rates by step type

9. Testing & Debugging (6 tables)

TableColumnsDescription
fw_test_cases16Test case definitions
fw_test_datasets12Test data sets
fw_test_scenarios14Test scenarios
fw_test_coverage12Coverage reports
fw_debug_sessions14Debug session logs
fw_sandbox_executions16Sandbox test runs

10. Integration (2 tables)

TableColumnsDescription
fw_api_connections18External API configs
fw_query_whitelist12Allowed query patterns

11. Public Portal (3 tables)

TableColumnsDescription
fw_form_portal_config16Portal settings
fw_portal_rate_limits10Rate limiting
fw_page_templates14Portal page layouts

12. Security (1 table)

TableColumnsDescription
fw_signature_audit_log12Signature audit trail

13. Module Settings (1 table)

TableColumnsDescription
fw_module_settings27FW configuration
Key Settings:
SettingTypeDefault
max_form_fieldsinteger100
max_workflow_stepsinteger50
default_approval_timeout_hoursinteger72
enable_public_portalsbooleanfalse
max_file_size_mbinteger25

Common Query Patterns

Get Form with Fields

const { data } = await supabase
  .from('fw_forms')
  .select(`
    *,
    fields:fw_form_fields(*)
  `)
  .eq('id', formId)
  .single();

Get Pending Approvals

const { data } = await supabase
  .from('fw_approval_requests')
  .select(`
    *,
    assignments:fw_approval_assignments(
      *,
      approver:pf_profiles(first_name, last_name)
    )
  `)
  .eq('status', 'pending')
  .contains('assignments.approver_id', [userId]);

Get Workflow Execution Status

const { data } = await supabase
  .from('fw_workflow_executions')
  .select(`
    *,
    logs:fw_execution_logs(*)
  `)
  .eq('id', executionId)
  .single();

Get Form Submissions

const { data } = await supabase
  .from('fw_form_submissions')
  .select(`
    *,
    form:fw_forms(name),
    submitter:pf_profiles(first_name, last_name)
  `)
  .eq('form_id', formId)
  .order('submitted_at', { ascending: false });

RLS Policies

FW uses multi-level RLS:
  1. Organization isolation via organization_id
  2. Form-level permissions via fw_form_permissions
  3. Submission access based on form settings
  4. Approval access for assigned approvers
Helper Functions:
  • fw_user_can_view_form() - Form view permission
  • fw_user_can_submit_form() - Submission permission
  • fw_user_can_approve() - Approval assignment check

Platform Integration

Forms are accessed via Platform Integration Layer:
// ✅ CORRECT - Use platform layer
import { FormEmbed, useFormSubmission } from '@/platform/forms';

// ❌ WRONG - Direct core import
import { FormEmbed } from '@/cores/fw/components';

See Also