From cklph-nextjs
The lib/data/ rule. Components and hooks NEVER call fetch directly. Use when adding any client-side API call or wiring a form/mutation to the backend.
How this skill is triggered — by the user, by Claude, or both
Slash command
/cklph-nextjs:data-layerThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Components and hooks never call `fetch("/api/…")`. Every client-side network call goes through `lib/data/`. A raw fetch in a component is a bug — Semgrep rule `no-raw-fetch-to-api-in-client-code` will catch it.
Components and hooks never call fetch("/api/…"). Every client-side network call goes through lib/data/. A raw fetch in a component is a bug — Semgrep rule no-raw-fetch-to-api-in-client-code will catch it.
The data-layer wraps every request with:
useAuthQuery calls refetch automatically.Skip the layer and you lose all four. The bypass shows up as flaky logouts on token expiry, missing CSRF errors in production, duplicate requests on mount, and stale UI after writes.
| Need | Use | Returns |
|---|---|---|
| One-off read (server action, effect) | authFetcher | Promise<T> |
| Cached read in a component | useAuthQuery | { data, error, isLoading, mutate } |
| Mutation (POST/PUT/PATCH/DELETE) | useAuthMutation | { trigger, data, error, isMutating } |
// Cached read
const { data, isLoading } = useAuthQuery<Item[]>("/api/items");
// Mutation — declares what to invalidate on success
const { trigger } = useAuthMutation<CreateItemInput, Item>("/api/items", {
method: "POST",
invalidates: ["/api/items", "/api/dashboard/stats"],
});
If you see fetch("/api/…") inside components/, app/, or lib/hooks/, rewrite it before doing anything else. The pattern is non-negotiable across MailPrism, SendBriefs, BeforeMerge, and ApertureStack.
Server-side data fetching (RSC, route handlers) does NOT use lib/data/ — it talks to services or Supabase directly. The rule is for the client only.
Pair with architecture for the lib/ layout, api-routes for what's on the other end of the call.
Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub chykalophia/cklph-marketplace --plugin cklph-nextjs