agentleFS
LooseWireDevLooseWireDev/mealforge/.agents/skills/tanstack-router-patterns/SKILL.md

tanstack-router-patterns

Skill1 starsChanged 4 months agoMITView on GitHub

Canonical patterns for the web app's TanStack Router + TanStack Query setup — file-based routing, the generated route tree, data fetching, and API client wiring. Use when adding routes, pages, or data fetching in apps/web.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Hono backend: use the typed tRPC hooks from src/lib/trpc.ts — trpc.<feature>.<procedure>.useQuery() / .useMutation().

    line 38
  2. Very specific:

    Python backend: use src/lib/apiClient.ts (reads VITE_API_URL) with TanStack Query (useQuery({ queryKey, queryFn })), types from …

    line 39
  3. Very specific:

    Prefer route loaders for data a page cannot render without.

    line 41
  4. Very specific:

    No barrel index.ts files anywhere under apps/web/src/.

    line 50

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

TanStack Router Patterns (apps/web)

File-based routing

Routes live in apps/web/src/routes/. The route tree is generated into src/routeTree.gen.ts by the TanStack Router Vite plugin — never edit that file, and never import route components manually to "wire" them; creating the file in src/routes/ IS the wiring.

  • __root.tsx — root layout: createRootRoute({ component: RootLayout }), renders shared nav and <Outlet />.
  • index.tsx — / via createFileRoute('/').
  • about.tsx → /about; posts.$postId.tsx → /posts/:postId; _layout.tsx files create pathless layouts.
import { createFileRoute } from '@tanstack/react-router';

export const Route = createFileRoute('/about')({
  component: AboutPage,
});

function AboutPage(): React.ReactElement {
  return <div>…</div>;
}

Type safety comes from the declare module '@tanstack/react-router' { interface Register { router: typeof router } } block in main.tsx — leave it in place. Use <Link to="/..."> (typed) instead of raw anchors, and Route.useParams() / Route.useSearch() for route data.

Pages vs features

Route files stay thin: layout + composition. Real UI and logic live in src/features/<name>/ (scaffolded by the feature generator — see the feature-development skill) and shared pieces in src/components/. A route file imports the feature's components; it does not contain business logic.

Data fetching

main.tsx already provides a QueryClientProvider.

  • Hono backend: use the typed tRPC hooks from src/lib/trpc.ts — trpc.<feature>.<procedure>.useQuery() / .useMutation(). When adding the FIRST tRPC call, wrap the app in <trpc.Provider client={createTRPCClient()} queryClient={queryClient}> in main.tsx (the scaffold leaves a comment marking the spot). Types flow from @<project>/shared/types — never define API response types by hand.
  • Python backend: use src/lib/apiClient.ts (reads VITE_API_URL) with TanStack Query (useQuery({ queryKey, queryFn })), types from src/lib/api-schema.ts (regenerate with pnpm run codegen).

Prefer route loaders for data a page cannot render without; use component-level queries for everything else.

Auth (Hono backend)

src/lib/auth.ts exposes the Better Auth client (useSession, signIn, signOut). Gate protected routes with a beforeLoad redirect on the route definition, not by conditionally rendering inside components.

Conventions that trip people up here

  • Components are the only default exports; hooks/utils are named exports with explicit return types.
  • No barrel index.ts files anywhere under apps/web/src/.
  • Tests (*.test.tsx) sit next to what they test and assert behavior, not markup structure.

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.