Skip to content

Quick Reference

A fast lookup table of the utilities, hooks, and helpers already in this codebase - check here before writing a new one. Each entry links to the file that defines it; follow the links in the other docs pages for the full explanation.

Auth & access guards

Server-side (Server Components, Server Actions) - src/lib/auth-utils.ts:

ExportWhat it does
requireAuth()Redirects to /login if there's no session; otherwise returns the session.
requireAuthAndPremium(redirectUrl?)Like requireAuth, plus redirects if the user has no active Polar subscription. Skipped when Polar isn't configured.
requireUnauth()Redirects signed-in users away from auth-only pages (login, signup) back to /.
getSessionOnServer()Reads the session without redirecting; null when unauthenticated.
requirePremiumUserFromRequest(req)Route Handler variant of requireAuthAndPremium - throws a 401/403 Response instead of redirecting.

Client-side:

ExportWhereWhat it does
authClientsrc/lib/auth-client.tsBetter Auth React client - signIn, signOut, useSession, checkout, ...
useCurrentUser()src/features/user/hooks/use-user.tsCurrent user's profile (trpc.user.me).
useHasActiveSubscription()src/features/subscriptions/hooks/use-subscription.tsStandard client-side premium check; treats everyone as premium when Polar isn't configured. Use for UI gating only, not enforcement.
useSubscription()src/features/subscriptions/hooks/use-subscription.tsRaw Polar customer state. Prefer useHasActiveSubscription unless you need the raw data.

tRPC procedure builders (src/trpc/init.ts) - see Architecture:

ExportWhat it does
baseProcedurePublic, no auth.
protectedProcedureRequires a session, throws UNAUTHORIZED otherwise. Attaches ctx.auth.
premiumProcedureprotectedProcedure + active subscription check, throws FORBIDDEN otherwise. Attaches ctx.customer.

Backend clients & services

ExportWhereWhat it does
prisma (default export)src/lib/db.tsShared Prisma client. Always import this instead of new PrismaClient().
getRedis()src/lib/redis.tsShared Redis client, connects lazily on first call.
redis (default export)src/lib/redis.tsRaw client instance - may not be connected yet, prefer getRedis().
isPolarEnabled / polarClientsrc/lib/polar.tsWhether billing is configured, and the Polar SDK client (null if not). Check the flag before using the client.
isResendEnabled / resendClientsrc/lib/resend.tsWhether transactional email is configured, and the Resend client (null if not).
sendEmail({ to, subject, html })src/lib/mailer.tsSends via Resend, falls back to console-logging the email when Resend isn't configured.
resetPasswordEmailHtml(...) / verifyEmailHtml(...)src/lib/mailer.tsPre-built HTML templates for the two auth emails.
openrouter / AI_MODELsrc/lib/ai.tsShared Vercel AI SDK provider and default chat model id, for streamText/generateText.
getStreamContext()src/lib/stream-context.tsShared resumable-stream context for resumable AI chat responses.

tRPC (data fetching)

ExportWhereWhat it does
useTRPC()src/trpc/client.tsxClient components: get query/mutation options for useQuery/useMutation.
TRPCReactProvidersrc/trpc/client.tsxRoot client provider (tRPC + React Query + IndexedDB persistence). Mounted once in layout.tsx.
trpc (options proxy)src/trpc/server.tsxServer Components: build the same query options as useTRPC(), for use with prefetch.
callersrc/trpc/server.tsxDirect server-side procedure calls as plain async functions, no HTTP round-trip.
prefetch(queryOptions)src/trpc/server.tsxPrefetches a query into the request-scoped QueryClient from a Server Component.
HydrateClientsrc/trpc/server.tsxWrap a subtree that used prefetch so the client tree gets the already-fetched data.
makeQueryClient()src/trpc/query-client.tsFactory for a correctly-configured QueryClient. Used internally by both providers above - rarely called directly.

Full walkthrough: Data Fetching.

Config

ExportWhereWhat it does
envsrc/config/env.tsRuntime-validated env vars (Zod). Always import this instead of reading process.env directly.
PAGINATIONsrc/config/constants.tsShared pagination defaults/limits (DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE, ...).
APP_NAME / APP_DESCRIPTIONsrc/config/constants.tsApp-wide display name/description for titles, metadata, emails.

UI utilities

ExportWhereWhat it does
cn(...inputs)src/lib/utils.tsMerges Tailwind classes safely (resolves conflicts) via clsx + tailwind-merge. Use instead of string concatenation.
useIsMobile()src/hooks/use-mobile.tsLive viewport check below the 768px breakpoint. false during SSR - prefer CSS breakpoints unless you need a real JS conditional.
useUIStoresrc/stores/ui-store.tsZustand store for cross-cutting UI state (currently: sidebar collapsed/expanded).

Shared components

Non-ui/ components in src/components/ - see Frontend for the full ui/ primitive list.

ComponentWhat it does
ConfirmDialogStandard "Are you sure?" dialog for ordinary, low-stakes deletes. Never wire a delete straight to a click.
CriticalConfirmDialogDestructive/hard-to-reverse deletes - user must retype a confirmation string before confirming.
AppShellDashboard layout shell: sidebar + EmailVerificationBanner + content area. Wraps every (dashboard) page.
AppSidebarSidebar nav content rendered inside AppShell.
EmailVerificationBannerDismissible-by-verification banner shown while the signed-in user's email is unverified.
LanguageToggleLocale switcher (en/de); persists the choice via a cookie-writing Server Action.

Details on the four required UI states (loading/empty/error/content) and confirm-dialog wiring: Frontend.

See also

  • Architecture - full project structure, key files, request flow.
  • Features - the feature-module pattern and existing demo features (each demo's own hooks/components live under src/features/demo/* and aren't listed here).
  • Frontend - design system, UI states, i18n.
  • Environment Variables - what each env.* field means.