tanstack-start-architecture
Skill0 starsChanged 16 days agoMITView on GitHub
Use when creating, moving, or naming files in a full-stack TanStack Start app (file-based routes, server functions) that also uses TanStack Query, Form, Table, DB, and Devtools, organized by technical layer. Covers routes, server/ (functions, middleware, services, db), lib/queries, lib/mutations, lib/collections, SSR prefetching, server route exceptions, tests, and growth. For frontend-only, use tanstack-router-architecture.
- Reads credentials
In this repository7 other files it gives its agents.
The file
Show its rules and text
We split this skill into the rules it gives an agent
21 rules. About 0 are common, 10 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 17
Read src/ before creating files.
- Distinctive: line 52
Read references/full-tree.md when you need the expanded tree.
- Distinctive: line 54
Add a folder on first use.
- Very specific: line 55
Keep a component in the route's -components/ until a second route uses it.
- Very specific: line 81
Add routes/api/<name>.ts only for: webhooks, an auth library handler, streaming or SSE endpoints, or endpoints for mobile and other …
- Very specific: line 93
Put tests next to the file.
- Distinctive: line 94
Test services and server function handlers without rendering.
- Very specific: line 95
Put end-to-end tests in e2e/ at the repo root.
- Distinctive: line 99
Read references/growth-stages.md when deciding whether to restructure.
- Very specific: line 103
Use routes/, components/, lib/.
- Very specific: line 107
Use the default layout. Past about 10 files in a layer, group by resource inside it (server/services/billing/).
- Very specific: line 111
Keep the layers. Group by feature inside each layer and mirror it in routes/.
- Distinctive: line 115
Read references/anti-patterns.md when reviewing a layout or before moving files.
- Very specific: line 117
Do not import server/services or server/db from client code.
- Distinctive: line 118
Do not put business logic in server functions or routes.
- Distinctive: line 119
Do not add a server route where a server function works.
- Distinctive: line 120
Do not write query keys inline.
- Very specific: line 121
Do not fetch in useEffect.
- Distinctive: line 122
Do not trust server function input.
- Very specific: line 123
Do not put non-route files in routes/ without a - prefix.
- Distinctive: line 124
Do not use PascalCase file names.
≈ “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.
Files
TanStack Start architecture
Full-stack React app with TanStack Start (TanStack Router plus server functions), grouped by technical role. Same client layers as tanstack-router-architecture, plus a top-level server/ folder. Data code lives in lib/queries, lib/mutations, and lib/collections, and calls server functions. For a frontend-only app, use tanstack-router-architecture.
Target version
Written for TanStack Start (@tanstack/react-start, Vite-based), Router v1, Query v5, Form, Table, DB, and Devtools on 2026-10-30. Start's API still changes between releases, so check the installed version for the router entry file and server route syntax.
Follow the repo first
Read src/ before creating files. If the project already has conventions (folder names, casing, aliases), use them. Check vite.config.ts for the Start plugin and tsconfig.json for aliases.
Default directory layout
src/
router.tsx # createRouter, query client, SSR-query integration
routeTree.gen.ts # generated. Commit it. Never edit it.
start.ts # global middleware and start config
routes/ # file-based routes, thin
__root.tsx # document shell, providers, devtools
index.tsx
invoices/
route.tsx
index.tsx
$invoiceId.tsx
-components/ # route-private UI (the - prefix is ignored by the router)
api/ # server routes: exceptions only (see below)
components/
ui/ forms/ tables/ providers/
hooks/
lib/ # client-safe code
queries/ # query keys and queryOptions, call server functions
mutations/ # mutationOptions and useMutation hooks
collections/ # TanStack DB collections
forms/ schemas/ auth/ utils/
server/ # server-only code
functions/ # createServerFn handlers
middleware/ # auth, logging, validation middleware
services/ # business logic
db/ # ORM client, schema, migrations
config/ # client env and constants
types/ styles/ test/Read references/full-tree.md when you need the expanded tree. Read references/data-layer.md when writing server functions, queries, mutations, collections, loaders, forms, or tables.
- Add a folder on first use. Do not create empty ones.
- Keep a component in the route's
-components/until a second route uses it. - Route files do routing only: path, search schema, loader, composition.
Naming conventions
- Files and folders: kebab-case. Route files follow router conventions.
- Components:
InvoiceTableininvoice-table.tsx. Named exports, except route files, which exportRoute. - Server functions:
invoice.functions.ts, exportinglistInvoicesFn,createInvoiceFn. - Middleware:
auth.middleware.ts. Services:invoice.service.ts. - Queries:
invoice.queries.ts. Mutations:invoice.mutations.ts. Collections:invoice.collection.ts. - Schemas:
invoice.schema.ts. Types:invoice.types.ts. Hooks:use-thing.ts. - Tests: next to the file. Imports:
@/maps tosrc/.
Dependency direction
routes -> components -> hooks -> lib/{queries,mutations,collections} -> server/functions -> server/services -> server/dblib/queries,lib/mutations,lib/collectionscallserver/functionsonly. They never importserver/servicesorserver/db.server/functionsvalidate input withlib/schemas, applyserver/middleware, callserver/services. No business logic.server/servicesandserver/dbare imported only byserver/files and server routes. Never by components orlib/.componentsnever importroutes.lib/utils,lib/schemas, andtypesare shared by both sides and import nothing from the app.
Server routes: exceptions only
Add routes/api/<name>.ts only for: webhooks, an auth library handler, streaming or SSE endpoints, or endpoints for mobile and other platforms. Keep handlers thin and call server/services. Everything else is a server function.
Where things live
- Env: client vars in
config/env.ts(import.meta.env,VITE_prefix). Server secrets inserver/env.ts(process.env), validated at startup. Never importserver/env.tsfrom client code. List vars in.env.example. - Query client: create per request in
router.tsx, pass through router context, and connect with the Router SSR-query integration. - Devtools: mount Router, Query, and DB devtools in
routes/__root.tsx, dev only. - Auth: session helpers in
lib/auth/(client-safe), session reading and guards inserver/middleware/auth.middleware.ts. Guard routes withbeforeLoadin a layout route. - Client state: prefer search params and the query cache.
Tests
- Put tests next to the file. Put setup and helpers in
test/. - Test services and server function handlers without rendering. Test components with a router and query client wrapper.
- Put end-to-end tests in
e2e/at the repo root.
Structure at three sizes
Read references/growth-stages.md when deciding whether to restructure.
Prototype
Use routes/, components/, lib/. Add server/functions and server/db on first use.
Mid-size
Use the default layout. Past about 10 files in a layer, group by resource inside it (server/services/billing/).
Large
Keep the layers. Group by feature inside each layer and mirror it in routes/. Enforce boundaries with lint rules.
Anti-patterns
Read references/anti-patterns.md when reviewing a layout or before moving files.
- Do not import
server/servicesorserver/dbfrom client code. - Do not put business logic in server functions or routes.
- Do not add a server route where a server function works.
- Do not write query keys inline. Use the key factory.
- Do not fetch in
useEffect. Use a loader plusensureQueryData. - Do not trust server function input. Validate it and check auth in middleware.
- Do not put non-route files in
routes/without a-prefix. - Do not use PascalCase file names.
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
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.

