How dabit3/react-native-ai works
1. This repo is a three-part monorepo: an Expo/React Native mobile app in app/, a TypeScript backend in server/, and a small Node CLI in cli/. The architecture is intentionally split so the mobile client stays UI-focused while the server owns API keys, provider integration, and file handling.
2. The mobile app is the primary user-facing surface. It is an Expo-based React Native project with native iOS/Android shells, shared TypeScript source, and bundled assets/fonts. Entry points are app/index.js and app/App.tsx, with the app rendering from src/main.tsx.
3. The app UI is organized around a few screens in app/src/screens: chat.tsx for text/assistant chat, images.tsx for image generation, assistant.tsx for assistant-style flows, and settings.tsx for runtime configuration. Shared UI pieces live in app/src/components, including model-specific icons and a model picker modal.
4. App-wide state and behavior are centralized in app/src/context.tsx, app/src/theme.ts, app/constants.ts, and app/src/utils.ts. These files govern selected model, theme selection, and mapping between user choices and backend routes, which is important for the architecture because the app does not hardcode provider logic into the screens themselves.
5. The mobile app is designed to support multiple LLM providers rather than a single backend. The README and component set show explicit support for OpenAI, Anthropic, Gemini, Cohere, and Mistral-branded UI affordances, with streaming/real-time response handling as a core interaction pattern.
6. The backend in server/src is the provider proxy and orchestration layer. It is split by capability into chat/, images/, and files/, with routers such as chatRouter.ts, imagesRouter.ts, and fileRouter.ts acting as the external API boundary consumed by the mobile app.
7. Chat is the most structured backend subsystem. The server/src/chat folder contains provider adapters (gpt.ts, claude.ts, cohere.ts, gemini.ts) plus orchestration helpers like createAssistant.ts, addMessageToThread.ts, getThreadMessages.ts, runResponse.ts, and runStatus.ts. This suggests a thread/run model for assistant-style conversations with streaming status updates back to the app.
8. Image generation is handled separately from chat, with server/src/images/gemini.ts implementing Gemini-based image generation and imagesRouter.ts exposing it. The README indicates this path also supports natural-language-to-image workflows and image input handling from the app’s image screen.
9. File uploads are a distinct backend boundary. server/src/files/upload-file.ts and helpers/saveFileToOpenai.ts indicate the server accepts uploads, stores them locally under server/uploads/, and can forward them to OpenAI-compatible storage when needed. This keeps file credentials and transport logic off the device.
10. The backend is environment-driven. Both app/.env.example and server/.env.example show that runtime configuration is externalized, with the server specifically requiring provider keys such as GEMINI_API_KEY. The repo’s architecture assumes the server is the trusted layer for secrets and provider access, while the app talks to it over HTTP.
11. The CLI in cli/ is a project bootstrap/configuration tool rather than an app runtime. The README shows it is invoked with npx rn-ai to generate a new project and set up environment configuration, making it part of the developer experience and not the production runtime path.
12. Native platform files under app/ios and app/android are mostly generated shells around the React Native runtime. They matter architecturally only insofar as they provide the deployment targets for the shared app code and host the app icons, splash screens, and platform manifests.
Main entry points: main.tsx Main UI · screens Screens · index.ts Server entry · components Shared UI
Components 25
Mobile app
Expo/React Native client and native shells.
- App entry · Loads the React Native application entrypoints.
app/index.js - Root app · Top-level app component wired into Expo.
app/App.tsx - Main UI · Bootstraps navigation and shared UI state.
app/src/main.tsx - App state · Holds selected model, runtime config, and cross-screen behavior.
app/src/context.tsx - Theme · Defines visual theme and styling primitives.
app/src/theme.ts - App utils · Maps user choices to backend routes and helper behavior.
app/src/utils.ts - Shared UI · Reusable components including model icons, header, and modal UI.
app/src/components - Screens · Primary user-facing app screens.
app/src/screens - Chat · Text and assistant conversation UI.
app/src/screens/chat.tsx - Images · Image generation and image input flows.
app/src/screens/images.tsx - Assistant · Assistant-style interaction flows.
app/src/screens/assistant.tsx - Settings · Runtime configuration and client settings.
app/src/screens/settings.tsx - iOS shell · Generated iOS host for the shared React Native app.
app/ios - Android shell · Generated Android host for the shared React Native app.
app/android
Backend
TypeScript provider proxy and orchestration API.
- Server entry · Starts the backend API service.
server/src/index.ts - Chat API · External boundary for chat and assistant requests.
server/src/chat/chatRouter.ts - Chat core · Manages threads, runs, and streaming response lifecycle.
server/src/chat - Providers · Provider-specific chat adapters for OpenAI, Anthropic, Cohere, and Gemini.
server/src/chat - Images API · External boundary for image generation requests.
server/src/images/imagesRouter.ts - Image gen · Gemini-based image generation implementation.
server/src/images/gemini.ts - Files API · External boundary for file upload handling.
server/src/files/fileRouter.ts - File upload · Accepts uploads and stores them for later provider use.
server/src/files/upload-file.ts - OpenAI save · Saves files into OpenAI-compatible storage when needed.
server/src/helpers/saveFileToOpenai.ts
CLI
Project bootstrap and setup tool.
- CLI · Project generation and setup command for new installs.
cli/cli.js
Other components
- react-native-ai · Three-part repo: mobile app, backend, and CLI.
Connections 31
- react-native-ai → App entry: contains · Repository includes the mobile runtime entrypoint.
- react-native-ai → Server entry: contains · Repository includes the backend runtime entrypoint.
- react-native-ai → CLI: contains · Repository includes the developer bootstrap CLI.
- App entry → Root app: boots · Expo entry loads the app shell.
- Root app → Main UI: renders · Top-level app component delegates to main UI composition.
- Main UI → App state: uses · Main UI reads and updates shared client state.
- Main UI → Theme: styles · Main UI applies shared theme primitives.
- Main UI → App utils: maps · Main UI relies on route and model mapping helpers.
- Main UI → Shared UI: composes · Main UI uses shared presentational components.
- Main UI → Screens: navigates · Main UI routes to the primary screen set.
- Screens → Chat: includes · Chat screen is a primary app surface.
- Screens → Images: includes · Images screen is a primary app surface.
- Screens → Assistant: includes · Assistant screen is a primary app surface.
- Screens → Settings: includes · Settings screen configures runtime behavior.
- Shared UI → Chat: supports · Shared UI provides controls used by chat flows.
- Shared UI → Images: supports · Shared UI provides controls used by image flows.
- Shared UI → App state: reads · Components reflect selected model and state.
- Settings → App state: updates · Settings screen changes runtime configuration.
- Chat → Chat API: calls · Chat UI sends requests to the backend chat API.
- Images → Images API: calls · Image UI sends requests to the backend image API.
- Assistant → Chat API: calls · Assistant flows use the chat API for threaded interactions.
- Settings → Server entry: configures · Runtime settings point the client at the backend service.
- Server entry → Chat API: mounts · Backend entry exposes chat routes.
- Server entry → Images API: mounts · Backend entry exposes image routes.
- Server entry → Files API: mounts · Backend entry exposes file routes.
- Chat API → Chat core: orchestrates · Chat API delegates to thread and run management.
- Chat core → Providers: adapts · Core orchestration calls provider-specific implementations.
- Images API → Image gen: delegates · Image API routes into Gemini-based generation logic.
- Files API → File upload: handles · Files API accepts uploads through the upload flow.
- File upload → OpenAI save: stores · Upload flow can persist to OpenAI-compatible storage.
- File upload → Chat core: feeds · Uploaded files can be used by chat and assistant flows.