π Why TanStack Start?
Tired of Next.js's confusing directives and ever-changing caching mechanisms? TanStack Start offers a refreshing alternative with full type safety, clear client-server boundaries, and a simpler mental model. This guide walks you through building a complete to-do application, covering every core feature from database integration to optimistic updates. By the end, you'll understand how to leverage server functions, dynamic routing, and client-only components effectively.

π οΈ Project Setup & Core Architecture
Start by scaffolding your project with npm create @tanstack/start@latest. Choose Tailwind CSS, ESLint, Drizzle ORM, and Shadcn for a modern stack. The generated structure includes a router.tsx that auto-generates a routeTree.gen.ts for full type safety across routes. Key files to know:
router.tsx: Central routing configuration.routes/: Define pages; use$for dynamic params (e.g.,$id).db/schema.ts: Define your database schema with Drizzle.
π‘ Pro Tip: Restart your TypeScript server after the first
routeTree.gen.tsgeneration to clear initial errors.

β‘ Server Functions & Data Flow
Unlike Next.js, TanStack Start runs loaders on both client and server. Use createServerFunction to ensure database calls execute only on the server. For a to-do app, create a serverLoader to fetch data:
const serverLoader = createServerFunction({
method: 'GET',
handler: async () => {
return db.query.todos.findMany();
}
});
For mutations (create, update, delete), use POST methods with useServerFunction hook to handle redirects and error states. Here's a comparison of key patterns:
| Pattern | Use Case | Client Behavior | Server Behavior |
|---|---|---|---|
createServerFunction | Data fetching/mutations | Makes fetch request | Executes directly |
createServerOnly | Sensitive operations | Throws error | Runs normally |
createClientOnly | Browser-only logic | Runs normally | Throws error |
createIsomorphic | Dual behavior | Runs client logic | Runs server logic |
Optimistic Updates: For instant UI feedback (e.g., toggling a checkbox), manage local state with useState and invalidate the router after the server call completes.

β Conclusion & Best Practices
TanStack Start simplifies full-stack development by eliminating ambiguous directives. Key takeaways:
- Use
createServerFunctionfor all server-side data operations. - Leverage client-only components for browser-specific features (e.g., local storage).
- Always wrap server calls in
useServerFunctionwhen invoking from client code. - Embrace type safety β the auto-generated route tree ensures zero runtime routing errors.
π Information Date: 2024-05-24
For more advanced patterns, check out our AI-powered development tools and budget PC builds that outperform consoles.
