tanstack-start-best-practices
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.
What this skill does
# 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.
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.