How intergalacticspacehighway/expo-trpc works
Project type and purpose
• This is a full-stack, monorepo-managed Expo application (iOS/Android/Web) integrated with tRPC for type-safe API calls.
• The “apps/expo” folder hosts the universal frontend and serverless API routes.
• The “packages/trpc-server” folder contains your shared tRPC routers and procedures.
File structure
• Top-level “apps/expo”: your Expo app (React Native + Expo Router), with an API route at app/api/trpc/[trpc]+api.ts.
• “packages/trpc-server”: defines and exports the tRPC router logic that the Expo API route imports.
• “packages/typescript-config” & “packages/eslint-config”: shared configs, not runtime components.
• “turbo.json”: orchestrates builds across apps and packages.
README insights
• The Expo app uses @tanstack/react-query + a tRPC client helper in utils/trpc.ts to query the API routes.
Main components and their interactions
a. Frontend (Expo React Native / Web)
• UI layers in apps/expo/app/index.tsx
• Uses React Query + tRPC client (utils/trpc.ts)
b. API Layer (Expo Router serverless function)
• Endpoint at /api/trpc/[trpc]+api.ts
• Imports createContext and the combined router from packages/trpc-server/trpc.ts
c. tRPC-Server Package
• Houses your procedures & routers in packages/trpc-server/routers/_app.ts
• Exports a ready-to-use tRPC router instance
d. (Optional future) Database or External Services
Relationships & data flow
1. User action in Expo UI
2. React Query + tRPC client dispatches an HTTP request to /api/trpc/<procedureName>
3. Expo Router invokes the serverless handler at [trpc]+api.ts
4. Handler calls into the shared tRPC router from packages/trpc-server
5. tRPC procedure executes business logic (and possibly calls a database or other services)
6. Result bubbles back through the serverless function to the client
Architectural patterns & design principles
• Monorepo with Turborepo for unified builds
• Code-sharing between frontend and server via tRPC and shared TypeScript configs
• Zero-API-schema-duplication: types flow end-to-end
• Serverless functions as the backend (Expo Router)