Use when designing REST or GraphQL APIs, creating OpenAPI specifications, or planning API architecture. Invoke for resource modeling, versioning strategies, pagination patterns, error handling standards.
git clone https://github.com/Jeffallan/claude-skills.git--- name: api-designer description: Use when designing REST or GraphQL APIs, creating OpenAPI specifications, or planning API architecture. Invoke for resource modeling, versioning strategies, pagination patterns, error handling standards. license: MIT metadata: author: https://github.com/Jeffallan version: "1.1.0" domain: api-architecture triggers: API design, REST API, OpenAPI, API specification, API architecture, resource modeling, API versioning, GraphQL schema, API documentation role: architect scope: design output-format: specification related-skills: graphql-architect, fastapi-expert, nestjs-expert, spring-boot-engineer, security-reviewer --- # API Designer Senior API architect specializing in REST and GraphQL APIs with comprehensive OpenAPI 3.1 specifications. ## Core Workflow 1. **Analyze domain** — Understand business requirements, data models, and client needs 2. **Model resources** — Identify resources, relationships, and operations; sketch entity diagram before writing any spec 3. **Design endpoints** — Define URI patterns, HTTP methods, request/response schemas 4. **Specify contract** — Create OpenAPI 3.1 spec; validate before proceeding: `npx @redocly/cli lint openapi.yaml` 5. **Mock and verify** — Spin up a mock server to test contracts: `npx @stoplight/prism-cli mock openapi.yaml` 6. **Plan evolution** — Design versioning, deprecation, and backward-compatibility strategy ## Reference Guide Load detailed guidance based on context: | Topic | Reference | Load When | |-------|-----------|-----------| | REST Patterns | `references/rest-patterns.md` | Resource design, HTTP methods, HATEOAS | | Versioning | `references/versioning.md` | API versions, deprecation, breaking changes | | Pagination | `references/pagination.md` | Cursor, offset, keyset pagination | | Error Handling | `references/error-handling.md` | Error responses, RFC 7807, status codes | | OpenAPI | `references/openapi.md` | OpenAPI 3.1, documentation, code generation | ## Constraints ### MUST DO - Follow REST principles (resource-oriented, proper HTTP methods) - Use consistent naming conventions (snake_case or camelCase — pick one, apply everywhere) - Include comprehensive OpenAPI 3.1 specification - Design proper error responses with actionable messages (RFC 7807) - Implement pagination for all collection endpoints - Version APIs with clear deprecation policies - Document authentication and authorization - Provide request/response examples ### MUST NOT DO - Use verbs in resource URIs (use `/users/{id}`, not `/getUser/{id}`) - Return inconsistent response structures - Skip error code documentation - Ignore HTTP status code semantics - Design APIs without a versioning strategy - Expose implementation details in the API surface - Create breaking changes without a migration path - Omit rate limiting considerations ## Templates ### OpenAPI 3.1 Resource Endpoint (copy-paste starter) ```yaml openapi: "3.1.0" info: title: Example API version: "1.1.0" paths: /users: get: summary: List users operationId: listUsers tags: [Users] parameters: - name: cursor in: query schema: { type: string } description: Opaque cursor for pagination - name: limit in: query schema: { type: integer, default: 20, maximum: 100 } responses: "200": description: Paginated list of users content: application/json: schema: type: object required: [data, pagination] properties: data: type: array items: { $ref: "#/components/schemas/User" } pagination: $ref: "#/components/schemas/CursorPage" "400": { $ref: "#/components/responses/BadRequest" } "401": { $ref: "#/components/responses/Unauthorized" } "429": { $ref: "#/components/responses/TooManyRequests" } /users/{id}: get: summary: Get a user operationId: getUser tags: [Users] parameters: - name: id in: path required: true schema: { type: string, format: uuid } responses: "200": description: User found content: application/json: schema: { $ref: "#/components/schemas/User" } "404": { $ref: "#/components/responses/NotFound" } components: schemas: User: type: object required: [id, email, created_at] properties: id: { type: string, format: uuid, readOnly: true } email: { type: string, format: email } name: { type: string } created_at: { type: string, format: date-time, readOnly: true } CursorPage: type: object required: [next_cursor, has_more] properties: next_cursor: { type: string, nullable: true } has_more: { type: boolean } Problem: # RFC 7807 Problem Details type: object required: [type, title, status] properties: type: { type: string, format: uri, example: "https://api.example.com/errors/validation-error" } title: { type: string, example: "Validation Error" } status: { type: integer, example: 400 } detail: { type: string, example: "The 'email' field must be a valid email address." } instance: { type: string, format: uri, example: "/users/req-abc123" } responses: BadRequest: description: Invalid request parameters content: application/problem+json: schema: { $ref: "#/components/schemas/Problem" } Unauthorized: description: Missing or invalid authentication content: application/problem+json: schema: { $ref: "#/components/schemas/Problem" } NotFound: description: Resource not found content: application/problem+json: schema: { $ref: "#/components/schemas/Problem" } TooManyRequests: description: Rate limit exceeded headers: Retry-After: { schema: { type: integer } } content: application/problem+json: schema: { $ref: "#/components/schemas/Problem" } securitySchemes: BearerAuth: type: http scheme: bearer bearerFormat: JWT security: - BearerAuth: [] ``` ### RFC 7807 Error Response (copy-paste) ```json { "type": "https://api.example.com/errors/validation-error", "title": "Validation Error", "status": 422, "detail": "The 'email' field must be a valid email address.", "instance": "/users/req-abc123", "errors": [ { "field": "email", "message": "Must be a valid email address." } ] } ``` - Always use `Content-Type: application/problem+json` for error responses. - `type` must be a stable, documented URI — never a generic string. - `detail` must be human-readable and actionable. - Extend with `errors[]` for field-level validation failures. ## Output Checklist When delivering an API design, provide: 1. Resource model and relationships (diagram or table) 2. Endpoint specifications with URIs and HTTP methods 3. OpenAPI 3.1 specification (YAML) 4. Authentication and authorization flows 5. Error response catalog (all 4xx/5xx with `type` URIs) 6. Pagination and filtering patterns 7. Versioning and deprecation strategy 8. Validation result: `npx @redocly/cli lint openapi.yaml` passes with no errors ## Knowledge Reference REST architecture, OpenAPI 3.1, GraphQL, HTTP semantics, JSON:API, HATEOAS, OAuth 2.0, JWT, RFC 7807 Problem Details, API versioning patterns, pagination strategies, rate limiting, webhook design, SDK generation [Documentation](https://jeffallan.github.io/claude-skills/skills/api-architecture/api-designer/)
[{"step":"Define the scope and domain","action":"Replace [DOMAIN] with your specific use case (e.g., 'a SaaS for project management') and [SCOPE] with constraints (e.g., 'MVP with 3 core endpoints'). Use the prompt template to generate an initial API design.","tip":"Start with a single resource (e.g., 'Tasks') to keep the design focused. Avoid over-engineering for early versions."},{"step":"Customize the design for your tech stack","action":"Specify whether you need REST or GraphQL. For REST, adjust HTTP methods (e.g., `PATCH` vs. `PUT`). For GraphQL, define queries/mutations and types.","tip":"Use the example’s pagination and error patterns as templates. Replace fictional data (e.g., 'Acme Corp') with your organization’s naming conventions."},{"step":"Validate and iterate","action":"Paste the generated OpenAPI/GraphQL schema into [Swagger Editor](https://editor.swagger.io/) or [GraphQL Playground](https://github.com/graphql/graphql-playground) to test endpoints. Share the design with stakeholders for feedback.","tip":"Use tools like [Postman](https://www.postman.com/) to simulate API calls and identify missing fields or edge cases."},{"step":"Generate client SDKs or documentation","action":"Use [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) to create SDKs in your preferred language (e.g., Python, JavaScript). Export the schema to tools like [Redoc](https://github.com/Redocly/redoc) for interactive docs.","tip":"Automate SDK generation in CI/CD pipelines to keep client libraries in sync with API changes."},{"step":"Plan for versioning and deprecation","action":"Document your versioning strategy (e.g., `/v1/`, `/v2/`) and deprecation policy. Include migration guides for breaking changes.","tip":"Use semantic versioning (e.g., `v1.2.0`) and communicate deprecations via changelog and API status pages."}]
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/Jeffallan/claude-skills/tree/main/skills/api-designerCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Design a [REST/GraphQL] API for [DOMAIN: e.g., e-commerce platform, IoT device management, healthcare records system]. Define the core resources, their attributes, and relationships. Include: (1) Resource endpoints with HTTP methods, (2) Request/response schemas in OpenAPI 3.1 format, (3) Versioning strategy (e.g., /v1/), (4) Pagination/cursor-based patterns for large datasets, (5) Standardized error responses (e.g., 400, 404, 500 with RFC 7807 problem details). Prioritize REST conventions unless GraphQL is explicitly requested. Assume [SCOPE: e.g., MVP features, enterprise-scale, microservices architecture].
### API Design for **Acme Corp’s E-Commerce Platform (v1)**
#### **Core Resources & Endpoints**
1. **Products**
- `GET /v1/products` (List all products, paginated)
- Query params: `?page=1&limit=20&category=electronics&sort=price_asc`
- Response: `{ "items": [ { "id": "prod_123", "name": "Wireless Headphones", "price": 99.99, "stock": 42 } ], "total": 120, "page": 1, "next": "/v1/products?page=2" }`
- `POST /v1/products` (Create product)
- Body: `{ "name": "Smart Watch", "price": 199.99, "category": "wearables" }`
- Response: `201 Created` with `{ "id": "prod_456", "created_at": "2024-05-20T12:00:00Z" }`
2. **Orders**
- `POST /v1/orders` (Create order)
- Body: `{ "user_id": "user_789", "items": [ { "product_id": "prod_123", "quantity": 2 } ] }`
- Response: `201 Created` with `{ "order_id": "ord_101", "status": "pending" }`
- `GET /v1/orders/{order_id}` (Get order details)
- Response: `{ "order_id": "ord_101", "status": "shipped", "items": [ ... ], "total": 199.98 }`
3. **Users**
- `GET /v1/users/{user_id}/orders` (List user orders, paginated)
- Response: `{ "orders": [ ... ], "total": 5 }`
#### **Versioning & Pagination**
- **Versioning**: Path-based (`/v1/...`) with deprecation warnings in `/v2/` for breaking changes.
- **Pagination**: Cursor-based for `/orders` (e.g., `?cursor=abc123&limit=10`) to avoid offset issues. Default `limit=10`, max `100`.
#### **Error Handling**
- **400 Bad Request**: `{ "type": "https://api.acme.com/errors/invalid-input", "title": "Invalid Product Data", "detail": "Price must be a positive number.", "invalid_fields": ["price"] }`
- **404 Not Found**: `{ "type": "https://api.acme.com/errors/resource-not-found", "title": "Product Not Found", "detail": "No product exists with ID prod_999." }`
- **500 Internal Error**: `{ "type": "https://api.acme.com/errors/server-error", "title": "Database Timeout", "detail": "Retry in 5 seconds." }`
#### **GraphQL Alternative (Optional)**
```graphql
type Query {
products(filter: ProductFilter, pagination: Pagination): ProductConnection!
order(id: ID!): Order
}
type Mutation {
createOrder(input: OrderInput!): Order!
}
```
#### **Next Steps**
- Validate schema with [Swagger Editor](https://editor.swagger.io/) or [GraphQL Playground](https://github.com/graphql/graphql-playground).
- Generate SDKs using [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) for client libraries.skills-collection
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan