Introduction
Budgetron uses oRPC to provide a fully type-safe API layer between the client and server. oRPC enables end-to-end type safety from your database to your UI components, catching errors at compile time rather than runtime.Architecture
oRPC Foundation
The API architecture is built on three key components:- Router Definition - Centralized router that combines all feature routers
- Procedures - Type-safe endpoints with input validation using Zod schemas
- Context - Request context including authentication session
API Structure
All API routes are defined insrc/server/api/router.ts:
Available Routers
Authentication (auth)
Handles user authentication and session management:
signIn- Email/password authenticationsignUp- User registrationsignInWithSocial- Social provider authentication (Google)signInWithOAuth- Custom OAuth provider authenticationsignOut- End user sessionsession- Get current sessionforgotPassword- Request password resetresetPassword- Reset password with token
Transactions (transactions)
Manage financial transactions:
create- Create a single transactioncreateMany- Bulk create transactionsupdate- Update transaction detailsdelete- Delete a transactiondeleteMany- Bulk delete transactionsgetByDateRange- Fetch transactions within date rangegetByCategory- Fetch transactions by categoryparseOFX- Parse and import OFX bank files
Budgets (budgets)
Manage budget tracking:
create- Create a new budgetupdate- Update budget detailsdelete- Delete a budgetsummary- Get all budgets summarydetails- Get detailed budget information
Bank Accounts (bankAccounts)
Manage user bank accounts:
create- Add a new bank accountupdate- Update account detailsdelete- Remove a bank accountgetAll- List all bank accounts
Categories (categories)
Manage transaction categories:
getAll- Get all categoriesgetAllSubCategories- Get all subcategories
Analytics (analytics)
Generate financial reports and insights:
getDashboardSummary- Get dashboard overview datagetCashFlowReport- Generate cash flow analysisgetCategorySpend- Analyze spending by categorygetCategoryIncome- Analyze income by category
User (user)
Manage user profile and accounts:
listAccounts- List connected accounts
AI (ai)
AI-powered features for financial insights.
Making API Calls
Server-Side (React Server Components)
Use the server RPC client to call procedures directly as functions:Client-Side (React Query)
Use the client RPC with React Query for data fetching:Client-Side (Mutations)
Use mutations for data modifications:Type Safety
Input Types
Infer input types from the router:Output Types
Infer output types from the router:Request/Response Format
Standard Request
All procedures accept an input object validated by Zod schemas:Standard Response
Procedures return typed data directly:Error Response
Errors are thrown asORPCError with standardized codes:
UNAUTHORIZED- Authentication required or invalid credentialsFORBIDDEN- Insufficient permissionsBAD_REQUEST- Invalid input dataNOT_FOUND- Resource not foundINTERNAL_SERVER_ERROR- Server error
Middleware
Authorization Middleware
Protected procedures automatically verify authentication:Timing Middleware
Logs execution time and adds artificial delay in development:Batching
The client automatically batches multiple requests into a single HTTP call:Example: Complete Procedure
Here’s a complete example of a protected procedure:Next Steps
- Authentication - Learn about BetterAuth integration
- Contributing - Add new API endpoints