← Back to Pull requests

feat(mobile): Expo app foundation — auth, API client, collection, Rapid Add camera #376

Closed
unknown closed this pull request without merging on Oct 20, 2026 02:43 UTC
View on GitHub
unknown unknown commented on Oct 19, 2026 01:55 UTC
Author

Refs #109 (and the native remainders of #21 Rapid Add and #105 photo matching it carries). Not Closes: you decide when #109 is done.

What this adds

The Expo app goes from a blank template to a signed-in, API-backed app with native Rapid Add.

  • Foundation: Expo SDK 57 (RN 0.86, React 19.2.3, new architecture) with Expo Router. Route groups mirror the web: (app) holds a Collection / Search / Add / Profile tab bar behind Stack.Protected, and sign-in sits outside it. TypeScript is strict and extends tsconfig.base.json. ESLint (eslint-config-expo) runs as part of npm run lint. npm run dev:mobile builds the shared types, then starts Expo. Settings come from .env.local (EXPO_PUBLIC_, see .env.example).

  • Auth: the same three modes as the web.

  • - Dev bypass sends Bearer dev:<id>.
    - Entra External ID uses expo-auth-session (authorization code + PKCE) against the same tenant and app registration, so the token has the same shape. Tokens are kept in expo-secure-store and refreshed before they expire.
    - "Not configured" is the third mode.
    - In every mode, a session counts as signed in only after POST /api/auth/validate accepts it.
  • Typed API client (src/api/client.ts) mirrors apps/web/src/lib/api.ts with swatchwatch-shared types. It covers polishes (status/untried filters, paging), detail, inventory quick actions, dupes, the mani log, catalog search, capture (start/frame/check/finalize/status/answer) and match-image.

  • Screens on the live API:

  • - Collection: status presets, untried badge, swatch thumbnails from the image-variant ladder, infinite scroll, pull to refresh.
    - Polish detail: gallery, finishes, hexes, status actions following D5, Mark tried, Log today's mani with undo, owned-dupe callout, buy link.
    - Search: Add / ♡ behind the #266 add guard, with fuzzy suggestions when nothing matches.
    - Profile: who is signed in, API URL, sign-in mode, sign out.
  • Rapid Add (Add tab):

  • - expo-camera scans barcodes on the device. GTINs are validated by a new shared barcode/gtin.ts that uses the web scanner's rules.
    - Photos tagged barcode / label / color are posted to /api/capture/{id}/frame. Network, 408, 429 and 5xx errors retry automatically, then the photo shows Retry / Remove.
    - The verdict comes from the read-only POST /api/capture/{id}/check: you own it / on your wishlist / near-dupe / new to you / pick one / not found.
    - A photo-library fallback and hints cover simulators and bottles with no barcode.
  • Match to Collection (/match): a camera or library photo goes to POST /api/polishes/match-image, and the extracted colors work as filter chips.

  • Design tokens: npm run sync:design-tokens generates packages/shared/src/constants/design-tokens.ts from the web's globals.css (oklch → hex, light + dark). The mobile theme uses it, and CI checks that it doesn't drift.

  • CI: a new Mobile (lint, typecheck, unit tests) job, plus mobile unit tests (node:test via tsx, 18 tests).
  • Screenshots

    Expo web preview at 375×812, signed in through dev bypass against a local Functions host and the local dev DB. The iOS simulator could not run (see Verification).

    | Sign-in | Collection (dark) | Collection (light) | Polish detail |
    |---|---|---|---|
    | ![](https://github.com/mattmck/swatchwatch/blob/claude/feat-109-expo-foundation-d6ba59/apps/mobile/docs/screenshots/sign-in.jpg?raw=true) | ![](https://github.com/mattmck/swatchwatch/blob/claude/feat-109-expo-foundation-d6ba59/apps/mobile/docs/screenshots/collection-dark.jpg?raw=true) | ![](https://github.com/mattmck/swatchwatch/blob/claude/feat-109-expo-foundation-d6ba59/apps/mobile/docs/screenshots/collection-light.jpg?raw=true) | ![](https://github.com/mattmck/swatchwatch/blob/claude/feat-109-expo-foundation-d6ba59/apps/mobile/docs/screenshots/polish-detail.jpg?raw=true) |

    | Search | Rapid Add | Verdict: you own it | Profile |
    |---|---|---|---|
    | ![](https://github.com/mattmck/swatchwatch/blob/claude/feat-109-expo-foundation-d6ba59/apps/mobile/docs/screenshots/search.jpg?raw=true) | ![](https://github.com/mattmck/swatchwatch/blob/claude/feat-109-expo-foundation-d6ba59/apps/mobile/docs/screenshots/rapid-add.jpg?raw=true) | ![](https://github.com/mattmck/swatchwatch/blob/claude/feat-109-expo-foundation-d6ba59/apps/mobile/docs/screenshots/rapid-add-verdict-owned.jpg?raw=true) | ![](https://github.com/mattmck/swatchwatch/blob/claude/feat-109-expo-foundation-d6ba59/apps/mobile/docs/screenshots/profile.jpg?raw=true) |

    Verification

  • ✅ npm run typecheck and npm run lint across the workspace (0 errors; the 13 warnings were already in web).

  • ✅ npm run test across the workspace (runs in the pre-commit hook), including the new mobile suites.

  • ✅ node scripts/sync-design-tokens.mjs --check. Brand hexes come out exactly equal to swatchWatchBrandPalette.

  • ✅ npm run build --workspace=apps/web passes with the new root React overrides.

  • ✅ End to end in dev-bypass mode (Expo web preview, local Functions host at :7071 through a throwaway CORS proxy, local dev DB):

  • - "Continue as dev user" → /auth/validate → Collection lists dev user 1's 20 owned polishes from the API.
    - The session is restored after a reload.
    - Polish detail loads.
    - Search returns catalog rows with ownership.
    - Rapid Add with hints (OPI / Big Apple Red) → capture/start → capture/check → "You own this · 2 bottles · Nothing was added".
  • ✅ A code-review pass found six issues; all are fixed in 35d21af:

  • - a barcode scanned into an already-started session was checked before its GTIN arrived
    - stale-scan callbacks after Scan next
    - two paging races
    - a network failure during token refresh signed the user out
    - the Android swatchwatch://auth redirect landed on an unmatched route
  • ❌ iOS Simulator not run: this Mac has only the Command Line Tools, not Xcode, so neither expo run:ios nor the simulator was available. Not exercised:

  • - native rendering (iOS / Android)
    - expo-camera preview and on-device barcode scanning
    - takePictureAsync → image-manipulator → frame upload
    - expo-image-picker
    - secure-store persistence (the web preview uses localStorage)
    - haptics
    - the Entra PKCE sign-in, which needs the redirect URI below and a dev build
  • ⚠️ I made no writes on the screens beyond one local capture_session row for dev user 1, so I did not exercise Add / Wishlist / status changes / Log mani / I bought it / Match. Their API calls are the same ones the web makes.
  • Judgment calls

    1. Expo SDK 57, not 54. apps/mobile/package.json was already on expo ~57.0.26, though dependabot had separately bumped react-native to 0.88 and left react at 19.1. I realigned react-native, react and every Expo package to SDK 57's bundledNativeModules. CLAUDE.md said SDK 54 and is now corrected.
    2. One React for the whole repo. The root package.json now has overrides: { react: 19.2.3, react-dom: 19.2.3 }.
    - Why: the root next devDependency hoisted react 19.2.7 while web and mobile pin 19.2.3. That nested expo-router where the hoisted Expo CLI couldn't find it, so expo start crashed. React Native's renderer also needs an exact React match.
    - 19.2.3 is the version web already pins, and the web build passes.
    - Bump the override together with web and Expo React upgrades.
    3. Expo SDK 57 + expo-auth-session instead of MSAL React Native. The issue says MSAL RN. react-native-msal is unmaintained and needs native config. expo-auth-session with PKCE gets the same tenant, scopes and token shape.
    4. Rapid Add checks before it adds. The web finalizes, which adds the polish to the collection, and then offers an undo. Mobile uses the read-only /check endpoint and writes only when the user taps Add (PUT /api/polishes/{shadeId}, or finalize for a SKU without a shade). In an aisle that is the safer default. The wishlist and near-dupe verdicts the web's capture-verdict.ts lists as "extension points" exist natively here.
    5. iOS UPC-A quirk. iOS reports UPC-A as a 13-digit EAN-13 with a leading 0. Because barcode.gtin lookups are exact, mobile sends the printed 12 digits, as the web scanner and OCR do. Normalizing GTINs on the server would be more robust; see follow-ups.
    6. Search uses GET /api/polishes?search= (catalog rows with the caller's status, hexes and images) rather than /catalog/search, whose results carry no color or ownership. /catalog/search (pg_trgm) is the fallback when the first returns nothing.
    7. Dev bypass is the default in development builds without Entra settings, and an explicit EXPO_PUBLIC_AUTH_DEV_BYPASS=false turns it off. Mobile dev bypass also still shows a sign-in button that calls /auth/validate, so "auth end-to-end" is exercised; the web auto-signs-in instead.
    8. No EXPO_PUBLIC_B2C_SIGNUP_SIGNIN_POLICY + a tenant id = External ID (no p=). The web would fall back to the legacy B2C_1_signupsignin path there.
    9. Shared additions are small and additive:
    - constants/design-tokens.ts (generated)
    - barcode/gtin.ts (a copy of the pure rules from apps/web/src/lib/barcode-scan.ts; I left web untouched because other sessions are editing it)
    - the Rapid Add frame reducer is copied into mobile, not moved
    10. CI:
    - setup-deps gets an include-mobile input with its own cache key, so the existing jobs keep their install.
    - The existing Lint & Typecheck job now names its workspaces explicitly, because the root scripts now include mobile.
    - No device builds.
    11. Screenshots are committed under apps/mobile/docs/screenshots (about 320 KB) so the README and this PR can show them.
    12. Route groups: (app) and sign-in only. There is no (marketing) or (admin) group yet, since neither has native screens.

    Decisions needed

    Each one is parked with my recommendation already applied. Nothing in this PR is blocked on them.

    1. Should mobile Rapid Add check first, or add on match like the web?
    - Recommended: keep check first (mobile, read-only /check, add on tap). The web finalizes, which adds immediately, and then offers an undo.
    - Blocks: nothing. If you want the web's behavior instead, it's a small change in add.tsx (call finalize in place of check).
    - Later, consider moving the web to check-first too, for consistency.
    2. Keep the root overrides that pin React to 19.2.3?
    - Recommended: yes, until web, mobile and next agree on a React patch. Without it expo start fails in this monorepo.
    - Blocks: React upgrades now have to bump the override.
    3. Stay on Expo SDK 57?
    - Recommended: yes. CLAUDE.md said SDK 54, but package.json was already on 57.
    - Blocks: nothing.
    4. MSAL React Native vs expo-auth-session?
    - Recommended: expo-auth-session. The issue text names MSAL RN.
    - Blocks: nothing until you register the redirect URI below.

    Owner actions

  • Register the redirect URI swatchwatch://auth:

  • - Entra admin center → External ID tenant → App registrations → the web app's registration → Authentication →
    Add a platform → Mobile and desktop applications.
    - Do this for each environment's tenant you want to sign in from.
    - No new registration or secret is needed (public client + PKCE).
  • To try sign-in, copy the web's NEXT_PUBLIC_B2C_ values into apps/mobile/.env.local as EXPO_PUBLIC_B2C_, set EXPO_PUBLIC_AUTH_DEV_BYPASS=false, then npx expo run:ios. Sign-in needs a dev build: Expo Go's redirect URI can't be registered.

  • Install Xcode (then sudo xcode-select -s /Applications/Xcode.app/Contents/Developer) to run the simulator checks listed above.

  • Local web preview only: the Functions host must allow http://localhost:8081 (func start --cors http://localhost:8081). Native builds need nothing.

  • The first CI run of the new Mobile job fills a new node_modules cache, so it's slower once.
  • Follow-ups (not in this PR)

  • Server-side GTIN normalization in the capture resolver (match UPC-A ↔ 0-prefixed EAN-13 ↔ GTIN-14).

  • Switch the web's barcode-scan.ts to the shared barcode/gtin.ts, and move the frame reducer into shared.

  • On-device color extraction native modules (#105 remainder in #109).

  • EAS build profiles and a CI smoke bundle (expo export) once Xcode/EAS are set up.
  • 🤖 Generated with Claude Code

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    New Features
    Added a mobile app with sign-in, collection browsing, polish search and details, photo matching, and Rapid Add scanning.
    Added barcode scanning, photo-based polish matching, and options to add matches to a collection or wishlist.
    Added light and dark themes that follow the device setting.
    Added support for development and Microsoft sign-in modes.
    Documentation
    Added mobile setup, configuration, testing, and design-token synchronization guidance.
    Chores
    Added mobile linting, type checking, unit tests, and design-token checks to CI.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: mattmck Review duration: 1487m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.75) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #376"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.5% · Safe to merge
    32.5%