agentleFS
omidnwomidnw/my-skills/skills/api-behavior-flow/SKILL.md

api-behavior-flow

Skill0 starsChanged 9 days agoMITView on GitHub

Design an API's behavior before or while implementing it — endpoint inventory, per-endpoint request/response contracts, decision branches (validation, auth, business rules), error model, and side effects — written as a structured API-FLOW.md plus optional Excalidraw flowcharts. Use whenever the user starts designing an API or new endpoints, asks for the API flow, "flow ورودی/خروجی", endpoint behavior, what an endpoint returns in each case, edge cases of an API, or wants API behavior mapped before coding — even phrased as "before implementing, show me what each endpoint does". Not for auditing an already-built UI page by page (that's behavior-audit) or drawing one standalone diagram (that's excalidraw).

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    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:

    Before implementing a feature whose backend has non-trivial branching (payments, auth, multi-step state machines, anything with …

    line 38
  2. Distinctive:

    Design the error model once, reuse everywhere: Follow the project's existing error filter.

    line 76
  3. Distinctive:

    Keep it dense bullets; no prose paragraphs.

    line 88
  4. Distinctive:

    No endpoint without an error path: If the spec can't name the error for a failure mode, that's an open question, not a gap to skip.

    line 98
  5. Very specific:

    Add a focused contract case matrix (input/role/state → status/payload/side effects).

    line 105
  6. Distinctive:

    Every endpoint in the inventory has: input schema, ≥1 error branch per failure mode, success shape, side effects listed.

    line 118
  7. Distinctive:

    Every open question is either answered (and folded into branches) or still visibly pending.

    line 120
  8. Distinctive:

    If implemented: zod validation on every input path.

    line 122

≈ “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

API Behavior Flow — contracts and decision branches before code

Design-to-delivery integration

For complex API/feature design, consider design-to-delivery: an Excalidraw flow in docs/diagrams/ can guide brainstorming, contract detail in docs/specs/<work-id>/specs.md or linked existing API-FLOW.md, and tasks in docs/task/<work-id>/tasks.md. This recommended sequence helps catch missing error branches and incompatible contracts. Adapt the order, reuse existing documents or omit optional artifacts when a simpler method fits. A diagram is not mandatory merely because this skill is loaded. Preserve prior documents and honor explicitly requested deliverables/timing.

Purpose

Turn "we need an endpoint for X" into an explicit behavior spec — inputs, outputs, every decision branch, error cases, and side effects — before or while implementing it. The spec is the working base the implementation then follows; it prevents the classic failure of discovering missing validation, error paths, and state rules mid-implementation.

Works in two modes:

  • Design-first (new API): write the spec, get user confirmation on ambiguous branches, then implement.
  • Retro-map (existing API): extract the spec from code, flag gaps and unhandled branches, then fix or document.

When to use

  • Designing a new API or a new group of endpoints.
  • User asks what an endpoint does in every case, or for input/output flows, decision trees, or API edge cases.
  • Before implementing a feature whose backend has non-trivial branching (payments, auth, multi-step state machines, anything with permissions).
  • Trigger phrases include: "flow ورودی و خروجی API", "شرط‌هاش چیه", "قبل از پیاده‌سازی بگو هر endpoint چیکار می‌کنه", "map the endpoints first", "what does this API return when…".

Preconditions

  • You know the project's stack (NestJS + zod is the house default; method adapts to any framework). Domain rules and auth model: infer from existing code/conventions; ask the user only for genuinely ambiguous business decisions (pricing, permission boundaries).
  • For retro-mapping a large API, delegate per-module reading to Explore subagents (same partitioning as behavior-audit); the main agent reads only the module map.
  • Context discipline: never paste whole controllers into the spec — extract behavior, not code.

Workflow

  1. Scope the surface (main agent — cheap reads only): module list, existing auth guard / interceptor / filter setup, shared DTOs or schemas, error-filter convention. Record the conventions the new endpoints must match (response envelope, error shape, pagination style, ID format).
  2. Inventory endpoints. One row per endpoint: method + path · purpose (one line) · auth requirement (public / authenticated / role) · idempotent? · side effects (writes, emails, webhooks, queue jobs). Group by resource. Flag endpoints whose purpose overlaps — that's a design smell to resolve before coding.
  3. Per endpoint, extract the contract — this exact shape, as dense bullets:
    • Input: body/query/params fields with types and constraints (zod schema names when they exist); which fields optional; defaults.
    • Decision branches — numbered, exhaustive, in evaluation order: validation → auth/permission → existence/state checks → business rules → concurrency/limits. Each branch names its trigger and its outcome (error code or the path it takes).
    • Outputs: success response shape (per status code — 200 vs 201 vs 204) + every error response with its code and message shape.
    • Side effects & ordering: what gets written/emitted, in what order, and what must be transactional.
    • Open questions: business decisions only the user can make, phrased as either/or.
  4. Design the error model once, reuse everywhere. Follow the project's existing error filter; if none exists, define one before endpoint work: error envelope (code, message, field details), HTTP status mapping, which errors are user-facing vs logged. Never invent a per-endpoint error shape.
  5. Write API-FLOW.md (repo root or the project's docs convention):
    • Header: scope, date, conventions it assumes.
    • Endpoint inventory table.
    • One section per endpoint in the step-3 shape; mermaid flowchart only for endpoints with ≥3 branches or multi-step state.
    • Open questions section at top — the user answers these before or during implementation; each answered question gets folded into the branch list.
    • Keep it dense bullets; no prose paragraphs.
  6. Resolve blocking questions, then implement when requested. Batch genuinely unresolved business decisions; infer safe defaults from existing contracts. Do not require a second approval for already-authorized implementation or implement during a mapping-only request. Implementation follows the spec — each zod schema and guard maps to a listed branch. When the API is implemented per the house API rules (global AGENTS.md → API Standards), the same schemas generate the OpenAPI document — keep API-FLOW.md and the code in sync when branches change later.

Rules

  • Branches must be explicit and ordered by the actual framework pipeline. Confirm middleware, guards, validation and rate-limit execution order; the conceptual categories above are not a universal instruction to validate before authentication. Preserve ownership/privacy boundaries and avoid existence leaks.
  • No endpoint without an error path. If the spec can't name the error for a failure mode, that's an open question, not a gap to skip.
  • Quote code file:line for every claim in retro-map mode; mark unverified items.
  • Describe behavior, not implementation. The spec survives refactors; coupled specs rot.
  • Auth, validation, and rate-limit decisions must follow the Security Defaults in global AGENTS.md — the spec lists them per endpoint, the rule defines the baseline.
  • Diagrams (when asked): excalidraw skill, docs/diagrams/, never raw Excalidraw JSON in chat.
  • Add a focused contract case matrix (input/role/state → status/payload/side effects); use behavioral-testing when implementing the cases. Concurrency and rollback need cases when the endpoint actually has those risks.

Common mistakes

  • Specifying only the happy path, then "discovering" validation and permission rules during implementation.
  • Inventing a new error shape per endpoint instead of using the project's error filter.
  • Writing the spec after the code — at that point it documents decisions instead of driving them (still worth doing as a retro-map, but say so).
  • Leaving open questions embedded in endpoint sections where the user won't see them.

Verification

  • Every endpoint in the inventory has: input schema, ≥1 error branch per failure mode, success shape, side effects listed.
  • Every open question is either answered (and folded into branches) or still visibly pending.
  • Spot-check retro-mapped claims against source (file:line) — 3–5 highest-risk branches.
  • If implemented: zod validation on every input path; OpenAPI doc generated and covering each endpoint (per API Standards rule).

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.