agentleFS
fatih-developerfatih-developer/fth-skills/skills/contract-first-designer/SKILL.md

contract-first-designer

Skill7 starsChanged 43 days agoMITView on GitHub

Write the OpenAPI or AsyncAPI contract before any code: resources, schemas, error format, pagination, and versioning, plus contract tests. Use when the user starts a new API, adds endpoints, needs a spec for frontend and backend to agree on, or wants to move from code-first to contract-first.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before designing, make sure you have the inputs below.

    line 16
  2. Distinctive:

    Instead of relying only on E2E tests, generate the scenarios required to prove the provider (backend) and consumer (frontend) honor the …

    line 38
  3. Very specific:

    No Ambiguous Types: Avoid Any or Object types in definitions.

    line 100
  4. Distinctive:

    Standardized Errors: Use RFC 7807 Problem Details for HTTP APIs instead of custom random error schemas.

    line 101
  5. Very specific:

    Security Definitions: Ensure Authorization headers/schemes (Bearer, ApiKey) are explicitly defined in the spec components.

    line 102

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Contract-First Designer Protocol

This skill enforces API design before implementation. It breaks the habit of writing controller code and auto-generating the spec from it. By designing the OpenAPI/AsyncAPI contract first, backend and frontend teams can work in parallel.

Core assumption: Code is cheap, contracts are expensive to change. A well-designed API contract prevents endless integration meetings.


0. Context Intake

Before designing, make sure you have the inputs below. Read the previous workflow step's artifact first if it exists. Ask only for what is missing, in a single message, and state any assumption you make instead of blocking.

  • Resources and main use cases, or the feature being built.
  • Protocol (from protocol-selection-output.json if it exists) and style conventions (naming, pagination, error format).
  • Existing specs or endpoints the new contract must stay compatible with.

1. Specification Generation (Static)

Analyze the business requirements to output a standard API documentation format.

REST APIs (OpenAPI 3.x)

  • Define all endpoints, methods (GET, POST, etc.).
  • Explicitly define standard HTTP status codes (200 OK, 201 Created, 400 Bad Request, 401 Unauthorized, 404 Not Found, 500 Internal Server Error).
  • Define strict Request/Response JSON schemas using $ref components.
  • Include pagination parameters (limit, cursor/offset) for all collection endpoints.

Event-Driven / WebSockets (AsyncAPI)

  • Define Channels and Messages.
  • Specify headers, payload shape, and correlation IDs.

2. Contract Testing (Pact / Schema Validation)

Instead of relying only on E2E tests, generate the scenarios required to prove the provider (backend) and consumer (frontend) honor the contract.

  • Describe the expected state.
  • Define what the mock provider should return.

3. Output Generation

Outputs. In file mode — the user wants artifacts, or this skill runs as a step of an ecosystem workflow — write both files below to docs/api-report/. In inline mode — a quick question — answer in the chat and end with the JSON below as a Handoff block instead of creating files.

  1. Human-Readable Markdown (docs/api-report/contract-designer-report.md)
### 📝 Contract-First Design
- **Protocol:** HTTP REST
- **Specification:** OpenAPI 3.1
- **Focus Area:** User Orders

#### 📑 OpenAPI Specification (Snippet)
```yaml
openapi: 3.1.0
info:
  title: Order API
  version: 1.0.0
paths:
  /orders:
    post:
      summary: Create a new order
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrderCreatePayload'
      responses:
        '201':
          description: Order created
# ...
```

#### 🛡️ Contract Testing Scenarios (Pact)
- **State:** "User is authenticated and has $50 balance"
- **Request:** `POST /orders` with valid payload.
- **Expected Response:** `201 Created` with `order_id` string.
  1. Machine-Readable JSON (docs/api-report/contract-designer-output.json)
{
  "skill": "contract-first-designer",
  "protocol": "REST",
  "endpoints": [
    {"method": "POST", "path": "/orders", "request_schema": "OrderCreatePayload", "responses": [201, 400, 401]}
  ],
  "pact_states": ["User is authenticated and has $50 balance"]
}

When to Skip

  • The user asks about a single existing endpoint's behavior, or the API is a private function call with no network boundary.

Guardrails

  • No Ambiguous Types: Avoid Any or Object types in definitions. Require strict typing (e.g., string with format: uuid).
  • Standardized Errors: Use RFC 7807 Problem Details for HTTP APIs instead of custom random error schemas.
  • Security Definitions: Ensure Authorization headers/schemes (Bearer, ApiKey) are explicitly defined in the spec components.

🔗 Next Steps & Handoffs

<!-- BEGIN GENERATED: handoffs (generated from the ecosystem workflow map by build_ecosystems.py — do not edit by hand) -->

Ecosystem: @ecosystem-api — API Domain.

Workflows:

  • OpenAPI-First Design Flow (api-design, step 2 of 4): next → @api-mock-designer, @sdk-scaffolder (optional) (can run in parallel).

Direct handoffs:

  • @breaking-change-detector — A previous contract version exists.

Handoff contract: pass results to the next skill through docs/api-report/contract-designer-output.json with the fields skill, workflow, created_at, inputs, summary, and next (the handoff contract of @ecosystem-api). If a next skill is not installed, continue with its step from the ecosystem map, or install it with npx skills add fatih-developer/fth-skills --skill <name> after the user agrees.

<!-- END GENERATED: handoffs -->

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.