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

# FW Module Tables Reference

> This document provides a reference for all database tables in the Forms & Workflow (FW) module.

This document provides a reference for all database tables in the Forms & Workflow (FW) module.

## Table Naming Convention

All FW tables use the `fw_` prefix following the platform convention.

## Core Tables

### Forms

| Table               | Description                                          |
| ------------------- | ---------------------------------------------------- |
| `fw_forms`          | Form definitions with metadata, status, and settings |
| `fw_form_fields`    | Field definitions for each form                      |
| `fw_form_versions`  | Version history for forms                            |
| `fw_form_templates` | Reusable form templates                              |

### Submissions

| Table                       | Description                   |
| --------------------------- | ----------------------------- |
| `fw_form_submissions`       | Submitted form data           |
| `fw_submission_attachments` | Files attached to submissions |
| `fw_submission_notes`       | Notes/comments on submissions |

### Workflow Definitions

| Table                     | Description                            |
| ------------------------- | -------------------------------------- |
| `fw_workflow_definitions` | Workflow structure and steps           |
| `fw_workflow_nodes`       | Individual nodes in a workflow         |
| `fw_workflow_edges`       | Connections between workflow nodes     |
| `fw_workflow_variables`   | Variables used in workflow expressions |

### Automation

| Table                         | Description                                              |
| ----------------------------- | -------------------------------------------------------- |
| `fw_automation_rules`         | Automation rule definitions with triggers and conditions |
| `fw_workflow_executions`      | Runtime execution records                                |
| `fw_workflow_execution_steps` | Individual step execution records                        |
| `fw_workflow_approvals`       | Approval requests and decisions                          |

### Analytics & Testing

| Table                     | Description                    |
| ------------------------- | ------------------------------ |
| `fw_automation_analytics` | Aggregated analytics view      |
| `fw_test_cases`           | Test case definitions          |
| `fw_test_datasets`        | Test data for workflow testing |
| `fw_test_scenarios`       | End-to-end test scenarios      |

## Common Query Patterns

### Get Active Forms Count

```typescript theme={null}
const { count } = await supabase
  .from("fw_forms")
  .select("*", { count: "exact", head: true })
  .eq("organization_id", organizationId)
  .eq("status", "published");
```

### Get Recent Submissions

```typescript theme={null}
const { data } = await supabase
  .from("fw_form_submissions")
  .select(`
    id,
    submitted_at,
    status,
    form:fw_forms(name),
    submitted_by_profile:pf_profiles!fw_form_submissions_submitted_by_fkey(display_name)
  `)
  .eq("organization_id", organizationId)
  .order("submitted_at", { ascending: false })
  .limit(5);
```

### Get Active Automations

```typescript theme={null}
const { count } = await supabase
  .from("fw_automation_rules")
  .select("*", { count: "exact", head: true })
  .eq("organization_id", organizationId)
  .eq("is_active", true);
```

### Get Pending Approvals

```typescript theme={null}
const { count } = await supabase
  .from("fw_workflow_approvals")
  .select("*", { count: "exact", head: true })
  .eq("organization_id", organizationId)
  .is("decision", null);
```

### Get Workflow Executions (Last 24 Hours)

```typescript theme={null}
const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString();
const { count } = await supabase
  .from("fw_workflow_executions")
  .select("*", { count: "exact", head: true })
  .eq("organization_id", organizationId)
  .gte("started_at", oneDayAgo);
```

## Important Notes

1. **Table Naming**: Use `fw_automation_rules` for automation rules, NOT `fw_workflows`
2. **Workflow Definitions**: Use `fw_workflow_definitions` for workflow structures
3. **Executions**: Use `fw_workflow_executions` for runtime execution data
4. **Multi-tenancy**: All queries must include `organization_id` filter

## Related Documentation

* [Mobile Navigation Guide](/development/mobile-navigation-guide) - See Quick Actions Pattern section
* FW Module Specs
