Architecture
Uxie uses tRPC to provide end-to-end typesafe APIs. The API is built on top of Next.js API routes and uses Prisma as the ORM layer to interact with a PostgreSQL database.What is tRPC?
tRPC allows you to easily build & consume fully typesafe APIs without schemas or code generation. It leverages TypeScript’s inference to provide autocompletion and type safety across your entire stack.API Routers
The Uxie API is organized into the following routers:- document - Document management, collaboration, and vectorization
- user - User profile and document listing
- highlight - Text and image highlighting within documents
- message - Chat messages for AI conversations about documents
- flashcard - Flashcard generation and retrieval for studying
Making API Calls
Client Setup
The tRPC client is configured in/src/lib/api.ts and uses React Query hooks for data fetching:
Queries vs Mutations
Queries are for reading data:Request Context
Every tRPC procedure has access to a context object that includes:The authenticated user’s session (null if not authenticated)
The Prisma client for database operations
Session Object
When authenticated, the session includes:Error Handling
All API procedures can throwTRPCError with appropriate error codes:
Data Transformers
Uxie uses SuperJSON to serialize/deserialize data, which allows you to send Date objects, Sets, Maps, and more over the wire:Type Safety
Import types from your router for full type safety:Next Steps
Authentication
Learn about authentication and protected procedures
Document API
Manage documents, collaborators, and vectorization
Highlight API
Add and manage highlights in documents
Flashcard API
Generate and retrieve flashcards for studying
