← Back to Hub

REST API CLAUDE.md

CLAUDE.md optimized for building REST APIs with Node.js. Covers routing patterns, validation, error handling, and database conventions.

CLAUDE.mddevelopmentapinode.jsrestexpresshono

by Build Ship Grow

rest-api-claude.md.md
markdown
# CLAUDE.md — REST API Project

## Stack
- Runtime: Node.js 22 with TypeScript
- Framework: Hono (or Express — adjust as needed)
- Database: PostgreSQL with Drizzle ORM
- Validation: Zod schemas
- Auth: JWT Bearer tokens

## Commands
```bash
pnpm dev           # Start with watch mode
pnpm build         # Compile TypeScript
pnpm test          # Run Vitest
pnpm db:migrate    # Run migrations
```

## API Conventions
- RESTful routes: `GET /users`, `POST /users`, `GET /users/:id`
- Always return JSON with consistent shape:
  `{ "data": ..., "error": null }` or `{ "data": null, "error": "message" }`
- Use HTTP status codes correctly (201 for created, 404 for not found, etc.)
- Validate all request bodies with Zod before processing
- Use middleware for auth, logging, and error handling

## File Structure
```
src/
  routes/        # Route handlers grouped by resource
  middleware/    # Auth, validation, error handler
  db/            # Schema, queries, migrations
  lib/           # Shared utilities
  types/         # TypeScript types and Zod schemas
```

## Rules
- Never return raw database errors to clients
- Always paginate list endpoints (limit/offset)
- Log errors with context but sanitize sensitive data
- Write integration tests for every endpoint