agentleFS
Google CloudKnown publisherGoogleCloudPlatform/devrel-demos/other/modernizing-expressjs/.agents/skills/scaffolding-api-routes/SKILL.md

scaffolding-api-routes

Skill416 starsChanged 31 days agoApache-2.0View on GitHub

Reads API_Contracts.md artifacts and rebuilds the legacy Express routes as modern Next.js Route Handlers or Server Actions. Use when following a legacy audit artifact to scaffold out a new Express API routes.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 0 are distinctive, and 4 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.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Create the folder structure in src/app/api/ representing the resources.

    line 31
  2. Very specific:

    Use the Zod Schemas defined in src/lib/models/schema.ts (from Step 3) to validate req.json().

    line 43
  3. Very specific:

    Ensure the API returns a standard 422 Unprocessable Entity or 400 Bad Request with a detailed error payload if validation fails.

    line 44
  4. Very specific:

    Write the GET, POST, PUT, PATCH, and DELETE functions.

    line 47

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Scaffolding Modern API Routes

Translate legacy Express route definitions and middleware chains into modern Next.js Route Handlers with built-in validation and unified session management.

Objective

Rebuild the documented API surface to ensure 1:1 functional parity with the legacy system, focusing on mapping Express Middlewares to Next.js Route Guards.

Instructions for the Scaffold Subagent

Copy this checklist and track your progress:

Task Progress:
- [ ] Step 1: Analyze API Contracts
- [ ] Step 2: Establish Route Architecture
- [ ] Step 3: Map Middleware to Guards
- [ ] Step 4: Implement Zod-Backed Request Validation
- [ ] Step 5: Implement Resource Handlers

Step 1. Analyze API Contracts

Locate and read docs/legacy-audit/API_Contracts.md. Identify:

  • Primary Routes & Sub-routes: Map these to the Next.js App Router (e.g., /api/[resource]/[sub-resource]/route.ts).
  • Legacy Middleware Requirements: Identify routes protected by Passport, custom "owner-only" checks, or roles.

Step 2. Establish Route Architecture

Create the folder structure in src/app/api/ representing the resources. Ensure that:

  • Dynamic Segments (e.g., [id]) are used for resource-specific operations (GET single, PUT, DELETE).
  • Index Segments (e.g., /api/posts/route.ts) are used for collection operations (GET list, POST new).

Step 3. Map Middleware to Guards

Translate legacy Express middleware chains into Modular Route Guards:

  • Authentication: Map requiresLogin to a getServerSession(authOptions) check.
  • Authorization (Ownership): Map resourceAuth.hasAuthorization to a "Resource Ownership Guard" (e.g., if (resource.user_id !== session.user.id) throw Unauthorized).
  • Authorization (Roles): Map role-specific middleware to logic that checks session.user.role.

Step 4. Implement Zod-Backed Request Validation

For every incoming request (POST, PUT, PATCH):

  • Use the Zod Schemas defined in src/lib/models/schema.ts (from Step 3) to validate req.json().
  • Ensure the API returns a standard 422 Unprocessable Entity or 400 Bad Request with a detailed error payload if validation fails.

Step 5. Implement Resource Handlers

Write the GET, POST, PUT, PATCH, and DELETE functions.

  • Strict Response Envelopes: Match the Common Response Envelope identified in the audit (e.g., whether to return a raw object or a wrapped { data: ... }).
  • Pagination & Sorting: Implement skip, limit, and sort parameters to mirror the legacy behavior precisely.
  • Status Code Parity: Match the exact success and error status codes documented in API_Contracts.md.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.