Pre-Code Checklist
- Resource + HTTP method + action
- Request → response contract (input shape, output shape, errors)
- Auth requirement (public / authenticated / role-gated)
- Failure scenarios + validation rules
Response Envelope
{ "success": true, "data": "<payload>", "message": "OK", "error": null }
{ "success": false, "data": null, "message": "<summary>", "error": { "code": "<CODE>", "details": [{ "field": "", "message": "" }] } }
HTTP Status Codes
| Code |
When |
| 200 |
GET · PUT · PATCH success |
| 201 |
POST created |
| 204 |
DELETE success (no body) |
| 400 |
Malformed request |
| 401 |
Missing / invalid auth |
| 403 |
Authenticated but forbidden |
| 404 |
Resource not found |
| 409 |
Conflict / duplicate |
| 422 |
Validation failure + error.details array |
| 429 |
Rate limited |
| 500 |
Server error — safe message only, no stack trace |
Design Rules
- Versioning — prefix all routes
/api/v1/.
- Endpoints — plural nouns, kebab-case:
/api/v1/posts, /api/v1/post-categories.
- Query params —
page, limit, sort, filter[key]=value.
- Auth —
Authorization: Bearer <token> (JWT/opaque) or HTTP-only cookie (same parent domain).
- Pagination — all list endpoints:
data: { items: T[], pagination: { page, limit, totalItems, totalPages } }.
- CORS — exact origin only (
http://localhost:3000 dev, exact domain prod). Never * with credentials.
- Naming — pick camelCase or snake_case; consistent throughout the project.
- Docs — expose OpenAPI spec at
/api/docs or /openapi.json when feasible.
Architecture
- Route handlers thin — business logic in service/use-case layer.
- Global error handler → catches all unhandled errors → safe 500.
- DB connection pooling. Async/non-blocking I/O.
- Cache read-heavy data (Redis or in-memory).
Security (non-negotiable)
- Secrets via env vars only — never hardcoded.
- Parameterized queries/ORM — no string-concatenated SQL.
- Hash passwords (bcrypt/argon2 or language equivalent).
- Rate-limit auth endpoints (login, register, password reset).
- Limit request body size (e.g., 1 MB).
- Security headers in production (X-Frame-Options, CSP, HSTS).
- Validate all input at boundary before processing.
Never Do
- Expose stack traces, DB errors, or internal details to client.
- Trust unvalidated client input or hardcode secrets.
- Skip pagination on list endpoints.
- Wildcard CORS
* with credentials.
- Business logic directly in route handlers.
Source: hilmifawwazsaad/NextJS-Boilerplate — distributed by TomeVault.
1---2name: hilmifawwazsaad-nextjs-boilerplate-backend3description: Pre-Code Checklist4---56## Pre-Code Checklist781. Resource + HTTP method + action92. Request → response contract (input shape, output shape, errors)103. Auth requirement (public / authenticated / role-gated)114. Failure scenarios + validation rules1213## Response Envelope1415```json16{ "success": true, "data": "<payload>", "message": "OK", "error": null }17{ "success": false, "data": null, "message": "<summary>", "error": { "code": "<CODE>", "details": [{ "field": "", "message": "" }] } }18```1920## HTTP Status Codes2122| Code | When |23| ---- | ------------------------------------------------ |24| 200 | GET · PUT · PATCH success |25| 201 | POST created |26| 204 | DELETE success (no body) |27| 400 | Malformed request |28| 401 | Missing / invalid auth |29| 403 | Authenticated but forbidden |30| 404 | Resource not found |31| 409 | Conflict / duplicate |32| 422 | Validation failure + `error.details` array |33| 429 | Rate limited |34| 500 | Server error — safe message only, no stack trace |3536## Design Rules3738- **Versioning** — prefix all routes `/api/v1/`.39- **Endpoints** — plural nouns, kebab-case: `/api/v1/posts`, `/api/v1/post-categories`.40- **Query params** — `page`, `limit`, `sort`, `filter[key]=value`.41- **Auth** — `Authorization: Bearer <token>` (JWT/opaque) or HTTP-only cookie (same parent domain).42- **Pagination** — all list endpoints: `data: { items: T[], pagination: { page, limit, totalItems, totalPages } }`.43- **CORS** — exact origin only (`http://localhost:3000` dev, exact domain prod). Never `*` with credentials.44- **Naming** — pick camelCase or snake_case; consistent throughout the project.45- **Docs** — expose OpenAPI spec at `/api/docs` or `/openapi.json` when feasible.4647## Architecture4849- Route handlers thin — business logic in service/use-case layer.50- Global error handler → catches all unhandled errors → safe 500.51- DB connection pooling. Async/non-blocking I/O.52- Cache read-heavy data (Redis or in-memory).5354## Security (non-negotiable)5556- Secrets via env vars only — never hardcoded.57- Parameterized queries/ORM — no string-concatenated SQL.58- Hash passwords (bcrypt/argon2 or language equivalent).59- Rate-limit auth endpoints (login, register, password reset).60- Limit request body size (e.g., 1 MB).61- Security headers in production (X-Frame-Options, CSP, HSTS).62- Validate all input at boundary before processing.6364## Never Do6566- Expose stack traces, DB errors, or internal details to client.67- Trust unvalidated client input or hardcode secrets.68- Skip pagination on list endpoints.69- Wildcard CORS `*` with credentials.70- Business logic directly in route handlers.7172---73> Source: [hilmifawwazsaad/NextJS-Boilerplate](https://github.com/hilmifawwazsaad/NextJS-Boilerplate) — distributed by [TomeVault](https://tomevault.io).74<!-- tomevault:4.0:skill_md:2026-05-22 -->