REST API Generator
Agent workflow that generates a complete REST API with CRUD routes, validation, error handling, and OpenAPI docs from a Prisma schema.
Code is provided "as is". Review and test before production use. Terms
Built by Thomas
@thomas
A CLAUDE.md agent workflow template that instructs Claude Code to generate a complete REST API from a Prisma schema. Copy the CLAUDE.md into your project, run Claude Code, and it will scaffold Zod validation schemas, CRUD route handlers, pagination, OpenAPI spec, and tests. Includes a helper script that lists Prisma models.
- Generate REST API routes from an existing Prisma schema using Claude Code
- Scaffold Zod validation schemas for all Prisma models
- Auto-detect framework (Next.js App Router, Express, or Fastify) and generate appropriate route handlers
- Generate OpenAPI spec and integration tests alongside routes
Step 1: Copy CLAUDE.md to your project root
cp CLAUDE.md /path/to/your/project/CLAUDE.mdValidation: CLAUDE.md should exist at your project root
Step 2: Ensure your project has a Prisma schema
Validation: prisma/schema.prisma should exist with model definitions
Step 3: Optionally run the helper script to see detected models
npx tsx scripts/generate.tsValidation: Should print model names found in your schema
Step 4: Run Claude Code and ask it to generate the API
claude
# Then say: Generate a REST API for my Prisma schemaValidation: Claude Code reads CLAUDE.md and generates route files, schemas, tests
- This is NOT a programmatic library — do not try to import functions from it
- Do not run scripts/generate.ts expecting it to generate code — it only lists models
- Do not use without a Prisma schema file in your project
- Requires Claude Code or another AI coding agent that reads CLAUDE.md files
- Only works with Prisma schemas — does not support other ORMs
- The helper script (scripts/generate.ts) only lists models; it does not generate code
- Quality of generated code depends on the AI agent following the CLAUDE.md instructions
Findings (8)
- -Documentation claims scripts/generate.ts is a 'helper script that lists Prisma models' and describes it as 'diagnostic tool', but the file header misleadingly says 'Standalone generator — parses Prisma schema and scaffolds API routes' which contradicts the actual implementation
- -Integration step 3 validation claims 'Should print model names found in your schema' but the actual output is 'Found {count} models: {list}' without explicitly stating model names are from the Prisma schema
- -scripts/generate.ts has no error handling for malformed Prisma schema — if regex fails to match models, it will silently report 0 models with no explanation
- -Regex in scripts/generate.ts uses /^model (\w+) \{/gm which will fail to match model names with spaces after 'model' keyword or on lines that don't start with 'model' due to indentation
- -CLAUDE.md Step 2 instructs checking for Next.js App Router by looking for 'app/' directory, but this is not a reliable detection method as many projects have an 'app' folder unrelated to Next.js
- +3 more findings
Suggestions (7)
- -Clarify in scripts/generate.ts header that this is a 'diagnostic tool to list Prisma models' not a code generator, to avoid user confusion
- -Add validation to scripts/generate.ts to detect malformed Prisma schema and provide helpful error messages (e.g., if no models found, check for syntax errors)
- -Improve regex in scripts/generate.ts to handle Prisma models with whitespace variations: /^\s*model\s+(\w+)\s*\{/gm
- +4 more suggestions