Infrastructure

The backbone of the boilerplate. PostgreSQL, Redis, tRPC, transactional email, and structured error handling — all production-grade and ready to scale.

PostgreSQL via Drizzle ORM

21 tables defined with Drizzle ORM covering auth, organizations, chat, memories, files, connectors, AI skills, and usage tracking. Full migration support included.

  • 21 tables with comprehensive relations defined at the schema level
  • Type-safe queries via Drizzle ORM with automatic type inference
  • 50+ query functions in the data access layer
  • All functions wrapped in try/catch with ChatSDKError for structured error handling
  • Organization scoping on all list/filter queries
  • Migration setup with drizzle-kit: generate, push, and migrate commands

Upstash Redis

Serverless Redis for three critical functions: rate limiting, token usage tracking, and conversation compaction storage.

  • Rate limiting: sliding window via @upstash/ratelimit (10 messages per 60s for paid users)
  • Token budget: per-user key with set/get/increment/decrement (1M initial budget)
  • Compaction cache: conversation summaries with 7-day TTL
  • HTTP-based Upstash client — no persistent TCP connections needed
  • Free tier users blocked (0 messages); paid tier: 10/60s

tRPC v11

Type-safe client-server communication layer with 10 routers and 82+ procedures. All calls except chat streaming go through tRPC.

  • 10 routers: chat, user, usage, payments, memory, file, org, team, skills, connectors
  • Public and private procedures with session-based auth middleware
  • Auth middleware extracts activeOrganizationId from session
  • Scope-aware analytics: org admins see all, team-admins see teams, members see own data
  • Three-tier permission model on team operations

Transactional email via Resend

Five email functions with branded HTML templates for verification, password reset, org invitations, and contact forms.

  • Verification link and OTP emails (adapts by type: email-verification, sign-in, forget-password)
  • Organization invitation emails with branded templates
  • Password reset emails with token expiration
  • Contact form via React Email template
  • Shared emailWrapper() for consistent header/footer across all emails
  • Non-blocking sending via waitUntil() for post-signup and invitation flows

Structured error handling

A custom ChatSDKError class with type-safe error codes, HTTP status mapping, visibility policies, and a toResponse() method for consistent API errors.

  • Custom ChatSDKError with type:surface error codes
  • HTTP status mapping: 400, 401, 403, 429, 503
  • Visibility policies: 'response' (shown to user) vs 'log' (server only)
  • 12 error surfaces: chat, auth, api, stream, database, history, and more
  • toResponse() method for consistent error responses

Shared utilities

Helper functions and type definitions used across the codebase. Tailwind class merging, URL helpers, message conversion, and debug logging.

  • cn() for Tailwind class merging via clsx + tailwind-merge
  • absoluteUrl() for generating full URLs
  • convertToUIMessages() for transforming DB messages to chat UI format
  • withFallback() for graceful error recovery
  • generateUUID() for ID generation
  • Development-only debug logging utilities

Custom React hooks

Three hooks for chat UI scroll behavior, message tracking, and responsive design.

  • useMessages: combines scroll-to-bottom with message-sent tracking
  • useScrollToBottom: MutationObserver + ResizeObserver with 150ms debounce
  • useIsMobile: matchMedia with 768px breakpoint, SSR-safe

Database schema overview

GroupTables
Authuser, session, account, verification
Organizationsorganization, member, invitation, team, team_member
Chatchat, message, vote, stream
AImemory, ai_skills, ai_skills_share, chatbot_preferences
Filesfiles, file_share
Integrationsuser_connector
Analyticsusage_event

tRPC routers

RouterProceduresDescription
chat17Chat CRUD, messages, votes, streams, pin/unpin, title/visibility
user9Profile, billing sync, sessions, preferences
usage6Token balance, rate limits, org analytics
payments2Stripe checkout & billing portal
memory7CRUD, full-text search, upsert (org-scoped)
file11CRUD, sharing, org/team scoping
org11Organization management, invitations, roles
team7Team CRUD, member management, permissions
skills8Owned-skill CRUD, sharing for org/team
connectors4List, connect, disconnect workspace connectors

82+ procedures total across 10 routers, all type-safe end-to-end.

Production infrastructure, not a prototype.

21 tables, 82+ tRPC procedures, Redis caching, email delivery — all wired.

Buy now
© 2026 hourzero. All rights reserved.