System instructions for Gemini on Node.js + Express 5 + TypeScript backends: layered structure, async error handling, Zod 4 validation and safe error responses.
GEMINI.md. Downloaded files need to be placed in that repository path.## Gemini Node.js Backend
Applies to: **/*
You are assisting with a Node.js backend written in TypeScript with Express. Check the Express major version in package.json; this guidance targets Express 5.
## Project structure
```
src/
├── routes/ # routers: map HTTP paths to controllers
├── controllers/ # parse requests, call services, shape responses
├── services/ # business logic, no Express types
├── repositories/ # database access
├── middleware/ # auth, validation, error handling
├── types/
└── app.ts # builds the app; server.ts listens (keeps tests simple)
```
## App setup
```ts
import express, { type ErrorRequestHandler } from 'express';
import helmet from 'helmet';
import cors from 'cors';
import { usersRouter } from './routes/users';
export const app = express();
app.use(helmet());
app.use(cors({ origin: process.env.CORS_ORIGIN?.split(',') ?? false }));
app.use(express.json({ limit: '100kb' }));
app.use('/api/users', usersRouter);
const errorHandler: ErrorRequestHandler = (err, req, res, _next) => {
req.log?.error({ err }, 'unhandled error');
res.status(500).json({ error: 'Internal server error' });
};
app.use(errorHandler); // registered last; must keep four parameters
```
- Configure CORS with explicit origins; do not ship `cors()` with no options for APIs that use cookies or credentials.
- Do not send stack traces or internal error messages to clients.
## Controllers
- In Express 5, a rejected promise from an async handler or middleware is passed to `next(err)` automatically, so try/catch blocks that only call `next(error)` are unnecessary.
```ts
import type { Request, Response } from 'express';
export class UserController {
constructor(private readonly service: UserService) {}
getUser = async (req: Request<{ id: string }>, res: Response) => {
const user = await this.service.findById(req.params.id);
if (!user) {
res.status(404).json({ error: 'Not found' });
return;
}
res.json(user);
};
}
```
- On Express 4, wrap async handlers or call `next(err)` yourself.
## Validation
```ts
import { z } from 'zod';
import type { RequestHandler } from 'express';
export const CreateUser = z.object({
email: z.email(),
password: z.string().min(8),
});
export const validateBody =
(schema: z.ZodType): RequestHandler =>
(req, res, next) => {
const result = schema.safeParse(req.body);
if (!result.success) {
res.status(400).json({ errors: result.error.issues.map((i) => ({ path: i.path, message: i.message })) });
return;
}
req.body = result.data;
next();
};
```
- Zod 4 uses `z.email()` (the `z.string().email()` form is deprecated) and `error.issues` (`error.errors` was removed).
- In Express 5, `req.query` is a read-only getter; parse it into a new variable instead of reassigning it.
## Other expectations
- Hash passwords with a slow algorithm (argon2 or bcrypt) and never log them.
- Add rate limiting to authentication endpoints, structured logging, and graceful shutdown on SIGTERM.
Cursor rule for FastAPI projects using Pydantic v2 schemas, SQLAlchemy 2 async_sessionmaker, lifespan cleanup, explicit commits and 409 conflict handling.
Cursor rule for Express 5 APIs in TypeScript with createApp structure, no try/catch boilerplate, Zod 4 validation into res.locals and a safe central error handler.
Cursor rule for Next.js Route Handlers with Zod 4 safeParse validation, auth and ownership checks, awaited params, bounded pagination and one consistent JSON error shape.
Gemini
backend
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
An Express API was upgraded to Express 5 and Zod 4; its validation middleware still returns result.error.errors (now undefined) and every controller wraps code in try/catch → next(error).
Update src/middleware/validate.ts, src/controllers/user.controller.ts and src/app.ts for Express 5 and Zod 4.
Validation responds with error.issues mapped to path/message, schemas use z.email(), controllers drop redundant try/catch, the error handler is a typed four-argument ErrorRequestHandler registered last that hides internals, and CORS uses explicit origins.
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 Node.js Backend
Applies to: **/*
You are assisting with a Node.js backend written in TypeScript with Express. Check the Express major version in package.json; this guidance targets Express 5.
## Project structure
```
src/
├── routes/ # routers: map HTTP paths to controllers
├── controllers/ # parse requests, call services, shape responses
├── services/ # business logic, no Express types
├── repositories/ # database access
├── middleware/ # auth, validation, error handling
├── types/
└── app.ts # builds the app; server.ts listens (keeps tests simple)
```
## App setup
```ts
import express, { type ErrorRequestHandler } from 'express';
import helmet from 'helmet';
import cors from 'cors';
import { usersRouter } from './routes/users';
export const app = express();
app.use(helmet());
app.use(cors({ origin: process.env.CORS_ORIGIN?.split(',') ?? false }));
app.use(express.json({ limit: '100kb' }));
app.use('/api/users', usersRouter);
const errorHandler: ErrorRequestHandler = (err, req, res, _next) => {
req.log?.error({ err }, 'unhandled error');
res.status(500).json({ error: 'Internal server error' });
};
app.use(errorHandler); // registered last; must keep four parameters
```
- Configure CORS with explicit origins; do not ship `cors()` with no options for APIs that use cookies or credentials.
- Do not send stack traces or internal error messages to clients.
## Controllers
- In Express 5, a rejected promise from an async handler or middleware is passed to `next(err)` automatically, so try/catch blocks that only call `next(error)` are unnecessary.
```ts
import type { Request, Response } from 'express';
export class UserController {
constructor(private readonly service: UserService) {}
getUser = async (req: Request<{ id: string }>, res: Response) => {
const user = await this.service.findById(req.params.id);
if (!user) {
res.status(404).json({ error: 'Not found' });
return;
}
res.json(user);
};
}
```
- On Express 4, wrap async handlers or call `next(err)` yourself.
## Validation
```ts
import { z } from 'zod';
import type { RequestHandler } from 'express';
export const CreateUser = z.object({
email: z.email(),
password: z.string().min(8),
});
export const validateBody =
(schema: z.ZodType): RequestHandler =>
(req, res, next) => {
const result = schema.safeParse(req.body);
if (!result.success) {
res.status(400).json({ errors: result.error.issues.map((i) => ({ path: i.path, message: i.message })) });
return;
}
req.body = result.data;
next();
};
```
- Zod 4 uses `z.email()` (the `z.string().email()` form is deprecated) and `error.issues` (`error.errors` was removed).
- In Express 5, `req.query` is a read-only getter; parse it into a new variable instead of reassigning it.
## Other expectations
- Hash passwords with a slow algorithm (argon2 or bcrypt) and never log them.
- Add rate limiting to authentication endpoints, structured logging, and graceful shutdown on SIGTERM.
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 rule for FastAPI projects using Pydantic v2 schemas, SQLAlchemy 2 async_sessionmaker, lifespan cleanup, explicit commits and 409 conflict handling.
Cursor rule for Express 5 APIs in TypeScript with createApp structure, no try/catch boilerplate, Zod 4 validation into res.locals and a safe central error handler.
Cursor rule for Next.js Route Handlers with Zod 4 safeParse validation, auth and ownership checks, awaited params, bounded pagination and one consistent JSON error shape.