What You’ll Build
A fully functional todo app with:- Create, read, update, and delete operations
- Realtime synchronization across tabs and devices
- Type-safe client code
- Authentication (optional)
Prerequisites
- TrailBase installed (installation guide)
- Node.js and npm/pnpm (for the frontend)
- Basic knowledge of TypeScript/JavaScript
Step 1: Initialize Your Project
Create a new directory and initialize TrailBase:traildepot/ directory containing:
data/- SQLite database filesmigrations/- Database migration filesconfig.textproto- API and auth configurationsecrets/- Secure credentials
On first run, TrailBase displays admin credentials in the terminal. Save these to access the admin dashboard at
http://localhost:4000/_/admin.Step 2: Create the Database Schema
Create a migration file for the todos table:traildepot/migrations/main/U1234567890__create_table_todos.sql. Edit it:
traildepot/migrations/main/U1234567890__create_table_todos.sql
Key Requirements:
- Tables must use
STRICTtyping - Primary key must be
INTEGERorBLOB(for UUIDv7) - Column names should be quoted to avoid SQL keyword conflicts
Step 3: Configure the Record API
Edittraildepot/config.textproto to expose the todos table as an API:
traildepot/config.textproto
Step 4: Generate Type Definitions
Generate TypeScript types from your schema:Todo type will include:
src/types/todo.ts
Step 5: Build the Frontend
Create a React component using the TrailBase client:- React
- Vue
src/App.tsx
Step 6: Add Realtime Updates
Subscribe to live changes to sync todos across tabs:src/App.tsx
Step 7: Test Your App
Start your development server:http://localhost:5173 and test:
- Add a todo in one tab
- Watch it appear in other tabs instantly
- Toggle completion status
- Delete todos
Step 8: Add Authentication (Optional)
Update your API configuration to require authentication:traildepot/config.textproto
traildepot/config.textproto
src/App.tsx
Next Steps
Database Setup
Learn advanced schema design patterns
Authentication
Implement OAuth and password auth
Realtime Subscriptions
Master WebSocket subscriptions
File Uploads
Handle file uploads and storage