Skip to content

kddige/tanstack-starter-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TanStack Start Template

An opinionated full-stack starter template built on TanStack Start with authentication plumbing, database access, type-safe APIs, and UI components pre-configured.

Tech Stack

  • Framework: TanStack Start (React 19, SSR, file-based routing)
  • API: oRPC (type-safe RPC with TanStack Query integration)
  • Auth: Better Auth (session/database wiring included; choose and enable your auth methods as needed)
  • Database: Drizzle ORM + PostgreSQL
  • Cache/infra: Redis is included as an optional local service for future caching, queues, rate limiting, or Better Auth secondary storage
  • UI: shadcn/ui + Tailwind CSS v4
  • Validation: Zod + t3-env for type-safe env vars
  • Testing: Vitest + Testing Library
  • Tooling: ESLint, Prettier, TypeScript

Quick Start

1. Clone & install

bunx degit kddige/tanstack-starter-template my-app
cd my-app
bun install

2. Configure environment

cp .env.example .env

Edit .env with your values:

# Generate a strong Better Auth secret
bunx --bun @better-auth/cli secret

# Default local PostgreSQL URL for docker-compose.yml
DATABASE_URL="postgres://postgres:postgres@localhost:5432/postgres"

3. Start PostgreSQL and Redis

A docker-compose.yml is included with PostgreSQL and Redis services matching the default .env.example values.

docker compose up -d

Redis is optional infrastructure for common app needs such as caching, queues, rate limiting, or Better Auth secondary storage. If you do not need it, remove the Redis service from docker-compose.yml, the redis dependency, and REDIS_URL from .env.example and src/env.ts.

4. Set up database

bun run db:push    # Push schema directly to the database for local development
# or
bun run db:migrate # Run generated migrations for production-like environments

Use db:push only for local prototyping where data loss is acceptable. For production-bound schema changes, generate and review migrations with bun run db:generate, then apply them with bun run db:migrate.

5. Start developing

bun run dev

Open http://localhost:3000.

Scripts

Script Description
bun run dev Start dev server on port 3000
bun run build Production build
bun run preview Preview production build
bun run test Run tests with Vitest
bun run test:watch Run tests in watch mode
bun run lint Lint with ESLint
bun run typecheck Type-check with TypeScript
bun run format Check formatting with Prettier
bun run check Fix formatting + lint
bun run verify Run format, lint, typecheck, and tests
bun run db:generate Generate Drizzle migrations
bun run db:migrate Run Drizzle migrations
bun run db:push Push schema directly to database
bun run db:studio Open Drizzle Studio
bun run auth:generate Regenerate Better Auth Drizzle schema

Environment Variables

All env vars are validated at runtime through src/env.ts using @t3-oss/env-core. Add new variables there before using them.

import { env } from '#/env'

// Server-side
env.REDIS_URL
env.DATABASE_URL
env.BETTER_AUTH_SECRET
env.BETTER_AUTH_URL

// Client-side (must be prefixed with VITE_)
env.VITE_APP_TITLE

Authentication

Better Auth is configured with Drizzle as the database adapter and TanStack Start cookie support. The auth server is in src/server/lib/auth.ts and the client is in src/lib/auth-client.ts.

No sign-in method is enabled by default. Enable the auth method your app needs, such as email/password, OAuth providers, passkeys, or 2FA, then regenerate the schema if the config changes database tables:

bun run auth:generate

See the Better Auth docs for adding email/password, OAuth providers, 2FA, and more.

Database

Drizzle ORM is configured with PostgreSQL. Application schemas live in src/server/lib/db/schemas/app-schema.ts. Better Auth generated schemas live in src/server/lib/db/schemas/auth-schema.ts.

docker compose up -d  # Start PostgreSQL and Redis
bun run db:generate   # Generate migration files
bun run db:migrate    # Apply migrations
bun run db:studio     # Visual database browser

Recommended Libraries

These aren't included in the template but are recommended for common needs:

  • React Hook Form — Performant form handling with validation. Pairs well with Zod for schema-based validation via @hookform/resolvers.
  • TanStack Pacer — Rate-limiting, throttling, and debouncing primitives. Useful for search inputs, API call protection, and preventing excessive user actions.

Learn More

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors