/aimi-engineering:nextjs-tanstack-conventionsfrom aimi-engineering
Guides Next.js App Router structure and TanStack Query data-fetching patterns: route layout, colocation, server/client boundary, query keys, cache invalidation.
Ships in aimi-engineering. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Evergreen, version-independent structural and state-management conventions
for the Next.js App Router and TanStack Query — where files live, where the
server/client boundary falls, and how server state is keyed, cached, and
invalidated. Full-depth material lives under references/; this file carries
everything needed to make a structural or data-layer decision without reading
further.
Attribution: The conventions below are paraphrased and reorganized from the official Next.js documentation (
vercel/next.js,docs/folder) and the official TanStack Query documentation (TanStack/query), both MIT licensed, then cross-checked against current docs via the Context7 MCP. No large verbatim blocks are reproduced. SeeNOTICE.md.
This skill and react-best-practices (Vercel Engineering's 58-rule
performance guide) are complementary, not overlapping. react-best-practices
answers "is this render/fetch/bundle fast?" — waterfalls, memoization,
bundle-splitting, re-render cost. This skill answers "is this file in the
right place, on the right side of the server/client boundary, keyed and
invalidated correctly?" — App Router structure and TanStack Query state
ownership. Apply both together on Next.js work; neither substitutes for the
other, and this file does not restate performance-rule content already owned
by react-best-practices.
app/ route tree: where a page's components,
data-fetching, and route-specific UI should live.'use client' or should stay a Server
Component.app/ define routing; each folder is a route
segment mapped to a URL segment. Project files (components, hooks, utils
used only by that route) can be safely colocated inside a route segment
folder without becoming routable themselves — only page, route,
layout, template, default, loading, error, and a few other
reserved file names are special.components/, lib/) is for code multiple routes
genuinely need, not a default dumping ground._folderName, leading underscore) opt a folder and
its children out of routing — useful for separating UI/implementation
detail from route structure, or avoiding collisions with future Next.js
file-convention names, without leaving the app/ tree.(folderName), parentheses) organize routes by team or
concern — e.g. multiple root layouts, or grouping (marketing) vs.
(shop) — without adding a segment to the URL path. Routes in different
groups must not resolve to the same URL; navigating across route groups
with different root layouts triggers a full page reload, not a soft
transition.loading.tsx wraps a segment in a <Suspense> boundary so Next.js can
serve a static shell while content streams; error.tsx is a per-segment
error boundary. Both are reserved file names read directly by the router —
don't hand-roll an equivalent inside page.tsx.'use client' is an
opt-in escape hatch, not a habit applied "to be safe." A component needs
it only for interactivity (event handlers), React state/effects, or
browser-only APIs.'use client' marks a boundary that extends downward through that file's
import graph, not upward to its importers. A Server Component layout can
import and render a Client Component child without itself becoming client
code — push the boundary as far down the tree as possible: isolate the one
interactive leaf, keep the shell (layout, data-fetching, page composition)
on the server.children, and the page composes it with a Server Component
passed in as that children slot; the Server Component still renders on
the server even though it's visually nested inside client-rendered chrome.
Importing the wrong direction silently forces everything downstream client-
side.useEffect after mount. useEffect-based initial fetching
produces the blank-shell → JS loads → fetch fires → render waterfall that
server-side fetching eliminates by resolving data during the server render
itself. Reserve client-side fetching (via useEffect or TanStack Query)
for data that changes after mount: polling, user-triggered refetch,
client-only interactions.await chain.
Start every independent request before awaiting any of them (call the
fetching functions first, then Promise.all the results) so requests fire
concurrently; awaiting each call in turn before starting the next is one of
the most common avoidable App Router performance mistakes.error.tsx requires
'use client' even though it lives in what is otherwise server-rendered
territory — this is a framework requirement, not a stylistic choice.['todos', {status, page}] hashes identically to
['todos', {page, status}]); two calls with different key values are
independently cached.['todos'], then
['todos', 'list', filters], then ['todos', 'detail', id] — so a broad
invalidateQueries({ queryKey: ['todos'] }) invalidates the whole family,
and a narrow key invalidates just one entry.['todo', id] where the factory emits ['todos', 'detail', id]
creates a silent cache-key drift bug: the entry exists, but the broad
invalidation you expect never reaches it.onSuccess, as the default "make the UI
reflect the mutation" mechanism. queryClient.invalidateQueries({ queryKey: [...] }), awaited or returned from onSuccess, marks matching
queries stale and triggers a refetch — this is the standard shape, not
manual local-state patching after a write.staleTime and gcTime deliberately per query; don't leave
every query at the library default or set both to Infinity reflexively.
staleTime (default 0) controls how long fetched data is considered
fresh before a refetch is triggered on next access; gcTime (default 5
minutes on the client, Infinity during server rendering) controls how
long an unused cache entry is retained in memory before eviction. A query
backing rarely-changing reference data warrants a longer staleTime; one
backing a live dashboard often warrants the default or shorter.useState/component state owns
UI-only state. Don't copy fetched data into local state "to tweak it" —
that duplication desyncs from the cache the moment an invalidation or
background refetch updates the original. TanStack Query is not a
replacement for genuinely client-only state (a theme toggle, a sidebar's
open/closed flag) — keep that in ordinary component/client state; it
replaces the server-state slice that global client-state libraries are
often misused to hold.Fetching in a Server Component and using TanStack Query in a Client Component are not competing choices for the same route — the standard integration prefetches on the server and hands the cache to the client:
page.tsx), construct a QueryClient,
await queryClient.prefetchQuery({ queryKey, queryFn }) for data the page
needs, then render <HydrationBoundary state={dehydrate(queryClient)}>
around the Client Component that will read it.useQuery({ queryKey, queryFn }) with the same query key used in the prefetch — it finds
the hydrated data immediately instead of suspending, and TanStack Query's
normal cache/invalidation/refetch behavior takes over from there.HydrationBoundary is itself a Client Component; the Server Component
wrapping it does not itself need 'use client'.See references/tanstack-query-conventions.md for the full pattern,
including per-request QueryClient construction to avoid leaking state
across users.
'use client' by default instead of
isolating the interactive leaf.useEffect + useState instead of a
Server Component, Route Handler, or server-prefetched TanStack Query.awaits on independent data sources instead of starting all
requests before awaiting any of them.useState instead of reading
it, deriving from it, or updating the cache directly.Before accepting an App Router structure or a TanStack Query data-layer change, confirm:
'use client' appears only where interactivity/state/browser APIs are
actually needed, as far down the tree as possible.onSuccess.staleTime/gcTime were chosen for the data's actual freshness needs, not
left at an unconsidered default or Infinity.For the full-depth source material behind these condensed rules — additional examples, the complete prefetch/hydration pattern, and route-group edge cases — read on demand (not auto-loaded):
references/app-router-structure.md — route segments, colocation, private
folders, route groups, parallel routes, and reserved file conventions in
full.references/server-client-boundary.md — the Server/Client Component
boundary, composition patterns, data-fetching placement, and waterfall
avoidance in full.references/tanstack-query-conventions.md — query keys and factories,
invalidation, mutations, staleTime/gcTime, server-vs-client state
separation, and the App Router prefetch/hydrate integration in full.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub aimi-so/aimi-engineering-plugin --plugin aimi-engineering19 skills in this plugin
/agent-browserBrowser automation using Vercel's agent-browser CLI. Use when you need to interact with web pages, fill forms, take screenshots, or scrape data. Alternative to Playwright MCP - uses Bash commands with ref-based element selection. Triggers on "browse website", "fill form", "click button", "take screenshot", "scrape page", "web automation"./agent-native-architectureBuild applications where agents are first-class citizens. Use this skill when designing autonomous agents, creating MCP tools, implementing self-modifying systems, or building apps where features are outcomes achieved by agents operating in a loop./aimi-design-handoffInterview the operator and author a compliant BusinessSpec.md/DesignSpec.md bundle at .aimi/design-bundles/<slug>/ so /aimi:brainstorm and /aimi:plan can treat a project with no Claude Design handoff like a real one. Use when a UI feature needs planning and no design bundle exists yet. Triggers on "no design bundle", "no Claude Design handoff", "write a BusinessSpec", "write a DesignSpec", "generate a design bundle", "design handoff interview"./architecture-foundationUse when proposing, reviewing, or laying down the initial architecture for a repository — greenfield layering decisions, brownfield convention inference, folder-layout proposals, module boundaries, or any foundation-gate story that must justify layering and domain-modeling choices. Applies Clean Architecture (dependency direction, layers, ports/adapters) and Domain-Driven Design (Ubiquitous Language, Bounded Contexts, Entities, Value Objects, Aggregates, Repositories) as condensed, actionable conventions. Trigger phrases: greenfield foundation, brownfield conventions, architecture proposal, layering, folder layout, module boundaries, dependency rule, bounded context, aggregate root, domain model, ubiquitous language, ports and adapters, foundation gate.
/brainstormGuide collaborative brainstorming sessions to clarify requirements before planning. Covers batched multiple-choice questions, adaptive exit, and design document capture. Triggers on: brainstorm, explore idea, think through, what should we build./create-agent-skillsExpert guidance for creating Claude Code skills and slash commands. Use when working with SKILL.md files, authoring new skills, improving existing skills, creating slash commands, or understanding skill structure and best practices.Other plugins' skills for the same job