Architecture Diagram
Core Architecture Principles
Serverless Backend
Convex handles all backend logic without managing servers. Queries and mutations are defined as TypeScript functions that run in Convex’s cloud.
Real-time Sync
Convex automatically keeps all connected clients in sync. When data changes, all subscribed components re-render instantly.
File-based Routing
Expo Router uses the app/ directory structure to define routes. Folder names in parentheses create layout groups.
Type-safe API
Convex generates TypeScript types from your schema, providing end-to-end type safety from database to UI.
Authentication Flow
The app uses Clerk for authentication, integrated with Convex for backend authorization:- User signs in via Clerk (OAuth or email)
- Clerk issues JWT with user identity
- Mobile app receives token stored in secure storage
- Convex validates JWT on every request via
auth.config.ts - Backend functions access user via
ctx.auth.getUserIdentity() - Webhooks sync user data from Clerk to Convex database
The integration happens in
app/_layout.tsx where ClerkProvider wraps ConvexProviderWithClerk, enabling automatic token passing to all Convex requests.Data Flow Pattern
Query Flow (Read)
Mutation Flow (Write)
Protected Routes
The app uses Expo Router’sStack.Protected component to guard authenticated routes:
(auth) group.
Key Integration Points
Convex Client Initialization
Location:lib/convex-client.ts
Clerk Authentication Config
Location:convex/auth.config.ts
Root Provider Setup
Location:app/_layout.tsx
The root layout wraps the entire app with:
ClerkProvider- Authentication stateConvexProviderWithClerk- Backend connectivity + authThemeProvider- Navigation themingPortalHost- Modal/dialog rendering
Development Workflow
When you runbun dev, two processes start simultaneously:
-
Expo development server (
bun start)- Serves the mobile app
- Enables hot reload
- Provides QR code for device testing
-
Convex development deployment (
bun convex:dev)- Deploys backend functions
- Watches for file changes
- Provides real-time logs
Both processes run in parallel using
mprocs, allowing you to see mobile and backend logs side-by-side.Storage Architecture
Quest Hunter uses multiple storage mechanisms:| Type | Technology | Use Case |
|---|---|---|
| Database | Convex Tables | Quests, users, locations, progress |
| File Storage | Convex Storage | User photos from completed locations |
| Secure Storage | Expo SecureStore | Clerk authentication tokens |
| Cache | Convex Client | Optimistic updates, query results |
Next Steps
Tech Stack Details
Learn about specific technology choices and why they were selected
Project Structure
Explore the directory organization and file conventions