# intergalacticspacehighway/expo-trpc architecture

> Architecture diagram of the GitHub repository intergalacticspacehighway/expo-trpc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/intergalacticspacehighway/expo-trpc
- Repository: https://github.com/intergalacticspacehighway/expo-trpc

## Overview

##### 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)

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Monorepo level
  subgraph "Monorepo"
    direction TB
    Turborepo("Turborepo (turbo.json)"):::config
    TSConfig("Shared TypeScript Config"):::config
    ESLintConfig("Shared ESLint Config"):::config
  end

  %% Client layer
  subgraph "Client (Expo App)" 
    direction TB
    ExpoApp("Expo App (UI Layer)"):::frontend
    TRPCClient("tRPC Client Helper"):::frontend
  end

  %% Serverless/API layer
  subgraph "Serverless API (Expo Router)"
    direction TB
    APIEndpoint("Serverless API Layer\n(app/api/trpc/[trpc]+api.ts)"):::api
  end

  %% tRPC server package
  subgraph "tRPC Server Package"
    direction TB
    TRPCRouters("tRPC Routers & Procedures\n(routers/_app.ts)"):::package
    TRPCSetup("Router Exporter & Context\n(trpc.ts)"):::package
  end

  %% Optional datastore
  DB("Database / External Service"):::datastore

  %% Relationships
  ExpoApp -->|"uses"| TRPCClient
  TRPCClient -->|"HTTP/JSON"| APIEndpoint
  APIEndpoint -->|"invokes handler"| TRPCSetup
  TRPCSetup -->|"uses routers"| TRPCRouters
  TRPCRouters -->|"calls"| DB
  DB -->|"data"| TRPCRouters
  TRPCRouters -->|"result"| TRPCSetup
  TRPCSetup -->|"HTTP Response"| TRPCClient
  TRPCClient -->|"updates UI"| ExpoApp

  %% Build orchestration links
  Turborepo --> ExpoApp
  Turborepo --> APIEndpoint
  Turborepo --> TRPCRouters
  TSConfig --> ExpoApp
  TSConfig --> TRPCRouters
  ESLintConfig --> ExpoApp
  ESLintConfig --> TRPCRouters

  %% Click Events
  click ExpoApp "https://github.com/intergalacticspacehighway/expo-trpc/blob/main/apps/expo/app/index.tsx"
  click TRPCClient "https://github.com/intergalacticspacehighway/expo-trpc/blob/main/apps/expo/utils/trpc.ts"
  click APIEndpoint "https://github.com/intergalacticspacehighway/expo-trpc/blob/main/apps/expo/app/api/trpc/[trpc]+api.ts"
  click TRPCRouters "https://github.com/intergalacticspacehighway/expo-trpc/blob/main/packages/trpc-server/routers/_app.ts"
  click TRPCSetup "https://github.com/intergalacticspacehighway/expo-trpc/blob/main/packages/trpc-server/trpc.ts"
  click Turborepo "https://github.com/intergalacticspacehighway/expo-trpc/blob/main/turbo.json"
  click TSConfig "https://github.com/intergalacticspacehighway/expo-trpc/tree/main/packages/typescript-config"
  click ESLintConfig "https://github.com/intergalacticspacehighway/expo-trpc/tree/main/packages/eslint-config"

  %% Styles
  classDef frontend fill:#ADD8E6,stroke:#000;
  classDef api fill:#90EE90,stroke:#000;
  classDef package fill:#FFA500,stroke:#000;
  classDef config fill:#D3D3D3,stroke:#000;
  classDef datastore fill:#C0C0C0,stroke:#000;
```
