How robodev mobile works

The same src/pages that build the web app run as a native iOS and Android app. This walks through what the command does on your Mac, what runs on the phone, and what's still missing. All code is from the local branch (packages/cli/src/mobile*.ts and packages/app/src/native*.tsx).

Overview

One command, about 4 seconds

$ robodev mobile
Mobile routes: 14 files in mobile/app (from src/pages)
Metro     http://127.0.0.1:19437
App       http://127.0.0.1:18437  (Metro + API through one port)
API       http://localhost:4000
Running   on iPhone 17 Pro (4.1 s). Edit src/pages and it reloads; Ctrl-C stops.

Example output; ports, file count and time vary. It assumes robodev dev is already running in another terminal (the backend on port 4000). Then, in order:

  1. Scaffold mobile/ on the first run: an Expo project.
  2. Mirror routes: regenerate mobile/app/** from src/pages/**, and src/api.gen.ts from robodev/api/**.
  3. Start Metro, React Native's bundler, on a free port for this project.
  4. Start a one-port proxy in front of Metro and the API.
  5. Open the device: boot a simulator or emulator, install Expo Go if needed, open the app URL.
  6. Wait until the app runs and print "Running". Optionally stream its console.
flowchart LR
  subgraph mac["Your Mac"]
    pages["src/pages/**"] -->|generateExpoRoutes| app["mobile/app/** (generated)"]
    api["robodev/api/**"] -->|writeApiHooks| gen["src/api.gen.ts"]
    app --> metro["Metro :19xxx"]
    gen --> metro
    dev["robodev dev :4000
(API, sockets, Postgres)"] proxy["proxy :18xxx
one origin"] metro --- proxy dev --- proxy end proxy -->|"exp://127.0.0.1:18xxx"| sim["iOS Simulator
Expo Go"] proxy -->|"adb reverse"| emu["Android emulator
Expo Go"] proxy -->|"--tunnel https"| phone["Real phone
Expo Go"]
Step 1 · Scaffold (first run only)

A small Expo project in mobile/

If mobile/package.json doesn't exist, the CLI writes one and installs Expo. Nothing in here is meant to be edited by hand.

FileWhat it is
package.jsonExpo SDK 58, React 19.3, React Native 0.88. Main entry is expo-router/entry.
app.jsonName, URL scheme, bundle ids (dev.robodev.<name>), the expo-router plugin.
metro.config.jsRewritten every run. Lets Metro build ../src (step 3).
tsconfig.jsonPlain, because Metro reads its paths.
tsconfig.check.jsonRewritten every run. For typechecking the screens the way Metro bundles them.
.gitignorenode_modules/ .expo/ app/ ios/ android/. The generated routes are never committed.

Install is npm install then npx expo install expo-router expo-linking expo-constants expo-status-bar react-native-safe-area-context react-native-screens @react-native-async-storage/async-storage, so Expo picks versions that match the SDK.

Step 2 · Mirror the routes

src/pages becomes Expo Router's app/

Expo Router uses the same file conventions as our pages: [id], [...rest], _layout, (group). So each page gets a generated file of two lines that points back at the real page. The page stays the only source.

src/pages/ (you write)
_layout.tsx
index.tsx
login.tsx
todos/index.tsx
todos/[id].tsx
board/[id].tsx
board/[id].native.tsx
mobile/app/ (generated, wiped each run)
_layout.tsx        ← rootLayout(app, Layout)
index.tsx          ← screen(page, "index.tsx")
login.tsx
todos/index.tsx
todos/[id].tsx
board/[id].tsx     ← one file; Metro picks .native
+not-found.tsx     ← built in if you have no 404
mobile/app/todos/[id].tsx
// Generated by `robodev mobile` from src/pages. Do not edit; edit the page instead.
import { screen } from "@robodev-ai/app/native";
import * as page from "../../../src/pages/todos/[id]";
export default screen(page, "todos/[id].tsx");
mobile/app/_layout.tsx
import { rootLayout } from "@robodev-ai/app/native";
import app from "../../src/app";
import Layout from "../../src/pages/_layout";
export default rootLayout(app, Layout);
Step 3 · Metro config

Build ../src with one copy of React

Metro normally only builds files inside its own project. Our pages live one folder up, and the web app has its own React in the project's node_modules. Two copies of React in one bundle breaks hooks, so the generated config does three things:

mobile/metro.config.js (generated)
config.watchFolders = [path.join(projectRoot, "src"), appPkg, clientPkg];  // 1. see ../src

const ROBODEV_ENTRIES = {                                             // 2. the native build
  "@robodev-ai/app": appNative,            // → packages/app/src/native.ts
  "@robodev-ai/app/native": appNative,
  "@robodev-ai/client": path.join(clientPkg, "src", "index.ts"),
};

config.resolver.resolveRequest = (context, moduleName, platform) => {
  const entry = ROBODEV_ENTRIES[moduleName];
  if (entry) return { type: "sourceFile", filePath: entry };
  // 3. a bare import from ../src (react, expo-router, …) resolves from mobile/node_modules
  if (isBare(moduleName) && !inside(context.originModulePath)) {
    return context.resolveRequest(
      { ...context, originModulePath: path.join(mobileRoot, "package.json") }, moduleName, platform);
  }
  return context.resolveRequest(context, moduleName, platform);
};
Why it matters

A page writes import { Button, Stack, useNavigate } from "@robodev-ai/app". On the web that's the DOM kit. On the phone, rule 2 swaps in native.ts, which exports the same names built on React Native. That's what lets one page file run on both.

Step 4 · One-port proxy

Bundle and API on the same origin

The app needs to reach two servers: Metro (bundle, assets, hot reload, debugger) and robodev dev (API, sockets). Instead of telling the app two URLs, the CLI starts a small proxy and sends everything through one port:

packages/cli/src/mobile-proxy.ts
const API_PREFIXES = ["/api/", "/api?", "/sockets/", "/_robodev/", "/.well-known/"];
const upstreamFor = (path) => (isApiPath(path) ? input.api : input.metro);

// HTTP: pipe the request to the right upstream.
// WebSockets (Metro /hot, /message, /inspector/*; Robodev /sockets/*): replay the upgrade
// request upstream and splice the two TCP connections together.
server.on("upgrade", (req, socket, head) => { ... upstream.pipe(socket); socket.pipe(upstream); });
Needs Bun 1.4 or newer.

Bun 1.3's node:http server never fires the upgrade event. HTTP works, but every WebSocket dies: no live sync, no hot reload, no --logs. The CLI prints a warning on 1.3.

Step 5 · Open the device

simctl on iOS, adb on Android, no IDE

The app runs inside Expo Go, a prebuilt app that loads a JavaScript bundle from a URL. So there is no Xcode build and no Gradle build. The CLI just makes sure the right Expo Go is installed and opens the URL.

StepiOS (mobile-ios.ts)Android (mobile-android.ts)
Pick devicesimctl list, newest iPhone runtime, or --devicefirst online adb devices, or boot an AVD (creates one if none)
Bootsimctl bootstatus -b (returns when usable)emulator -avd …, wait for sys.boot_completed=1
Windowopen -a Simulator, skipped with --headless-no-window -gpu swiftshader_indirect with --headless
Reach the Macshares the Mac's network, nothing to doadb reverse tcp:PORT tcp:PORT
Expo GoAsk Metro which SDK it serves, look up the matching Expo Go build on api.expo.dev (cached in ~/.expo for offline), download once, install if the version differs
Skip promptspre-approve exp:// and exps:// in the device's scheme-approval plistopen with an explicit package: am start -p host.exp.exponent
Opensimctl terminate, then simctl openurlam force-stop, wait for the process to exit, then am start -d exp://…

The URL includes __expo_disable_fab=1&__expo_disable_onboarding=1 so Expo Go's onboarding sheet and floating dev button stay out of the way, the same as Expo's own CLI does.

Step 6 · Ready signal and logs

Knowing the app is actually running

Before opening the app, the CLI notes the JS runtimes Metro's debugger knows about (GET /json/list). After opening it, it polls every 100 ms until a new one appears. A new runtime means the bundle has loaded and React Native is executing it. That's when it prints "Running … (4.1 s)".

packages/cli/src/mobile-shared.ts → streamConsole (with --logs)
// Expo Go's JS console never reaches the simulator's system log, so read it over the
// Chrome DevTools Protocol, through Metro's inspector proxy.
const ws = new WebSocket(target.webSocketDebuggerUrl, { headers: { Origin: origin } });
ws.onopen = () => ws.send(JSON.stringify({ id: 1, method: "Runtime.enable" }));
ws.onmessage = (event) => {
  if (msg.method !== "Runtime.consoleAPICalled") return;
  print(`[app ${msg.params.type}] ${text}`);   // [app error] TypeError: …
};

This works the same on iOS and Android, and it's what makes the command usable by an agent: a clear ready line, then the app's errors as plain text.

On the phone

What @robodev-ai/app/native does at runtime

rootLayout()

  • Makes the API client once: createClient({ url, storage: AsyncStorage }), so the session survives app restarts.
  • Wraps everything in RobodevProvider (auth, data cache), the theme from defineApp({ theme }) resolved for light/dark, and a safe-area view.
  • Renders your src/pages/_layout.tsx around an Expo Router native stack with headers off, so the app's own layout draws the chrome.
  • Back swipe from the left edge only. iOS 26's full-screen back swipe would steal drags from canvases like the diagram board.

screen(page, file)

  • Reads the module's default export plus auth and title, same as the web (pageFromModule).
  • auth = "required" and signed out: <Redirect href="/login?next=…">. "guest" and signed in: redirect to next or afterSignIn.
  • Splits Expo Router's params into params (names from the file, like [id]) and search (the rest), then renders <Page params search />, the same props as on the web.
Page usesWebPhone
Stack, Text, Button, Input, Card…DOM elements + CSSView, Text, Pressable, TextInput with theme styles (native-ui.tsx)
Link to="/todos"router linkExpo Router Link
useNavigate()web historyrouter.push / replace / back, same signature
useGetTodos()fetch, same-origin cookiefetch to the proxy host, token in AsyncStorage
useSocket()WebSocketWebSocket through the proxy
className, DOM propsappliedaccepted and ignored
Platform files and typechecking

Write a phone version only where it matters

Most pages run unchanged. When a screen needs native APIs or a different layout, add a sibling file; the web bundle ignores .native/.ios/.android files and Metro prefers them.

board/[id].tsx          web: SVG canvas, mouse, keyboard shortcuts
board/[id].native.tsx   phone: touch drawing, pinch zoom, react-native-view-shot thumbnails
_layout.native.tsx      phone: account sheet instead of a dropdown menu

The Diagrams port has five .native files: _layout, index, auth, diagrams and the _board-list helper, plus the board screens. Everything else, including all API hooks, is shared.

npx tsc -p mobile/tsconfig.check.json

That config typechecks the screens the way Metro bundles them: moduleSuffixes: [".ios", ".native", ""], @robodev-ai/app mapped to native.ts, and React and React Native types from mobile/node_modules. It's a separate file because putting those paths in tsconfig.json made Metro resolve react to its type package and fail to bundle.

Editing while it runs

Fast Refresh keeps state

Save a page and Metro sends the changed module over its /hot socket (through the proxy). React Fast Refresh swaps it in place. One catch: a module that exports auth or title next to its component isn't a refresh boundary on its own, so the edit re-runs the generated route file, which calls screen() again. To keep state, screen() remembers one wrapper per file:

packages/app/src/native-app.tsx
const screens = new Map<string, { page: PageDefinition; Screen: () => ReactNode }>();

export function screen(pageModule: PageModule, file: string) {
  const known = screens.get(file);
  if (known) {
    known.page = pageFromModule(pageModule, file);  // new component inside
    return known.Screen;                            // same wrapper → no remount
  }
  ...
}
Real phones

LAN or tunnel, scan a QR code

--lan

The proxy listens on 0.0.0.0. The CLI prints exp://192.168.x.x:18xxx and a QR code. Same Wi-Fi only, and some office networks block it.

--tunnel

The proxy port goes out through Starbase's tunnel as https://<random id>.<tunnel host>. The app opens with exps://. Works from any network, public while the command runs, and the id is remembered per project so the QR code stays the same.

Scan with the iPhone camera or Expo Go on Android. Because the API goes through the same port, the phone talks to your local backend with no extra setup.

Agents

Built to be driven by a machine

robodev mobile --ios --headless --logs
Firecracker microVMs can't run the simulators themselves.

The iOS Simulator needs macOS, and the Android emulator needs KVM, which a microVM usually doesn't expose. The design that works: the app (Metro, proxy, backend) runs in the agent's VM with --tunnel, and a separate device host (a Mac for iOS, a Linux box with KVM for Android) opens the tunnel URL. The agent drives the device host over an API and reads screenshots and logs back.

Limits and open work

What isn't solved yet

Blocked by a decision

Data layer uses useSyncExternalStore

native.ts re-exports useApi/useMutation from the shared data.ts, which Urban has ruled out. Option: give mobile its own small store on useState/useEffect behind the same hook names until the web design is settled. No page code changes either way.

Not built

App Store / Play Store builds

Everything runs inside Expo Go, which is a development app. Shipping a real app needs a native build (Expo prebuild or EAS Build), signing, icons and store metadata. app.json already has bundle ids, but no build step exists.

Limit of Expo Go

Only native modules Expo Go includes

Libraries with their own native code must be in Expo Go's set (react-native-view-shot is). Anything else needs a development build instead of Expo Go, which the CLI doesn't make yet.

Not built

A device host for agents

Described above; nothing exists yet.

Rough edge

Bun 1.4 and Expo Go downloads

The proxy needs Bun 1.4 for WebSockets. The first run per SDK downloads Expo Go from Expo; later runs use the cache in ~/.expo.

Small

react-router wording

Mobile doesn't use react-router. useNavigate and useSearchParams only mention its signature in comments; those can be reworded.