Skip to main content

TanStack Start + Hono Full-Stack Architecture

TanStack Start is a full-stack React framework with SSR, file-based routing, and server functions. Hono is an ultrafast, lightweight web framework that runs on any JavaScript runtime. Combining them in a monorepo gives you a modern, type-safe full-stack stack.

badmin

Admin panel — TanStack Start + Hono + Drizzle + SQLite.

cyop

AI captioning platform — TanStack Router + Hono + tRPC + Drizzle + Postgres.

Architecture Overview

Frontend: TanStack Start

TanStack Start provides file-based routing with @tanstack/react-router, SSR via Vinxi, and full-stack server functions.

Key Setup

Route Configuration

Server Functions

TanStack Start supports server-side functions that run only on the server:
Use server functions for data fetching and mutations that need server-side execution. They automatically handle serialization and avoid leaking secrets to the client.

Backend: Hono

Hono is the API layer — fast, type-safe, and runtime-agnostic. It handles auth, CRUD, and business logic.

Basic Server Setup

Service Pattern

Use factory functions for dependency injection:
Factory functions (createXxxService) give you explicit dependency injection without class boilerplate. Each service receives its dependencies as parameters, making testing trivial — just pass mock implementations.
Instead of JWT tokens, use signed session cookies for simplicity and security:
Session versioning lets you force logout users when their password changes or account is disabled. Increment sessionVersion on the user record — stale cookies will be rejected.

Localized Error Responses

For bilingual apps, return locale-aware error messages from the API:

Styling: UnoCSS

For TanStack Start projects, UnoCSS is lighter and faster than Tailwind for utility classes:
Use presetWind4 for Tailwind CSS 4-compatible utilities. Use presetIcons for FontAwesome/Material icon classes without importing SVGs.

Best Practices

  1. Monorepo with shared contracts — Put Zod schemas and tRPC routers in a shared package so frontend and backend stay type-synced
  2. Factory-function services — Prefer createAuthService(opts) over class AuthService for explicit DI
  3. Signed cookie sessions — Simpler than JWT, revocable by bumping sessionVersion
  4. Server functions for secrets — Never expose API keys or DB queries in client code
  5. Locale-aware errors — Frontend sends X-Locale, server returns localized keys
  6. UnoCSS over Tailwind — Faster build, icon presets, and Tailwind-compatible utilities

References

Last modified on April 17, 2026