Antigravity workspace rule for full-stack TypeScript changes in Next.js 16 with async params, validated Server Actions, Prisma 7 and an explicit verification list.
.agents/rules/antigravity-full-stack-typescript.md. Downloaded files need to be placed in that repository path.---
trigger: glob
globs: "**/*"
---
# Full-Stack TypeScript with the Next.js App Router
Applies to: Next.js App Router projects in TypeScript that use Prisma ORM, Tailwind CSS and Vitest, where one change usually touches a page, a mutation and the database.
Version baseline: checked against Next.js 16.3, React 19.2, Prisma ORM 7, Tailwind CSS 4, Zod 4 and TypeScript 5.9. Read `package.json` before editing. If the project pins older majors (for example Next.js 14, where `params` is a plain object), follow the installed version and say which docs you used.
## Before editing
- Read `package.json`, `tsconfig.json`, `next.config.ts`, `prisma.config.ts`, `prisma/schema.prisma` and the closest existing route that does something similar. Reuse its data-access helpers, auth helper and error shape instead of inventing new ones.
- List the files you plan to touch (route segment, Server Action, data-access function, schema, test) before writing code.
- Ask before adding a dependency, changing the Prisma schema or creating a migration.
- Keep `strict: true`. Do not silence type errors with `any`, `as unknown as` or `@ts-ignore`.
## Server Components by default
- Pages and layouts are Server Components. Put `'use client'` on the smallest component that needs state, effects, event handlers or browser APIs.
- `params` and `searchParams` are Promises since Next.js 15. Await them.
- Pass only serializable data to Client Components. Never pass a Prisma client, a class instance or an ordinary function (Server Actions are the exception).
```tsx
// app/products/[id]/page.tsx
import { notFound } from 'next/navigation';
import { getProduct } from '@/lib/data/products';
import { AddToCart } from './add-to-cart';
export default async function ProductPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const product = await getProduct(id);
if (!product) notFound();
return (
<main className="mx-auto max-w-3xl p-6">
<h1 className="text-2xl font-semibold">{product.name}</h1>
<AddToCart productId={product.id} />
</main>
);
}
```
## Server Actions
Every Server Action can be called with a direct POST request, so hiding the form is not access control. In each action: authenticate, authorize, validate, then write.
```ts
// app/products/actions.ts
'use server';
import { z } from 'zod';
import { revalidatePath } from 'next/cache';
import { prisma } from '@/lib/prisma';
import { requireAdmin } from '@/lib/auth';
const ProductInput = z.object({
name: z.string().trim().min(1).max(120),
priceCents: z.coerce.number().int().nonnegative(),
});
export type ActionState = { ok: boolean; errors?: Record<string, string[] | undefined> };
export async function createProduct(_prev: ActionState, formData: FormData): Promise<ActionState> {
await requireAdmin();
const parsed = ProductInput.safeParse({
name: formData.get('name'),
priceCents: formData.get('priceCents'),
});
if (!parsed.success) {
return { ok: false, errors: z.flattenError(parsed.error).fieldErrors };
}
await prisma.product.create({ data: parsed.data });
revalidatePath('/products');
return { ok: true };
}
```
- Do not cast `formData.get()` results with `as string` or parse money with `parseFloat`. Validate with a schema and store money as integer minor units or a decimal type.
- Show validation errors in the client form with `useActionState`, and disable the submit button while the action is pending.
## Caching and revalidation
- `fetch` is not cached by default. Check `next.config.ts` for `cacheComponents`.
- With Cache Components on, cache reads with `'use cache'` plus `cacheLife`/`cacheTag`, and call `updateTag(tag)` from the Server Action when the user must see their own write immediately.
- Without it, use `revalidatePath` or `revalidateTag(tag, 'max')`. The single-argument `revalidateTag(tag)` is deprecated.
- In the summary, name which cached data a mutation invalidates.
## Prisma ORM 7
- Use the single client instance exported from the project's `lib/prisma.ts`, imported from the generator's `output` path. The connection URL lives in `prisma.config.ts`, not in the `datasource` block.
- Use `select` to return only the fields the page renders.
- Wrap multi-step writes that must succeed together in `prisma.$transaction`.
- Schema changes need a migration the developer runs (`npx prisma migrate dev --name <change>`). Never run migrations against a shared or production database.
## UI, loading and errors
- Style with Tailwind utility classes. Theme tokens live in CSS (`@theme`), so do not add a `tailwind.config.js` unless the project already has one.
- Add `loading.tsx` or a `<Suspense>` boundary around slow data. Add an `error.tsx` (a Client Component) where a segment can fail, and call `notFound()` for missing records.
## Tests
- Unit-test schemas, pure helpers and synchronous components with Vitest. Next.js documents that Vitest does not support async Server Components, so cover those with an end-to-end test (for example Playwright).
- When behavior changes, update or add the test in the same change.
## Verify before finishing
Run these when they are available in the project, and report the results:
- `npx tsc --noEmit`
- `npx vitest run`
- `npx eslint .` (Next.js 16 removed `next lint`)
- `npx prisma validate` after schema edits
- `npx next build` to catch server/client boundary and prerendering errors
Cursor rules for Next.js 14+ App Router projects updated for Next.js 16 with async params, validated Route Handlers, generateMetadata and proxy.ts in place of middleware.
CLAUDE.md rules for the Next.js 16 App Router with async params, streaming via Suspense, secured Server Actions, metadata conventions and explicit caching choices.
Copilot instructions for Next.js App Router code with awaited params, authenticated Server Actions, typed Route Handlers and explicit caching.
Antigravity
fullstack
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
An Antigravity agent adds a product page and an admin-only create form to a Next.js 16 App Router app that uses Prisma 7, Tailwind 4, Zod 4 and Vitest.
Add /products/[id] showing name and price, and a createProduct Server Action for admins with fields name (1-120 chars) and priceCents (non-negative integer). After creating, the /products list must show the new item. Files: lib/prisma.ts exports prisma; lib/auth.ts exports requireAdmin(); next.config.ts has no cacheComponents.
Illustrative; not a recorded model run. A file plan, then: app/products/[id]/page.tsx typed with params: Promise<{ id: string }> and awaiting it, calling notFound() for a missing product; a 'use server' action that calls requireAdmin() before validating with a Zod schema (z.coerce.number().int() for priceCents, no parseFloat or `as string`), returns field errors via z.flattenError, writes with prisma.product.create and calls revalidatePath('/products'); a small 'use client' form using useActionState; a Vitest test for the schema; and a closing list of the tsc, vitest, eslint and build commands with their results.Google describes Antigravity as its agentic development platform. Antigravity reads workspace rules from AGENTS.md or GEMINI.md and from Markdown files in .agents/rules/, with a trigger front matter field that sets when a rule is active. Global rules live under ~/.gemini/.
.agents/rules/antigravity-full-stack-typescript.mdStarting point, not a tested configuration for your repository. Active when files matching globs are involved (trigger: glob). Review the instructions, adapt the file paths and run your project's existing checks.
---
trigger: glob
globs: "**/*"
---
# Full-Stack TypeScript with the Next.js App Router
Applies to: Next.js App Router projects in TypeScript that use Prisma ORM, Tailwind CSS and Vitest, where one change usually touches a page, a mutation and the database.
Version baseline: checked against Next.js 16.3, React 19.2, Prisma ORM 7, Tailwind CSS 4, Zod 4 and TypeScript 5.9. Read `package.json` before editing. If the project pins older majors (for example Next.js 14, where `params` is a plain object), follow the installed version and say which docs you used.
## Before editing
- Read `package.json`, `tsconfig.json`, `next.config.ts`, `prisma.config.ts`, `prisma/schema.prisma` and the closest existing route that does something similar. Reuse its data-access helpers, auth helper and error shape instead of inventing new ones.
- List the files you plan to touch (route segment, Server Action, data-access function, schema, test) before writing code.
- Ask before adding a dependency, changing the Prisma schema or creating a migration.
- Keep `strict: true`. Do not silence type errors with `any`, `as unknown as` or `@ts-ignore`.
## Server Components by default
- Pages and layouts are Server Components. Put `'use client'` on the smallest component that needs state, effects, event handlers or browser APIs.
- `params` and `searchParams` are Promises since Next.js 15. Await them.
- Pass only serializable data to Client Components. Never pass a Prisma client, a class instance or an ordinary function (Server Actions are the exception).
```tsx
// app/products/[id]/page.tsx
import { notFound } from 'next/navigation';
import { getProduct } from '@/lib/data/products';
import { AddToCart } from './add-to-cart';
export default async function ProductPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const product = await getProduct(id);
if (!product) notFound();
return (
<main className="mx-auto max-w-3xl p-6">
<h1 className="text-2xl font-semibold">{product.name}</h1>
<AddToCart productId={product.id} />
</main>
);
}
```
## Server Actions
Every Server Action can be called with a direct POST request, so hiding the form is not access control. In each action: authenticate, authorize, validate, then write.
```ts
// app/products/actions.ts
'use server';
import { z } from 'zod';
import { revalidatePath } from 'next/cache';
import { prisma } from '@/lib/prisma';
import { requireAdmin } from '@/lib/auth';
const ProductInput = z.object({
name: z.string().trim().min(1).max(120),
priceCents: z.coerce.number().int().nonnegative(),
});
export type ActionState = { ok: boolean; errors?: Record<string, string[] | undefined> };
export async function createProduct(_prev: ActionState, formData: FormData): Promise<ActionState> {
await requireAdmin();
const parsed = ProductInput.safeParse({
name: formData.get('name'),
priceCents: formData.get('priceCents'),
});
if (!parsed.success) {
return { ok: false, errors: z.flattenError(parsed.error).fieldErrors };
}
await prisma.product.create({ data: parsed.data });
revalidatePath('/products');
return { ok: true };
}
```
- Do not cast `formData.get()` results with `as string` or parse money with `parseFloat`. Validate with a schema and store money as integer minor units or a decimal type.
- Show validation errors in the client form with `useActionState`, and disable the submit button while the action is pending.
## Caching and revalidation
- `fetch` is not cached by default. Check `next.config.ts` for `cacheComponents`.
- With Cache Components on, cache reads with `'use cache'` plus `cacheLife`/`cacheTag`, and call `updateTag(tag)` from the Server Action when the user must see their own write immediately.
- Without it, use `revalidatePath` or `revalidateTag(tag, 'max')`. The single-argument `revalidateTag(tag)` is deprecated.
- In the summary, name which cached data a mutation invalidates.
## Prisma ORM 7
- Use the single client instance exported from the project's `lib/prisma.ts`, imported from the generator's `output` path. The connection URL lives in `prisma.config.ts`, not in the `datasource` block.
- Use `select` to return only the fields the page renders.
- Wrap multi-step writes that must succeed together in `prisma.$transaction`.
- Schema changes need a migration the developer runs (`npx prisma migrate dev --name <change>`). Never run migrations against a shared or production database.
## UI, loading and errors
- Style with Tailwind utility classes. Theme tokens live in CSS (`@theme`), so do not add a `tailwind.config.js` unless the project already has one.
- Add `loading.tsx` or a `<Suspense>` boundary around slow data. Add an `error.tsx` (a Client Component) where a segment can fail, and call `notFound()` for missing records.
## Tests
- Unit-test schemas, pure helpers and synchronous components with Vitest. Next.js documents that Vitest does not support async Server Components, so cover those with an end-to-end test (for example Playwright).
- When behavior changes, update or add the test in the same change.
## Verify before finishing
Run these when they are available in the project, and report the results:
- `npx tsc --noEmit`
- `npx vitest run`
- `npx eslint .` (Next.js 16 removed `next lint`)
- `npx prisma validate` after schema edits
- `npx next build` to catch server/client boundary and prerendering errors
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Antigravity truncates any single rule file over 24,000 bytes, and global plus always_on rules share a 20,000-token budget, according to the docs. AGENTS.md (or GEMINI.md) in a workspace directory is one of the documented rule locations, and ~/.gemini/AGENTS.md works globally. Use .agents/rules/ when a rule should only apply in some situations.
Documentation checked 2026-11-05: Google Antigravity docs: RulesGoogle Antigravity home page
Cursor rules for Next.js 14+ App Router projects updated for Next.js 16 with async params, validated Route Handlers, generateMetadata and proxy.ts in place of middleware.
CLAUDE.md rules for the Next.js 16 App Router with async params, streaming via Suspense, secured Server Actions, metadata conventions and explicit caching choices.
Copilot instructions for Next.js App Router code with awaited params, authenticated Server Actions, typed Route Handlers and explicit caching.