This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is an AI-powered React Native App Builder that generates React Native applications from natural language prompts. The app demonstrates:
- Real-time AI code generation using OpenAI GPT-5 Codex with streaming responses
- Dynamic code execution where generated React Native components are compiled and rendered at runtime
- InstantDB for authentication, real-time data sync, and as the backend for generated mini-apps
- Each user build gets its own InstantDB app instance created via the InstantDB Platform API
# Development
bun start # Start Expo development server
bun run android # Build and run on Android
bun run ios # Build and run on iOS
bun run web # Start web version
# Code quality
bun run lint # Run ESLint
# Project setup (first time only)
bunx expo prebuild # Generate native codeCreate a .env file with:
EXPO_PUBLIC_INSTANT_APP_ID=your-instant-app-id
INSTANT_APP_ADMIN_TOKEN=your-admin-token
INSTANT_ORG_ID=your-org-id
OPENAI_API_KEY=your-openai-api-keyNote: The main app uses EXPO_PUBLIC_ prefix for client-side variables (read via process.env.EXPO_PUBLIC_*), while server-side code uses unprefixed variables.
The schema defines three main entities:
$users: Authenticated users with emailbuilds: Generated apps linked to users viabuildOwnerrelationship. Each build has:instantAppId: ID of the InstantDB app created for this buildcode: Generated React Native codereasoning: AI's reasoning process (optional)isPreviewable: Whether the build is ready for previewtitle: User's prompt as the title
$files: File storage entity
There are two separate InstantDB clients:
-
lib/db.ts- Client-side database for React Native- Uses
@instantdb/react-native - Used in components with
db.useAuth(),db.useQuery() - For frontend data fetching and auth
- Uses
-
lib/adminDB.ts- Admin client for privileged operations- Uses
@instantdb/adminwith admin token - Used in API routes for server-side operations
- Can act as users via
adminDB.asUser({ email })
- Uses
File-based routing in /app directory:
index.tsx- Main app screen (protected, requires auth)login.tsx- Authentication screen (shown when not authenticated)_layout.tsx- Root layout with auth guards usingStack.Protectedbuild/[id].tsx- Dynamic route for individual buildsapi/generate+api.tsx- Server-side API endpoint for code generation
Protected routes use Stack.Protected guard={condition} - when user exists, shows index; when !user, shows login.
- User submits prompt →
POST /api/generate - API creates new InstantDB app via Platform API (
lib/platformAPI.ts) - Creates build record linked to user
- Streams response from GPT-5 Codex with both
text-delta(code) andreasoning-delta - Progressive saves build as code streams in (debounced via
triggerSave) - Sets
isPreviewable: truewhen complete
utils/codeStrToReactElement.ts is the core utility that:
- Takes generated code string and
instantAppId - Replaces placeholder
instantAppIdwith actual ID - Cleans code (finds import/export boundaries)
- Transpiles with Babel (JSX → JS, TypeScript, modules → CommonJS)
- Creates a custom
requirefunction providing React, React Native, and InstantDB - Executes the code in a sandboxed Function constructor
- Returns a React element that can be rendered
Important: This allows user-generated code to run in the app. The code only has access to react, react-native, and @instantdb/react-native modules.
InstantDB auth is managed through:
db.useAuth()hook for auth state (isLoading,user,error)db.auth.signOut()for logout- Token verification in API routes via
adminDB.auth.verifyToken(token) - Headers use
RefreshTokenkey to pass auth token to API
Components use db.useQuery() which automatically re-renders when data changes:
const { data } = db.useQuery({ builds: {} }, { isActive: true });The buildOwner relationship allows querying builds linked to the current user.
- InstantDB transactions: Use
db.tx.builds[id].create().link()to create entities with relationships - Acting as users: Server-side operations use
adminDB.asUser({ email })to maintain user context - Streaming AI: Use
for await (const chunk of fullStream)to handle text and reasoning deltas - Expo Router: All routes in
/appwith file-based naming; dynamic routes use[param].tsx - Platform API:
lib/platformAPI.tswraps the InstantDB Platform API for programmatic app management
- The app uses Bun as the package manager (npm-compatible)
- TypeScript is enabled with strict mode
- React 19.1.0 with React Native 0.81.5
- Polyfills loaded in
utils/polyfills.tsfor web compatibility - System prompt for AI is in
resources/systemPrompt.txtloaded viautils/systemPrompt.ts