Installation Guide
This guide provides comprehensive instructions for installing and configuring your ORPC + Better Auth application. Whether you’re setting up for local development or preparing for production, this guide covers everything you need.System Requirements
- Node.js: Version 20.0.0 or higher
- Package Manager: pnpm 9.15.4+ (recommended), npm, or yarn
- Operating System: macOS, Windows, or Linux
- Memory: At least 4GB RAM recommended
- Disk Space: ~500MB for dependencies
Package Manager Setup
This project uses pnpm as the package manager. While you can use npm or yarn, pnpm is recommended for its speed and efficiency.Installing pnpm
Project Setup
Clone the Repository
Clone the starter template to your local machine:
Replace
<repository-url> with the actual repository URL and my-app with your project name.Install Dependencies
Install all required packages:This installs all dependencies defined in
package.json:Core Dependencies:@orpc/[email protected]- ORPC server-side runtime@orpc/[email protected]- ORPC client for making type-safe calls@orpc/[email protected]- TanStack Query integration[email protected]- Authentication library[email protected]- Next.js framework[email protected]- React library[email protected]- TypeScript ORM@libsql/[email protected]- SQLite/Turso client[email protected]- Schema validation
[email protected]- Primitive UI components[email protected]- Tailwind utility function[email protected]- CSS variant management[email protected]- Icon library[email protected]- Theme management[email protected]- Toast notifications
@biomejs/[email protected]- Fast linter and formatter[email protected]- Drizzle ORM CLI toolstypescript@5- TypeScript compiler
Environment Configuration
Create your environment configuration file:The
.env.example file contains:.env.example
Environment Variables Explained
The base URL for your application. Used by:
- ORPC client for API calls (
/rpcendpoint) - Better Auth client for authentication requests
http://localhost:3000Production: Your deployed URL (e.g., https://myapp.com)Database connection string for Drizzle ORM.Local SQLite:
file:./local.dbTurso (production): libsql://[database-name].turso.io?authToken=[token]The Turso CLI (pnpm db:local) uses this to create a local database file.Secret key for encrypting sessions and tokens. Required for production.Generate a secure random string:
The base URL for Better Auth. Defaults to
NEXT_PUBLIC_SERVER_URL if not set.Only needed if your auth endpoint is on a different domain.Allowed origin for CORS requests. Used by Better Auth to validate request origins.Development: Usually not needed (defaults to
NEXT_PUBLIC_SERVER_URL)Production: Set to your frontend domain if different from APIDatabase Configuration
This project uses Drizzle ORM with SQLite/Turso for the database. Two options are available:Option 1: Local SQLite (Development)
Best for local development and testing.Start the Local Database
The Turso CLI provides a local SQLite server:This command:
- Creates a
local.dbfile in your project root - Starts a Turso-compatible local server
- Watches for schema changes
Keep this terminal running while you develop. The database server needs to be active for your application to work.
Push the Schema
Apply your database schema to create the tables:This creates tables for:
- Authentication:
user,session,account,verification - Application:
todo(example table)
src/db/schema/auth.ts- Better Auth tablessrc/db/schema/todo.ts- Application tables
Option 2: Turso (Production)
Recommended for production deployments.Get Connection Credentials
Retrieve your database URL and authentication token:Update your
.env file:Drizzle Configuration
The database configuration is indrizzle.config.ts:
drizzle.config.ts
Database Schema Files
Authentication Schema (src/db/schema/auth.ts):
Better Auth automatically creates these tables via Drizzle adapter:
user- User accountssession- Active sessionsaccount- OAuth accounts (if enabled)verification- Email verification tokens
src/db/schema/todo.ts):
Verification Steps
Before starting development, verify your installation:Check TypeScript
Run the type checker:You should see no errors. If you do, make sure all dependencies are installed correctly.
Verify Database Connection
Test the database connection by starting the dev server and checking for errors:Look for successful startup messages. No database connection errors should appear.
Available Scripts
Yourpackage.json includes these helpful scripts:
Script Descriptions
Start the development server with Turbopack on port 3000Hot reload: Automatically reloads on file changesType updates: ORPC types update instantly when you change procedures
Create an optimized production buildRun this before deploying to verify there are no build errors
Start the production server (after building)Use this to test the production build locally
Run Biome linter and TypeScript type checkerChecks for code quality issues and type errors
Format code with BiomeAutomatically fixes formatting issues
Start local SQLite database serverKeep this running in a separate terminal during development
Push schema changes to databaseUse this to apply schema changes without creating migration files
Open Drizzle StudioVisual database browser and query tool
Generate migration filesCreates SQL migration files from schema changes
Run migrationsApplies migration files to the database
Troubleshooting
pnpm install fails
pnpm install fails
Solution 1: Clear pnpm cacheSolution 2: Delete lock file and node_modulesSolution 3: Check Node.js version
Database connection errors
Database connection errors
Make sure:
- The
db:localcommand is running DATABASE_URLin.envis correct- You have write permissions in the project directory
- No other process is using the database file
Type errors in editor
Type errors in editor
- Restart your TypeScript server (VS Code: Cmd+Shift+P → “TypeScript: Restart TS Server”)
- Make sure
src/routers/index.tsexportsAppRoutertype - Check that ORPC client imports match your router structure
- Run
pnpm typecheckto see all type errors
Port already in use
Port already in use
Change the port in Update
package.json:.env:Biome formatting conflicts with other formatters
Biome formatting conflicts with other formatters
Disable other formatters (Prettier, ESLint) in your editor settings.For VS Code, add to
.vscode/settings.json:Next Steps
Your installation is complete! Here’s what to do next:Quickstart
Follow the quickstart guide to build your first feature
Core Concepts
Learn how ORPC and Better Auth work
Database Setup
Set up your database with Drizzle and Turso
API Reference
Explore available procedures and types