.cursor/skills/api-integration-helper/SKILL.md
Connects Next.js frontends to backend Route Handlers with centralized fetch wrappers, TypeScript response types, simple async state (loading / empty / success / error), and debug-friendly single-module API code. Use when wiring client components to `app/api`, refactoring scattered fetch calls, defining request/response typing for API calls, or when the user mentions API integration, fetch patterns, or keeping the frontend decoupled from backend internals.
npx skillsauth add Volodymyr199606/payment-risk-reviewer api-integration-helperInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Ship clean HTTP boundaries between the browser and Route Handlers (or a single backend base URL). The frontend knows URLs + JSON shapes + errors — nothing about databases, ORMs, or server-only modules.
Pairs with contract-architect (stable JSON types), frontend-architect (where lib/api lives), ui-builder (how screens show async states).
| Do | Do not |
|----|--------|
| Import shared types from types/ (or lib/api re-exports) | Import server modules (db, prisma, route internals) into client code |
| Call documented HTTP routes (/api/...) via lib/api | Duplicate URL strings across feature components |
| Treat the response as JSON matching a contract | Assume field names or nesting match DB columns |
Client components ("use client") must only use lib/api + types + UI — never direct DB or env secrets on the client.
lib/
api.ts # optional: apiClient.ts or api/review.ts if > ~150 lines
types/
api.ts # or index.ts — request/response DTOs aligned with Route Handlers
One primary module for HTTP keeps breakpoints, logging, and error mapping in one place.
Use native fetch in lib/api unless the repo already standardizes on something else.
Conventions
fetch("/api/review", { ... }) so Vercel previews and local dev work without NEXT_PUBLIC_API_URL for the default case.headers: { "Content-Type": "application/json" } on POST/PUT/PATCH; body: JSON.stringify(payload).response.ok; if false, try await response.json() for { message?: string } (or project error shape), then throw a small ApiError or return Result — pick one style and reuse it.AbortController only if UX needs cancel; avoid extra libraries.Central wrapper (recommended)
Implement one internal helper, e.g. requestJson<T>(path, init), that:
fetchprocess.env.NODE_ENV === "development")Feature functions stay thin:
// lib/api.ts — illustrative
export async function postReview(input: ReviewRequest): Promise<ReviewResponse> {
return requestJson<ReviewResponse>("/api/review", {
method: "POST",
body: JSON.stringify(input),
});
}
types/ and match what Route Handlers return and accept (same names as contract-architect if used).requestJson<T> is enough for most MVPs; avoid deep mapped types.errorCode string union on server responses if the UI must show different copy — keep the union small.Default for hackathon MVP: useState + one discriminated union per screen or per resource.
type AsyncState<T> =
| { status: "idle" }
| { status: "loading" }
| { status: "empty" } // optional: valid “no data” after success
| { status: "success"; data: T }
| { status: "error"; message: string };
data.Escalate to React Query / SWR only when the repo already uses them or caching/refetch is required — not for a single POST demo.
Map the union to UI as in ui-builder: skeleton (loading), short copy (empty), cards (success), alert + retry (error). The API layer does not render UI; it only returns data or throws/returns errors consistently.
lib/api/* folder): developers open one place to set breakpoints.{ message: string, code?: string } from the server so the client does not parse raw stacks.fetch inside components/features/* for the same route called in multiple places.| Check | Action |
|-------|--------|
| Types | pnpm exec tsc --noEmit (or project equivalent) passes |
| Success | Submit valid payload; network tab shows 200 and JSON matches T |
| Error | Force 4xx/5xx; UI shows mapped message; no uncaught promise |
| Coupling | Grep components for @/lib/db or prisma — should be empty on client |
One module, typed JSON, one async union, HTTP-only coupling — enough structure to debug and extend without framework churn.
development
Builds Next.js + TypeScript UIs with modular components, clear layout hierarchy, card-based results, polished spacing and typography, async states (loading, empty, success, error), responsive behavior, and thin API integration. Use when implementing or polishing screens, building feature UI from scratch, wiring components to backend routes, or when the user asks for clean minimal UI, demo-ready pages, or step-by-step UI construction with manual test steps.
tools
Designs hackathon-ready frontend architecture: folder layout, page shell, component boundaries, state flow, API touchpoints, TypeScript types, async UI states, and responsive patterns. Optimized for Next.js MVPs, speed, and demo quality. Use when scaffolding or refactoring UI, planning pages and components, wiring client to API, or when the user mentions frontend structure, layout, state management, or implementation order for an MVP.
development
Audits an existing MVP for demo readiness: user flow clarity, visible value, visual polish, information scanability, first impression, and what to cut or simplify. Produces a prioritized list of practical, quick-win improvements only. Use when polishing for a demo, hackathon presentation, stakeholder walkthrough, or when the user asks for demo readiness, first impression, or what to remove before showing the product.
tools
Designs clean, stable MVP API and UI contracts: input/output shapes, TypeScript types, sample JSON, required vs optional fields, validation hints, and extension notes. Optimized for one-day builds and card-friendly UIs. Use when defining endpoints, request/response schemas, form models, shared types, or before wiring frontend to backend; when the user mentions contracts, DTOs, API design, or stable JSON shapes for an MVP.