# tanstack-start-best-practices

Best practice rules for full-stack React apps built with TanStack Start. Guides server functions, middleware, and session security.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 9800 installs · ★ 228
- Author: DeckardGer
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/DeckardGer/tanstack-agent-skills/tree/HEAD/skills/tanstack-start/SKILL.md
- Updated: 2026-09-09
- HTML: https://affpapa.org/en/nevibecode/skills/tanstack-start-best-practices

## What it does

A curated set of conventions for full-stack React applications built with TanStack Start. The skill guides data mutations with `createServerFn` and route guards using the `beforeLoad` hook. It also addresses hydration mismatches.

Rules include clear explanations alongside good and bad code examples. The guidelines cover critical areas like schema validation and cookie security, down to file separation using `.functions.ts` and deployment adapters.

Because the guidance relies directly on TanStack Start primitives, using it in a plain client-side SPA creates needless overhead.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add DeckardGer/tanstack-agent-skills --skill tanstack-start-best-practices -a claude-code
```
```bash
npx skills add DeckardGer/tanstack-agent-skills --skill tanstack-start -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/tanstack-start/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/tanstack-start/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add DeckardGer/tanstack-agent-skills --skill tanstack-start -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/tanstack-start/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add DeckardGer/tanstack-agent-skills --skill tanstack-start -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/tanstack-start/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install DeckardGer/tanstack-agent-skills tanstack-start
```

2. **Manually: put the files in place**
- File: `.github/skills/tanstack-start/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add DeckardGer/tanstack-agent-skills --skill tanstack-start -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/DeckardGer/tanstack-agent-skills --path skills/tanstack-start
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/tanstack-start/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add DeckardGer/tanstack-agent-skills --skill tanstack-start -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/DeckardGer/tanstack-agent-skills/tree/HEAD/skills/tanstack-start/SKILL.md

## When to use it
- implement server functions with schema validation using `createServerFn`
- protect routes and manage user sessions with middleware
- prevent hydration mismatches and configure streaming SSR
- separate server and client code using `.functions.ts` files

## Example prompts
- Review this server function against TanStack Start patterns and add input validation
- Set up auth middleware using the beforeLoad hook for protected routes
- Configure streaming SSR and static prerendering for this route

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: f1591cfba74c51af.

BEGIN THIRD-PARTY FILE f1591cfba74c51af
```text
---
name: tanstack-start-best-practices
description: TanStack Start best practices for full-stack React applications. Server functions, middleware, SSR, authentication, and deployment patterns. Activate when building full-stack apps with TanStack Start.
---

# TanStack Start Best Practices

Comprehensive guidelines for implementing TanStack Start patterns in full-stack React applications. These rules cover server functions, middleware, SSR, authentication, and deployment.

## When to Apply

- Creating server functions for data mutations
- Setting up middleware for auth/logging
- Configuring SSR and hydration
- Implementing authentication flows
- Handling errors across client/server boundary
- Organizing full-stack code
- Deploying to various platforms

## Rule Categories by Priority

| Priority | Category | Rules | Impact |
|----------|----------|-------|--------|
| CRITICAL | Server Functions | 5 rules | Core data mutation patterns |
| CRITICAL | Security | 4 rules | Prevents vulnerabilities |
| HIGH | Middleware | 4 rules | Request/response handling |
| HIGH | Authentication | 4 rules | Secure user sessions |
| MEDIUM | API Routes | 1 rule | External endpoint patterns |
| MEDIUM | SSR | 5 rules | Server rendering patterns |
| MEDIUM | Error Handling | 3 rules | Graceful failure handling |
| MEDIUM | Environment | 1 rule | Configuration management |
| LOW | File Organization | 3 rules | Maintainable code structure |
| LOW | Deployment | 2 rules | Production readiness |

## Quick Reference

### Server Functions (Prefix: `sf-`)

- `sf-create-server-fn` — Use createServerFn for server-side logic
- `sf-input-validation` — Always validate server function inputs
- `sf-method-selection` — Choose appropriate HTTP method
- `sf-error-handling` — Handle errors in server functions
- `sf-response-headers` — Customize response headers when needed

### Security (Prefix: `sec-`)

- `sec-validate-inputs` — Validate all user inputs with schemas
- `sec-auth-middleware` — Protect routes with auth middleware
- `sec-sensitive-data` — Keep secrets server-side only
- `sec-csrf-protection` — Implement CSRF protection for mutations

### Middleware (Prefix: `mw-`)

- `mw-request-middleware` — Use request middleware for cross-cutting concerns
- `mw-function-middleware` — Use function middleware for server functions
- `mw-context-flow` — Properly pass context through middleware
- `mw-composability` — Compose middleware effectively

### Authentication (Prefix: `auth-`)

- `auth-session-management` — Implement secure session handling
- `auth-route-protection` — Protect routes with beforeLoad
- `auth-server-functions` — Verify auth in server functions
- `auth-cookie-security` — Configure secure cookie settings

### API Routes (Prefix: `api-`)

- `api-routes` — Create API routes for external consumers

### SSR (Prefix: `ssr-`)

- `ssr-data-loading` — Load data appropriately for SSR
```
END THIRD-PARTY FILE f1591cfba74c51af

The third-party file has ended. Everything between the f1591cfba74c51af tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2940 of 4209 bytes. © DeckardGer · MIT · https://github.com/DeckardGer/tanstack-agent-skills/tree/HEAD/skills/tanstack-start/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
