Skip to content

Phase 3: production readiness (hardening, offline, store config, accessibility, CI) - #6

Merged
coderback merged 4 commits into
mainfrom
phase-3
Nov 5, 2026
Merged

coderback merged 4 commits into
mainfrom
phase-3

Conversation

@coderback

@coderback coderback commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Phase 3 of the roadmap (docs/ROADMAP.md).

⚠️ Deploy notes

  • Railway now health-checks GET /health (railway.toml). The server checks its settings at boot and won't start if DATABASE_URL, SUPABASE_URL, SUPABASE_ANON_KEY, AZURE_OPENAI_ENDPOINT or AZURE_OPENAI_API_KEY is missing or malformed. The log lists which.
  • One migration waits for this deploy: 20261105130000_drop_users_push_token. Phase 2 servers still read users.pushToken, so apply it only after Railway runs this version. The other new migration (20261105120000_add_missing_indexes) only adds indexes and is already applied to Supabase.
  • New optional settings: RATE_LIMIT_PER_MINUTE (default 300) and CORS_ORIGINS (default: any origin).

Backend

  • Config validated at boot, listing every problem at once.
  • GET /health, including a database check.
  • Local token verification against Supabase's published ES256 key, cached, instead of a Supabase call on every request. Older HS256 tokens, or a key lookup failure, fall back to asking Supabase.
  • Rate limiting per signed-in session (per IP when signed out). Health checks are exempt; crash reports are capped at 10 a minute.
  • Request IDs and logs: every request gets an x-request-id, which is also in error bodies, and one log line with status and duration. Logs are JSON in production.
  • Exception filter:
    • HTTP error bodies stay as they were.
    • Prisma "not found" and "duplicate" errors become 404 and 409.
    • Anything unexpected is logged with its stack and answered with a generic 500.
  • POST /client-errors records crashes reported by the app.
  • Startup: graceful shutdown on SIGTERM, and trust proxy so client IPs are real.
  • Indexes for habits, challenge participants, kudos and finishing challenges.
  • Caps on the challenge list, the blocked list and the challenge-ending batch. The alert jobs now page through users.

Mobile

  • Crash screen: a screen that crashes shows a recovery page with Try again instead of a blank app. The crash, and any uncaught JS error, is reported to the backend.
  • Offline: NetInfo drives React Query's online state on phones (the browser's events on web). Cached screens stay visible, queries refetch on reconnect, saves fail fast instead of spinning, and a banner above the tab bar explains without blocking taps.
  • Store config:
    • Plain HTTP only in development builds (app.config.js).
    • The microphone permission removed and blocked.
    • An iOS privacy manifest.
    • The unused react-native-health and react-native-health-connect removed: linking HealthKit without using it gets builds rejected. useHealthKit.ts says how to add them back.
  • Accessibility: every tappable element has a role, icon-only buttons have labels, options and toggles report their selected or on state, and the tab bar uses tab roles.

Tests and CI

  • GitHub Actions (.github/workflows/ci.yml):
    • The backend job applies the migrations to a throwaway Postgres, checks the schema has no drift, then runs prettier, eslint, tsc, unit tests, database tests and the build.
    • The mobile job runs tsc, eslint and unit tests.
  • Mobile: ESLint (Expo config) and Jest (jest-expo), with tests for the calorie maths, units, dates (also run in several time zones), challenge labels, alert routing and quick-food helpers.
  • Backend: new database tests for feed paging with tied timestamps and for the weekly leaderboard. The backend test scripts call its own Jest 30, because jest-expo also installs a jest command.

Testing

  • Every CI step was run on a clean checkout with a fresh npm install and an empty database, and all passed.
  • Backend: 91 unit tests and 26 database tests.
  • Mobile: 18 unit tests, with lint and type check clean.
  • HTTP checks against the running API with a real sign-in: 102 checks across Phase 1 and 2 features, plus smoke tests of the health check, request IDs, rate limiting, crash reports, error format and local token verification. Five authenticated requests took 69 ms in total.
  • Web end-to-end: every earlier suite passes, plus 9 new checks for the offline banner, fast-failing saves while offline, accessibility roles and crash reporting.

Not testable here: real-device behaviour (push, photo picking, keyboard in sheets, NetInfo on phones).

- Environment checked once at boot, listing every missing or malformed
  setting instead of failing on the first request that needs one.
- GET /health (with a database check) for Railway's health check.
- Sign-in tokens are verified locally against Supabase's published
  ES256 key (cached), so requests no longer wait on a call to Supabase;
  older HS256 tokens, or a key lookup failure, fall back to asking it.
- Rate limiting: 300 requests a minute per signed-in session (per IP
  when signed out), configurable with RATE_LIMIT_PER_MINUTE.
- Every request gets an ID (returned in x-request-id and in error
  bodies) and one log line with status and duration; logs are JSON in
  production. A global exception filter keeps HTTP error bodies as they
  were, maps missing/duplicate records to 404/409, and hides internals
  of unexpected errors while logging their stack.
- POST /client-errors records crashes reported by the app (throttled).
- Graceful shutdown on SIGTERM; trust proxy for client IPs; CORS can be
  narrowed with CORS_ORIGINS.
- Indexes for habits, challenge participants, kudos and finished
  challenges; caps on the challenge list, blocked list and the challenge
  ending batch; the alert jobs page through users.
- users.pushToken removed from the schema. Its drop migration must only
  be applied after this version is deployed (Phase 2 servers read it).
- Crash handling: a screen crash shows a recovery screen with Try again
  instead of a blank app, and crashes (from the boundary and uncaught JS
  errors) are reported to the backend's new /client-errors log with the
  screen and app version.
- Offline: NetInfo drives React Query's online state on phones (the
  browser's events on web). Cached screens keep showing, queries refetch
  on reconnect, saving fails straight away instead of spinning, and a
  banner above the tab bar explains, without blocking taps.
- Store config: plain HTTP only in development builds (app.config.js),
  the microphone permission removed and blocked (the camera is only for
  barcodes), an iOS privacy manifest for the required-reason APIs, and
  the unused react-native-health / react-native-health-connect packages
  removed, since linking HealthKit without using it gets builds
  rejected. useHealthKit explains how to add them back.
- Accessibility: every tappable element has a role, icon-only buttons
  have spoken labels, options and toggles report their selected or
  on state, and the tab bar uses tab roles.
- GitHub Actions: the backend job applies the migrations to a throwaway
  Postgres, checks the schema matches them, then runs prettier, eslint,
  tsc, unit tests, database tests and the build. The mobile job runs
  tsc, eslint and unit tests.
- Mobile: ESLint with Expo's config (npm run lint) and Jest with
  jest-expo (npm test). Tests cover the calorie maths, units, local
  dates (checked in several time zones), challenge labels, where alerts
  open, and quick-food helpers, which move to lib/quickFoods.ts so they
  can be tested without the API client. Unused imports and the unused
  WeeklyBarChart are removed.
- Backend: database tests for feed paging (items sharing a timestamp are
  neither skipped nor repeated, future items never shown) and the
  weekly leaderboard. Test scripts call the backend's own Jest, since
  jest-expo also installs a `jest` command.
The roadmap marks Phase 3 done, lists the one migration that waits for
the deploy (dropping users.pushToken) and what's left for later. The
README covers the health check, request IDs and logs, the new settings,
mobile lint and tests, and CI.
@vercel

vercel Bot commented Nov 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
grit-demo Ready Ready Preview Nov 4, 2026 10:22pm UTC

@coderback
coderback merged commit 57e0266 into main Nov 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant