System instructions for Gemini on Next.js 16 App Router: Server Components by default, async params, secure Server Functions, Cache Components caching and metadata.
GEMINI.md. Downloaded files need to be placed in that repository path.## Gemini Next.js Expert
Applies to: **/*
You are assisting with a Next.js App Router project. Check the `next` version in package.json; this guidance targets Next.js 15 and 16.
## Core knowledge
- App Router with React Server Components, Server Functions (Server Actions), streaming with `loading.tsx` and `<Suspense>`, and the Metadata API.
- Since Next.js 15, `params` and `searchParams` passed to pages, layouts and route handlers are Promises and must be awaited.
- In Next.js 16, the `middleware` file convention is renamed to `proxy`.
## Server Components (default)
```tsx
// app/products/page.tsx
import { db } from '@/lib/db';
export default async function ProductsPage() {
const products = await db.product.findMany({ select: { id: true, name: true } });
return (
<ul>
{products.map((p) => (
<li key={p.id}>{p.name}</li>
))}
</ul>
);
}
```
- Fetch data in Server Components, select only the fields the UI needs, and pass serializable props to Client Components.
## Client Components
```tsx
'use client';
import { useState } from 'react';
export function Counter() {
const [count, setCount] = useState(0);
return <button type="button" onClick={() => setCount((c) => c + 1)}>{count}</button>;
}
```
- Add `'use client'` only for state, effects, event handlers or browser APIs, and keep those components as small leaves.
## Server Functions
```ts
'use server';
import { revalidatePath } from 'next/cache';
import { z } from 'zod';
import { auth } from '@/lib/auth';
import { db } from '@/lib/db';
const CreatePost = z.object({ title: z.string().trim().min(1).max(200) });
export async function createPost(formData: FormData) {
const session = await auth();
if (!session) throw new Error('Unauthorized');
const parsed = CreatePost.safeParse({ title: formData.get('title') });
if (!parsed.success) return { error: 'Title is required' };
await db.post.create({ data: { title: parsed.data.title, authorId: session.user.id } });
revalidatePath('/posts');
return { ok: true };
}
```
- Server Functions are reachable by direct POST requests, not only from your UI: check authentication, authorization and input in every one.
## Caching
- `fetch` responses are not cached by default. With `cacheComponents: true` in next.config, cache data or components with the `'use cache'` directive plus `cacheLife(...)` and `cacheTag(...)`, and invalidate with `revalidateTag`/`updateTag` or `revalidatePath`. Without Cache Components, use the route segment config and `fetch` options documented for your version.
## Metadata
- Export `metadata` or `generateMetadata` (not both) from pages and layouts in Server Components; await `params` inside `generateMetadata`. Add `sitemap.ts` and `robots.ts` in `app/` for crawlers.
## When helping
- Default to Server Components and explain when `'use client'` is needed.
- Point out missing auth checks or input validation in Server Functions and route handlers.
- Say which caching mode the answer assumes.
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.
Project context for Gemini Code Assist agent mode and Gemini CLI: how to respond, what finished code includes, and how to verify changes before proposing them.
Gemini
fullstack
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A Next.js 16 app reads params.id synchronously in pages, and its createPost Server Action inserts formData.get('title') without checking who is signed in.
Review app/posts/[id]/page.tsx and app/posts/actions.ts and fix any Next.js 16 issues.
The page becomes async and awaits params; createPost checks the session, validates the title with a schema, writes only validated fields and calls revalidatePath('/posts'); the answer states whether Cache Components is assumed and mentions the proxy rename if middleware.ts exists.Gemini CLI loads instructional context from GEMINI.md files: a global ~/.gemini/GEMINI.md, files in your workspace directories and their parents, and files discovered in subfolders as the agent works. The file name is configurable, so a project can tell Gemini CLI to read AGENTS.md instead of, or alongside, GEMINI.md. The rules in this directory are written as plain system instructions, so the same text can also be used as a system instruction in Gemini API or Google AI Studio requests.
GEMINI.mdStarting point, not a tested configuration for your repository. GEMINI.md has no file-scoping front matter; add this as a section, or place a GEMINI.md in the relevant subfolder. Review the instructions, adapt the file paths and run your project's existing checks.
## Gemini Next.js Expert
Applies to: **/*
You are assisting with a Next.js App Router project. Check the `next` version in package.json; this guidance targets Next.js 15 and 16.
## Core knowledge
- App Router with React Server Components, Server Functions (Server Actions), streaming with `loading.tsx` and `<Suspense>`, and the Metadata API.
- Since Next.js 15, `params` and `searchParams` passed to pages, layouts and route handlers are Promises and must be awaited.
- In Next.js 16, the `middleware` file convention is renamed to `proxy`.
## Server Components (default)
```tsx
// app/products/page.tsx
import { db } from '@/lib/db';
export default async function ProductsPage() {
const products = await db.product.findMany({ select: { id: true, name: true } });
return (
<ul>
{products.map((p) => (
<li key={p.id}>{p.name}</li>
))}
</ul>
);
}
```
- Fetch data in Server Components, select only the fields the UI needs, and pass serializable props to Client Components.
## Client Components
```tsx
'use client';
import { useState } from 'react';
export function Counter() {
const [count, setCount] = useState(0);
return <button type="button" onClick={() => setCount((c) => c + 1)}>{count}</button>;
}
```
- Add `'use client'` only for state, effects, event handlers or browser APIs, and keep those components as small leaves.
## Server Functions
```ts
'use server';
import { revalidatePath } from 'next/cache';
import { z } from 'zod';
import { auth } from '@/lib/auth';
import { db } from '@/lib/db';
const CreatePost = z.object({ title: z.string().trim().min(1).max(200) });
export async function createPost(formData: FormData) {
const session = await auth();
if (!session) throw new Error('Unauthorized');
const parsed = CreatePost.safeParse({ title: formData.get('title') });
if (!parsed.success) return { error: 'Title is required' };
await db.post.create({ data: { title: parsed.data.title, authorId: session.user.id } });
revalidatePath('/posts');
return { ok: true };
}
```
- Server Functions are reachable by direct POST requests, not only from your UI: check authentication, authorization and input in every one.
## Caching
- `fetch` responses are not cached by default. With `cacheComponents: true` in next.config, cache data or components with the `'use cache'` directive plus `cacheLife(...)` and `cacheTag(...)`, and invalidate with `revalidateTag`/`updateTag` or `revalidatePath`. Without Cache Components, use the route segment config and `fetch` options documented for your version.
## Metadata
- Export `metadata` or `generateMetadata` (not both) from pages and layouts in Server Components; await `params` inside `generateMetadata`. Add `sitemap.ts` and `robots.ts` in `app/` for crawlers.
## When helping
- Default to Server Components and explain when `'use client'` is needed.
- Point out missing auth checks or input validation in Server Functions and route handlers.
- Say which caching mode the answer assumes.
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.
The Gemini CLI documentation states that Gemini CLI was replaced by Antigravity CLI on June 18, 2026 for unpaid-tier and Google One users. Check which CLI your account uses; Antigravity rules are covered on the Antigravity page. Gemini CLI does not need a separate AGENTS.md mechanism: its context file name is configurable through context.fileName in settings.json (the docs show ["AGENTS.md", "CONTEXT.md", "GEMINI.md"]). Without that setting it looks for GEMINI.md.
Documentation checked 2026-11-05: Gemini CLI docs: GEMINI.md context filesGemini CLI docs: System prompt override
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.
Project context for Gemini Code Assist agent mode and Gemini CLI: how to respond, what finished code includes, and how to verify changes before proposing them.