DeckardGer

tanstack-start-best-practices

4
1
# Install this skill:
npx skills add DeckardGer/tanstack-agent-skills --skill "tanstack-start-best-practices"

Install specific skill from multi-skill repository

# 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.

# SKILL.md


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 6 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
  • ssr-hydration-safety β€” Prevent hydration mismatches
  • ssr-streaming β€” Implement streaming SSR for faster TTFB
  • ssr-selective β€” Apply selective SSR when beneficial
  • ssr-prerender β€” Configure static prerendering and ISR

Environment (Prefix: env-)

  • env-functions β€” Use environment functions for configuration

Error Handling (Prefix: err-)

  • err-server-errors β€” Handle server function errors
  • err-redirects β€” Use redirects appropriately
  • err-not-found β€” Handle not-found scenarios

File Organization (Prefix: file-)

  • file-separation β€” Separate server and client code
  • file-functions-file β€” Use .functions.ts pattern
  • file-shared-validation β€” Share validation schemas

Deployment (Prefix: deploy-)

  • deploy-env-config β€” Configure environment variables
  • deploy-adapters β€” Choose appropriate deployment adapter

How to Use

Each rule file in the rules/ directory contains:
1. Explanation β€” Why this pattern matters
2. Bad Example β€” Anti-pattern to avoid
3. Good Example β€” Recommended implementation
4. Context β€” When to apply or skip this rule

Full Reference

See individual rule files in rules/ directory for detailed guidance and code examples.

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.