nextjs-api-routes
Skill0 starsChanged 15 days agoMITView on GitHub
Backend inside a Next.js App Router project — thin route.js handlers over the same modules/services/validations/models structure as an Express API, cached Mongoose or Prisma connection for serverless, Zod parsing, a single errorResponse helper, GET/POST only. Use when building API endpoints in a Next.js app (app/api/**/route.js) or moving Express-style modules into Next.js.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- bkjain655/agent-skillstheir own version, first seen Aug 2, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- bkjain655/agent-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- ai-integrationSkill
- api-docsSkill
- auth-sessionsSkill
- backend-conventionsSkill
- backend-reviewSkill
- create-backendSkill
- deploy-dockerSkill
- mongoose-mongodbSkill
- new-moduleSkill
- prisma-postgresSkill
- redis-cacheSkill
- scheduled-jobsSkill
- security-hardeningSkill
- session-logSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Keep the same module discipline as an Express backend.
- Very specific: line 114
Only GET and POST exports.
- Very specific: line 117
Read env only in one config module.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Next.js API Routes
Keep the same module discipline as an Express backend; only the HTTP layer changes. Next.js versions change fast — if the project has AGENTS.md or node_modules/next/dist/docs/, read it before using any non-trivial API.
Layout
src/
app/api/<resource>/route.js GET, POST
app/api/<resource>/remove/route.js POST (soft delete)
config/databases.js cached connection
lib/http.js errorResponse
modules/<name>/
models/<name>.model.js Mongoose
services/<name>.service.js
validations/<name>.schema.jsRoute handlers replace controllers and routes. Services, validations and models follow the backend-conventions, mongoose-mongodb or prisma-postgres skills unchanged.
Connection (serverless-safe)
import mongoose from 'mongoose';
import config from '@/config/index.js';
const cache = globalThis.mongooseCache || (globalThis.mongooseCache = { conn: null, promise: null });
const getMongoose = async () => {
if (cache.conn) {
return cache.conn;
}
const { uri } = config.mongo;
if (!uri) {
const error = new Error('The database connection is not configured');
error.statusCode = 500;
throw error;
}
if (!cache.promise) {
cache.promise = mongoose.connect(uri, { maxPoolSize: 10 }).catch((error) => {
cache.promise = null;
throw error;
});
}
cache.conn = await cache.promise;
return cache.conn;
};
export { getMongoose };src/config/index.js is the only module that reads environment variables; it exposes config.mongo.uri. Each service starts with await getMongoose();. For Prisma, keep a single client on globalThis in development the same way.
Handler
import { errorResponse } from '@/lib/http.js';
import { createLogService, getLogsService } from '@/modules/log/services/log.service.js';
import { createLogSchema, getLogsSchema } from '@/modules/log/validations/log.schema.js';
const GET = async (request) => {
try {
const params = new URL(request.url).searchParams;
const query = getLogsSchema.parse({
days: params.get('days') ?? undefined,
date: params.get('date') ?? undefined,
});
return Response.json(await getLogsService(query));
} catch (error) {
return errorResponse(error);
}
};
const POST = async (request) => {
try {
const data = createLogSchema.parse(await request.json());
const item = await createLogService(data);
return Response.json({ item }, { status: 201 });
} catch (error) {
return errorResponse(error);
}
};
export { GET, POST };Errors
import { ZodError } from 'zod';
const errorResponse = (error) => {
if (error instanceof ZodError) {
return Response.json({ message: 'Invalid input' }, { status: 400 });
}
if (error?.name === 'CastError') {
return Response.json({ message: 'Invalid id' }, { status: 400 });
}
const status = error.statusCode || 500;
const message = status >= 500 ? 'Something went wrong' : error.message;
return Response.json({ message }, { status });
};
export { errorResponse };Rules
- Only
GETandPOSTexports. Delete isPOST /api/<resource>/removewith{ id }→ soft delete. - Handlers parse with Zod, call one service, return JSON. No database code in
route.js. - Auth: verify the session/token at the top of each handler (or in
middleware.jsfor coarse gating) and pass the user/scope into the service; never trust ids from the body for scoping. - Read env only in one config module;
NEXT_PUBLIC_*never holds secrets. - Mark handlers that must not be cached as dynamic per the installed Next.js version's docs.
- Single-user/personal apps may skip the scope field, but still keep
isActive, timestamps and indexes on every filter field.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

