> ## Documentation Index
> Fetch the complete documentation index at: https://docs-terra.withunify.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Server Actions

> Reference for Terra's server actions

# Server Actions

> Terra uses Next.js Server Actions for all data mutations.

## Action Files

| File               | Purpose                 |
| ------------------ | ----------------------- |
| `airtable.ts`      | Airtable OAuth and sync |
| `notifications.ts` | Email/SMS sending       |
| `insights.ts`      | Analytics queries       |
| `applicants.ts`    | Applicant management    |
| `status.ts`        | Submission status       |
| `domains.ts`       | Custom domain config    |
| `workspaces.ts`    | Folder management       |
| `agencies.ts`      | Agency management       |
| `form-versions.ts` | Draft/publish           |
| `webhooks.ts`      | Webhook config          |
| `team.ts`          | Permissions             |
| `settings.ts`      | Org settings            |

## Common Patterns

### Permission Check

```typescript theme={null}
"use server";

export async function updateSubmission(id: string, data: Data) {
  const user = await requireAdmin();  // Throws if unauthorized

  await supabaseAdmin
    .from("form_submissions")
    .update(data)
    .eq("id", id);

  await logAudit(user.id, "submission.updated", { id });

  return { success: true };
}
```

### ActionResult Pattern

```typescript theme={null}
type ActionResult<T> =
  | { success: true; data: T }
  | { success: false; error: string };

export async function createForm(data: FormData): Promise<ActionResult<Form>> {
  try {
    const user = await requireAdmin();
    const form = await insertForm(data);
    return { success: true, data: form };
  } catch (error) {
    return { success: false, error: error.message };
  }
}
```

### Revalidation

```typescript theme={null}
import { revalidatePath } from "next/cache";

export async function publishForm(id: string) {
  await updateFormStatus(id, "published");
  revalidatePath(`/forms/${id}`);
  revalidatePath("/forms");
}
```

***

<CardGroup cols={2}>
  <Card title="Database Schema" icon="database" href="/core-systems/data/database-schema">
    Table reference
  </Card>

  <Card title="Authorization" icon="shield" href="/core-systems/identity/authorization">
    Permission checks
  </Card>
</CardGroup>
