agentleFS
Echo-ScionEcho-Scion/orioncortex/.agents/skills/api-contract/SKILL.md

api-contract

Skill2 starsChanged 5 days agoMITView on GitHub

Use when defining, validating, or modifying API data contracts, request/response validation schemas (Zod, OpenAPI), or boundary safety layers.

14 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use design-system and release.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • AnthropicSkill

    design-system

    Audit, document, or extend your design system. Use when checking for naming inconsistencies or hardcoded values across components, writing documentation for a component's variants, states, and accessibility notes, or designing a new pattern that fits the existing system.

    Also in 3 projects that use this

  • MicrosoftSkill

    release

    Use ONLY when the user explicitly asks to cut/publish a Huabu desktop release or tag a version. Performs an outward action — bumps the version in apps/desktop/package.json, commits + annotated-tags vX.Y.Z, and pushes the branch + tag. That tag push auto-builds the macOS/Windows installers and publishes a GitHub Release. Provides `status`, `bump`, `tag-push`, and a one-command `run` (bump → tag-push).

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

8 rules. 0 are common, 7 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 11 edited versions we read keep these.

  • 7

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When writing API endpoints, use these exact templates:

    line 13
  2. Distinctive:

    Never guess API shape. Code without a validated specification is speculative guessing.

    line 45
  3. Distinctive:

    When a requirement spans multiple independently testable sub-domains (e.g., auth, billing, notifications):

    line 48
  4. Distinctive:

    FORBIDDEN (Raw DB Exception Leaks): Never expose internal database error messages, stack traces, table names, or raw SQL queries in …

    line 61
  5. Distinctive:

    Every HTTP endpoint must return a structured, predictable response envelope:

    line 67
  6. Distinctive:

    Before implementing the route handler:

    line 101
  7. Distinctive:

    Write an automated unit test supplying invalid, malicious, or extraneous parameters.

    line 102
  8. Very specific:

    Verify that the contract layer rejects the payload with an explicit HTTP 400/422 and matching error code before connecting business logic.

    line 103

“Common” is measured: kept by at least 6 in 10 of the 11 edited versions of this file we could read. “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

API Contract Guard

Your role is to ensure zero malformed data reaches the database.

Zod Schema Templates (MANDATORY)

When writing API endpoints, use these exact templates:

1. The Auth/Registration Template

export const RegisterSchema = z.object({
  email: z.string().email("Invalid email format"),
  password: z.string().min(8, "Minimum 8 characters").regex(/[0-9]/, "Must contain a number"),
  name: z.string().min(2).max(50)
});

2. The Pagination Template (GET Requests)

export const PaginationQuerySchema = z.object({
  page: z.coerce.number().int().positive().default(1),
  limit: z.coerce.number().int().positive().max(100).default(20),
  search: z.string().optional()
});

3. The Strict Update Template (PATCH Requests)

export const UpdateProfileSchema = z.object({
  bio: z.string().max(200).optional(),
  avatarUrl: z.string().url().optional()
}).strict(); // Prevents injection of arbitrary fields like `isAdmin`

The Agent MUST never proceed with an API implementation without defining the validation schema (Zod, Pydantic, or OpenAPI) first.

📜 Specification-First Architecture & Protocol (SDD)

Never guess API shape. Code without a validated specification is speculative guessing. Follow this 4-phase protocol:

Phase 0: Scope & Capability Mapping

When a requirement spans multiple independently testable sub-domains (e.g., auth, billing, notifications):

  1. Decompose First: Define an explicit Capability Map before drafting individual endpoint schemas:
    | Module ID | Responsibility | Dependencies |
    |---|---|---|
    | auth | Accounts, JWT tokens, RBAC | — |
    | billing | Invoicing, payment webhooks | auth |
    | notifications | Email dispatch, alerts | auth, billing |
  2. Acyclic Dependency Invariant: Dependency arrows must point in one direction. Cyclical dependencies between modules are strictly forbidden.

Phase 1: Contract Invariants & Negative Refusals

  • FORBIDDEN (Untyped Any Payloads): Loosely typed request bodies (any, dynamic, raw dictionaries, untyped maps) are strictly forbidden across boundary layers. Every endpoint MUST validate incoming parameters against an explicit Zod, Pydantic, or OpenAPI contract.
  • FORBIDDEN (Raw DB Exception Leaks): Never expose internal database error messages, stack traces, table names, or raw SQL queries in client-facing HTTP responses. Internal exceptions MUST be caught, logged server-side, and mapped to standard error envelopes.
  • FORBIDDEN (Mass-Assignment): Mutation schemas MUST enforce strict key stripping (.strict() in Zod, extra="forbid" in Pydantic). Rejecting unexpected payload properties is non-negotiable.
  • Immutable DTO First: Define the complete contract DTO before authoring service or repository logic.

Phase 2: Standard Unified Response Envelopes

Every HTTP endpoint must return a structured, predictable response envelope:

Success Envelope (HTTP 200/201):

{
  "success": true,
  "data": {},
  "error": null,
  "meta": {
    "timestamp": "2026-10-11T22:45:00Z",
    "version": "v1"
  }
}

Error Envelope (HTTP 4xx/5xx):

{
  "success": false,
  "data": null,
  "error": {
    "code": "VALIDATION_FAILED",
    "message": "Field 'email' failed format validation",
    "details": [
      { "field": "email", "issue": "Invalid email address format" }
    ]
  },
  "meta": {
    "timestamp": "2026-10-11T22:45:00Z"
  }
}

Phase 3: Contract Rejection Tests (Red-First & TDD Handoff)

Before implementing the route handler:

  1. Write an automated unit test supplying invalid, malicious, or extraneous parameters.
  2. Verify that the contract layer rejects the payload with an explicit HTTP 400/422 and matching error code before connecting business logic.
  3. Hand off validated payload schemas to /data-logic for immutable model mapping and execute the full cycle under /strict-tdd.

📚 Mandatory Knowledge Routing (JIT References)

If your current task intersects with these domains, you MUST execute view_file on the target BEFORE writing code:

If User Prompt/Task Relates To...Immediately Load (view_file)
API Safety Patterns.agents/skills/api-contract/references/api_safety_patterns.md

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.