api-design
Grounded corpus (Tier-1 consultation): pagination, versioning,
error shape (RFC 9457), idempotency, async ops, rate limiting, bulk,
naming, expansion, webhooks — query ./scripts-run <skills-root>/corpus-grounding/scripts/ground search --manifest <skills-root>/api-design/data/manifest.json "<concern>" and propose
the grounded pattern (+ hardening + anti-patterns + RFC link) before
designing from memory. Corpus: data/api-patterns.csv.
When to use
Use this skill when designing new API endpoints, restructuring existing APIs, or deciding about versioning and deprecation.
Do NOT use when:
- Implementing an already-designed endpoint (use
api-endpoint skill)
- Writing tests for APIs (use
api-testing skill)
Procedure: Design an API
- Gather context — read
agents/settings/contexts/api-versioning.md, agents/reference/docs/api-resources.md, agents/reference/docs/query-filter.md, agents/reference/docs/controller.md, and guideline php/api-design.md.
- Identify the resource — determine the domain entity, its attributes, and relationships. Check existing models and resources for field naming patterns.
- Define endpoints — list each endpoint with HTTP method, URL path, request body, query parameters, and response structure. Follow existing route file patterns.
- Decide versioning — determine whether this extends the current version or requires a new version (see decision table below).
- Design error responses — define 4xx/5xx responses matching the project's existing error format.
- Validate against existing patterns — compare your design with 2-3 similar existing endpoints. Flag any inconsistencies.
- Run adversarial review — use
adversarial-review skill to check for breaking changes, consistency issues, and missing error cases.
Versioning decisions
URL-based versioning
Routes versioned via URL prefix: /api/v1/..., /api/v2/...
routes/api/v1/projects.php → /api/v1/projects (Laravel)
app/api/v1/projects/route.ts → /api/v1/projects (Next.js)
routes/api/v2/projects.php → /api/v2/projects
Automatic fallback
If a route doesn't exist in the requested version, the system falls back to the next older version. Configured in the framework's app config (config/app.php in Laravel):
'api_versioning' => [
'versions' => 'v2,v1', // newest first
],
When to create a new version
| Change type |
Action |
| Add optional field |
Extend current version |
| Add new endpoint |
Add to current version |
| Remove/rename field |
New version |
| Change field type |
New version |
| Change validation rules |
New version |
If an existing client would break without code changes → new version required.
Deprecation workflow
- Mark as deprecated — add headers:
Deprecation: true, Sunset: YYYY-MM-DD, Link: <successor>
- Document — add to API changelog with sunset date
- Monitor usage — track clients still using deprecated endpoints
- Remove — after sunset date, remove route + controller + docs
Minimum 3 months between deprecation and removal.
Design review
Before presenting an API design, run the adversarial-review skill.
Focus on: Breaking changes? Consistency? Error responses?
Output format
- Endpoint specification — method, path, request/response structure
- Versioning decision with rationale
- Error response format following existing project patterns
Gotcha
- Consistency beats "better" design — check existing patterns first.
- Always include pagination on list endpoints.
- Max nesting depth: 2 levels (
/users/{id}/orders/{id}).
- Don't version internal APIs only your own frontend consumes.
- Deprecation without migration path is useless — always provide the replacement.
- Don't duplicate controllers for new versions — use fallback logic.
Do NOT
- Do NOT introduce a new response format in an established API — match existing patterns.
- Do NOT create v2 endpoints without a deprecation plan for v1.
- Do NOT skip pagination on list endpoints.
Auto-trigger keywords
- API design
- REST API
- endpoint design
- resource structure
- response format
- API versioning
- deprecation
- breaking changes
1---2name: api-design3description: Use when designing APIs, planning endpoints, REST conventions, versioning, or deprecation — even when the user just says 'expose this as an endpoint' without naming API design.4---56# api-design789> **Grounded corpus (Tier-1 consultation):** pagination, versioning,10> error shape (RFC 9457), idempotency, async ops, rate limiting, bulk,11> naming, expansion, webhooks — query `./scripts-run12> <skills-root>/corpus-grounding/scripts/ground search --manifest13> <skills-root>/api-design/data/manifest.json "<concern>"` and propose14> the grounded pattern (+ hardening + anti-patterns + RFC link) before15> designing from memory. Corpus: [`data/api-patterns.csv`](data/api-patterns.csv).1617## When to use1819Use this skill when designing new API endpoints, restructuring existing APIs, or deciding about versioning and deprecation.2021Do NOT use when:22- Implementing an already-designed endpoint (use `api-endpoint` skill)23- Writing tests for APIs (use `api-testing` skill)2425## Procedure: Design an API26271. **Gather context** — read `agents/settings/contexts/api-versioning.md`, `agents/reference/docs/api-resources.md`, `agents/reference/docs/query-filter.md`, `agents/reference/docs/controller.md`, and guideline `php/api-design.md`.282. **Identify the resource** — determine the domain entity, its attributes, and relationships. Check existing models and resources for field naming patterns.293. **Define endpoints** — list each endpoint with HTTP method, URL path, request body, query parameters, and response structure. Follow existing route file patterns.304. **Decide versioning** — determine whether this extends the current version or requires a new version (see decision table below).315. **Design error responses** — define 4xx/5xx responses matching the project's existing error format.326. **Validate against existing patterns** — compare your design with 2-3 similar existing endpoints. Flag any inconsistencies.337. **Run adversarial review** — use `adversarial-review` skill to check for breaking changes, consistency issues, and missing error cases.3435## Versioning decisions3637### URL-based versioning3839Routes versioned via URL prefix: `/api/v1/...`, `/api/v2/...`4041```42routes/api/v1/projects.php → /api/v1/projects (Laravel)43app/api/v1/projects/route.ts → /api/v1/projects (Next.js)44routes/api/v2/projects.php → /api/v2/projects45```4647### Automatic fallback4849If a route doesn't exist in the requested version, the system falls back to the next older version. Configured in the framework's app config (`config/app.php` in Laravel):5051```php52'api_versioning' => [53 'versions' => 'v2,v1', // newest first54],55```5657### When to create a new version5859| Change type | Action |60|---|---|61| Add optional field | Extend current version |62| Add new endpoint | Add to current version |63| Remove/rename field | New version |64| Change field type | New version |65| Change validation rules | New version |6667> If an existing client would break without code changes → **new version required**.6869### Deprecation workflow70711. **Mark as deprecated** — add headers: `Deprecation: true`, `Sunset: YYYY-MM-DD`, `Link: <successor>`722. **Document** — add to API changelog with sunset date733. **Monitor usage** — track clients still using deprecated endpoints744. **Remove** — after sunset date, remove route + controller + docs7576Minimum 3 months between deprecation and removal.7778## Design review7980Before presenting an API design, run the **`adversarial-review`** skill.81Focus on: Breaking changes? Consistency? Error responses?8283## Output format84851. Endpoint specification — method, path, request/response structure862. Versioning decision with rationale873. Error response format following existing project patterns8889## Gotcha9091- Consistency beats "better" design — check existing patterns first.92- Always include pagination on list endpoints.93- Max nesting depth: 2 levels (`/users/{id}/orders/{id}`).94- Don't version internal APIs only your own frontend consumes.95- Deprecation without migration path is useless — always provide the replacement.96- Don't duplicate controllers for new versions — use fallback logic.9798## Do NOT99100- Do NOT introduce a new response format in an established API — match existing patterns.101- Do NOT create v2 endpoints without a deprecation plan for v1.102- Do NOT skip pagination on list endpoints.103104## Auto-trigger keywords105106- API design107- REST API108- endpoint design109- resource structure110- response format111- API versioning112- deprecation113- breaking changes