AEAl-Andalus⺢Experience
Sign in · Join
AEAl-Andalus⺢Experience
ProjectsGalleryAboutArticlesDashboardAPI
© 2026 — Modular content systems☕buy me a coffee
Framework Study Guide
ChaptersCardsLegendRoadmapRoute Map
Chapters
00 · Root Layout01 · Server Page (page.tsx)01a · Special Files (not-found, error, loading)02 · Client Component (UI & Interaction)02a · Client Boundaries & Islands03 · Entity Actions (actions/*.ts)04 · Server Actions ("use server")05 · Context Provider (context/*.tsx)06 · API Route (app/(api)/<entity>/route.ts)07 · TypeScript + Prisma08 · Entity-First Feature Design09 · Deployment, Docker & Cloud10 · Next 16 + Prisma 7 Upgrade11 · Prisma 7 (SQLite-first, App Router)12 · TypeORM (Entities + Migrations)13 · Drizzle ORM (SQL-first)11 · CSS, Mobile-First Flex, Tailwind12 · Libraries, Accelerators & Production Shortcuts14 · Next.js 16: cache, PPR, proxy, AI
→ cards/04-server-actions

Chapter

04 · Server Actions ("use server")

Mutation entry points: adapt UI input, call entity actions, trigger revalidation.

Mental Model

  • Server Actions are the mutation boundary callable from the UI.
  • They orchestrate: validate → authorize → call entity action → revalidate.
  • No Prisma here; data authority stays in entity actions.

File Classification

Layer: Mutation boundary
Directive: "use server"
Runtime: Server
Prisma: ❌ Never
Calls: Entity actions for writes
Revalidation: ✅ Explicit

Canonical Example

"use server";

import { createProject } from "./actions/createProject";
import { getSession } from "@/auth";
import { revalidatePath, revalidateTag } from "next/cache";

export async function createProjectAction(formData: FormData) {
const session = await getSession();
if (!session) throw new Error("Unauthorized"); // security

await createProject(formData, session.user.id);
revalidatePath("/projects"); // re-render route
revalidateTag("projects"); // bust cache tag
}

Server vs Entity Actions (Quick)

  • Server Action: callable by UI, no Prisma, orchestrates + revalidates.
  • Entity Action: owns Prisma, validation, authorization; not called by UI directly.
  • Keep mutations thin at server-action layer; keep rules/DB in entity actions.

Next 16 Security — Actions are POST Endpoints

  • Every Server Action is automatically exposed as a POST endpoint — externally callable if the route is known.
  • Implication: always authorize at the top of every action. Do not rely on UI-only guards.
  • Use session checks (getSession()), role gates (requireAdmin()), and input validation (Zod.parse()) on every action.
  • Server Actions are for UI-triggered mutations only. For webhooks/external integrations, use Route Handlers with signature verification.
  • revalidateTag() is finer-grained than revalidatePath() — prefer tagged cache invalidation for data-dependent routes.