Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ packages/mobile/certs/public-key.pem
.claude/*
!.claude/skills/
.context/
.worktrees/
.codegraph/
.DS_Store
*.swp
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Provider-agnostic fitness/health data pipeline. Syncs data from various provider
- **Server-side metric computation**: All metric values must be computed on the server — never derive, aggregate, or transform metric data in web or iOS client code. The API response should contain every value the UI needs to display. Clients are responsible only for rendering (colors, labels, formatting, layout) — not for computing the numbers they display. This prevents inconsistencies when the same metric appears on multiple screens or platforms. If a client is calling a scoring/calculation function on raw data from the API, that calculation belongs in the server router instead.
- **Good architecture and modeling**: Actively look for opportunities to decouple code, model real-world concepts as proper classes/types, use common interfaces, and apply SOLID principles with domain-driven design. When you see scattered logic that represents a single concept (e.g., "is this provider connected?"), extract it into a model or interface rather than leaving it inline. Prefer domain-driven abstractions over ad-hoc checks spread across the codebase. Follow SOLID principles: single responsibility (each class/module does one thing), open/closed (extend via composition, not modification), Liskov substitution (subtypes must be substitutable), interface segregation (small, focused interfaces), and dependency inversion (depend on abstractions, not concretions). Prefer composition over inheritance — build complex behavior by combining simple, focused components rather than deep class hierarchies. Use dependency injection, strategy patterns, and mixins instead of base classes.
- **Dual-platform parity (web + mobile)**: Every feature, bug fix, and UI change must be implemented on both `packages/web` and `packages/mobile`. When adding a new page, chart, or data view to one platform, implement the equivalent on the other in the same PR. Shared logic lives in domain-specific packages (`@dofek/format`, `@dofek/scoring`, `@dofek/nutrition`, `@dofek/training`, `@dofek/stats`, `@dofek/onboarding`, `@dofek/providers`) — import from there instead of duplicating. Platform-specific code (HealthKit, barcode scanning, Expo secure storage, ECharts vs react-native-svg) stays in the respective package. When reviewing PRs, check that both platforms are updated.
- **Mobile Expo Router route hygiene**: Never colocate tests, stories, fixtures, or helper-only files under `packages/mobile/app/`. Expo Router treats files in `app/` as route candidates, which can create extra iOS tabs/screens. Put route tests under `packages/mobile/app-tests/` and route stories under `packages/mobile/app-stories/`. If a file under `app/` is not a real route/layout/special Expo Router file, move it out instead of hiding it with `href: null`.
- **Always report errors to Sentry**: Never silently swallow errors or only log them. Every `catch` block that handles an unexpected error must call `captureException()` (from `./telemetry` in mobile, or the equivalent in server code) so failures are visible in our error monitoring. Silent `catch(() => {})` blocks are banned — they hide bugs and make debugging impossible.
- **Surface errors to the user by default**: When a server error occurs, send a specific, actionable error message to the client — never hide it behind a generic "Something went wrong" or "Failed to load." Use a TRPCError with an appropriate code (e.g., `PRECONDITION_FAILED`, `NOT_FOUND`) and a human-readable message that tells the user what's wrong and what to do. Clients must display `error.message` from the server, not hardcoded strings. Hiding the real error from the user makes debugging slower and generates support requests that could be self-service.
- **Fail fast, never warn-and-continue**: When a required precondition is missing (env file, config, dependency), fail immediately with a clear error — never log a warning and silently continue with broken state. A deploy that proceeds with an empty `.env.prod` is worse than one that fails loudly. Warnings that don't stop execution are deceptive; they hide the real problem and cause confusing downstream failures.
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"release:npm:publish": "pnpm --recursive publish --access public --no-git-checks",
"typecheck": "tsc --noEmit",
"lint": "pnpm lint:sandbox && pnpm lint:analytics-sql",
"lint:sandbox": "pnpm lint:exact-versions && biome check . --max-diagnostics=500 && pnpm lint:suppressions && pnpm lint:workflow-downloads && pnpm lint:analytics-policy && pnpm lint:mobile-telemetry && pnpm lint:web-stories && pnpm lint:review-scenarios",
"lint:sandbox": "pnpm lint:exact-versions && biome check . --max-diagnostics=500 && pnpm lint:suppressions && pnpm lint:workflow-downloads && pnpm lint:analytics-policy && pnpm lint:mobile-telemetry && pnpm lint:web-stories && pnpm lint:review-scenarios && pnpm check:mobile-app-routes",
"lint:fix": "biome check --write .",
"lint:exact-versions": "tsx scripts/exact-versions.ts",
"lint:openapi": "redocly lint docs/whoop-api.openapi.yaml --extends minimal",
Expand Down Expand Up @@ -213,7 +213,8 @@
"size": "size-limit",
"depcruise": "depcruise --config .dependency-cruiser.cjs src/ packages/",
"spellcheck": "cspell --no-progress",
"check:mobile-update": "tsx scripts/check-ota-manifest.ts"
"check:mobile-update": "tsx scripts/check-ota-manifest.ts",
"check:mobile-app-routes": "tsx scripts/check-mobile-app-route-files.ts"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
},
"dependencies": {
"@ai-sdk/otel": "1.0.47",
Expand Down
5 changes: 4 additions & 1 deletion packages/mobile/.rnstorybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { StorybookConfig } from "@storybook/react-native";

const config: StorybookConfig = {
stories: ["../components/**/*.stories.?(ts|tsx|js|jsx)", "../app/**/*.stories.?(ts|tsx|js|jsx)"],
stories: [
"../components/**/*.stories.?(ts|tsx|js|jsx)",
"../app-stories/**/*.stories.?(ts|tsx|js|jsx)",
],
addons: ["@storybook/addon-ondevice-actions", "@storybook/addon-ondevice-controls"],
};

Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { StorybookConfig } from "@storybook/react-native-web-vite";
const currentDir = dirname(fileURLToPath(import.meta.url));

const config: StorybookConfig = {
stories: ["../components/**/*.stories.@(ts|tsx)", "../app/**/*.stories.@(ts|tsx)"],
stories: ["../components/**/*.stories.@(ts|tsx)", "../app-stories/**/*.stories.@(ts|tsx)"],
framework: "@storybook/react-native-web-vite",
docs: {
autodocs: "tag",
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- **Storybook**: Every component MUST have a `.stories.tsx` file (lives in `.storybook` and `.rnstorybook`).
- **Charts**: Use `react-native-svg` for all chart implementations.
- **Navigation**: Uses Expo Router. Screen paths map to `app/`.
- **Expo Router route hygiene**: Never colocate tests, stories, fixtures, or helper-only files under `packages/mobile/app/`. Expo Router treats files in `app/` as route candidates, which can create extra iOS tabs/screens. Put route tests under `packages/mobile/app-tests/` and route stories under `packages/mobile/app-stories/`. If a file under `app/` is not a real route/layout/special Expo Router file, move it out instead of hiding it with `href: null`.
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
- **Query state handling**: Treat loading, error, and empty as separate UI states. Do not use `query.data ?? []` or similar fallbacks when `query.error` exists. Use `components/QueryStatePanel.tsx` for explicit error/empty/loading states on screens and cards.
- **Loading performance**: Follow `../../docs/performance/loading-performance-runbook.md` for slow screens. Do not blank visible previous/cached data during background refetches; use blocking loading only when no usable data exists, preserve server error messages, and keep sync/refresh invalidation targeted to affected query families.

Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ See `../../docs/nutrition-ai-input.md` for end-to-end behavior and API flow.

## Project Structure

- `app/`: Expo Router screens (file-based routing).
- `app/`: Expo Router screens (file-based routing). Keep this route-only; tests and stories in `app/` can become accidental screens.
- `app-tests/`: Vitest tests for Expo Router screens.
- `app-stories/`: Storybook stories for Expo Router screens.
- `components/`: React Native UI components (SVG-based charts).
- `modules/`: Native Swift modules:
- `background-refresh`: iOS background task registration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type { AppRouter } from "dofek-server/router";
import { useMemo } from "react";
import { View } from "react-native";
import { within } from "storybook/test";
import ActivitiesScreen from "../../app/(tabs)/activities";
import { trpc } from "../../lib/trpc";
import ActivitiesScreen from "./activities";

const mapPreview = {
width: 1024,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { Meta, StoryObj } from "@storybook/react-native";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { httpBatchLink } from "@trpc/client";
import { View } from "react-native";
import { seedFoodStoryQuery } from "../../app/(tabs)/_food-story-fixture";
import FoodScreen from "../../app/(tabs)/food";
import { trpc } from "../../lib/trpc";
import { colors } from "../../theme";
import { seedFoodStoryQuery } from "./_food-story-fixture";
import FoodScreen from "./food";

function localDateString(dayOffset = 0): string {
const date = new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { MISSING_PREVIOUS_NIGHT_MESSAGE } from "dofek-server/sleep-need-contract";
import { type ReactNode, useMemo } from "react";
import { View } from "react-native";
import { trpc } from "../../lib/trpc";
import { colors } from "../../theme";
import {
createProcessingStatusStoryLink,
seedReadyProcessingStatus,
} from "./_processing-status-story-fixture";
import TodayScreen from "./index";
} from "../../app/(tabs)/_processing-status-story-fixture";
import TodayScreen from "../../app/(tabs)/index";
import { trpc } from "../../lib/trpc";
import { colors } from "../../theme";

function localDateString(dayOffset = 0): string {
const date = new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { mobileRecoveryFixtureSchema } from "dofek-server/mobile-dashboard-contr
import type { AppRouter } from "dofek-server/router";
import { useMemo } from "react";
import { View } from "react-native";
import { trpc } from "../../lib/trpc";
import { colors } from "../../theme";
import { createFixtureDates } from "./_fixture-dates";
import { createFixtureDates } from "../../app/(tabs)/_fixture-dates";
import {
createProcessingStatusStoryLink,
seedReadyProcessingStatus,
} from "./_processing-status-story-fixture";
import RecoveryScreen from "./recovery";
} from "../../app/(tabs)/_processing-status-story-fixture";
import RecoveryScreen from "../../app/(tabs)/recovery";
import { trpc } from "../../lib/trpc";
import { colors } from "../../theme";

function createRecoveryErrorStoryLink(recoveryUnavailable: boolean): TRPCLink<AppRouter> {
return () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { mobileTrainingFixtureSchema } from "dofek-server/mobile-dashboard-contr
import type { AppRouter } from "dofek-server/router";
import { useMemo } from "react";
import { View } from "react-native";
import { trpc } from "../../lib/trpc";
import { createFixtureDates, type FixtureDates } from "./_fixture-dates";
import { createFixtureDates, type FixtureDates } from "../../app/(tabs)/_fixture-dates";
import {
createProcessingStatusStoryLink,
seedReadyProcessingStatus,
} from "./_processing-status-story-fixture";
import StrainScreen from "./strain";
} from "../../app/(tabs)/_processing-status-story-fixture";
import StrainScreen from "../../app/(tabs)/strain";
import { trpc } from "../../lib/trpc";

const STRAIN_COMPANION_RESPONSES = {
"training.hrZones": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from "@storybook/react-native";
import { View } from "react-native";
import { ActivitySourceDecisionCard } from "./ActivitySourceDecisionCard";
import { ActivitySourceDecisionCard } from "../../app/activity/ActivitySourceDecisionCard";

const meta = {
title: "Activity/ActivitySourceDecisionCard",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from "@storybook/react-native";
import { View } from "react-native";
import { HrZonesChart, PowerZonesChart } from "./ZoneDistributionCharts";
import { HrZonesChart, PowerZonesChart } from "../../app/activity/ZoneDistributionCharts";

const heartRateZones = [
{ zone: 0, label: "Below Zone 1", minPct: 0, maxPct: 50, seconds: 180, percent: 5.8 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { getQueryKey } from "@trpc/react-query";
import type { AppRouter } from "dofek-server/router";
import { useMemo } from "react";
import { View } from "react-native";
import AlertsScreen from "../app/alerts";
import { trpc } from "../lib/trpc";
import { colors } from "../theme";
import AlertsScreen from "./alerts";

type AlertsScenario =
| "needs-attention"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { OperationResultObservable, TRPCLink } from "@trpc/client";
import type { AppRouter } from "dofek-server/router";
import { useMemo } from "react";
import { View } from "react-native";
import BehaviorAssociationsScreen from "../app/behavior-associations";
import { trpc } from "../lib/trpc";
import { colors } from "../theme";
import BehaviorAssociationsScreen from "./behavior-associations";

type BehaviorAssociationsScenario = "available" | "empty";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { OperationResultObservable, TRPCLink } from "@trpc/client";
import type { AppRouter } from "dofek-server/router";
import { useMemo } from "react";
import { View } from "react-native";
import BreathworkScreen from "../app/breathwork";
import { trpc } from "../lib/trpc";
import { colors } from "../theme";
import BreathworkScreen from "./breathwork";

function createMockLink(): TRPCLink<AppRouter> {
return () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { OperationResultObservable, TRPCLink } from "@trpc/client";
import type { AppRouter } from "dofek-server/router";
import { useMemo } from "react";
import { View } from "react-native";
import CorrelationScreen from "../app/correlation";
import { trpc } from "../lib/trpc";
import { colors } from "../theme";
import CorrelationScreen from "./correlation";

type CorrelationScenario = "available" | "insufficient";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { inferRouterClient, OperationResultObservable, TRPCLink } from "@tr
import type { AppRouter } from "dofek-server/router";
import { useMemo } from "react";
import { View } from "react-native";
import CycleScreen from "../app/cycle";
import { trpc } from "../lib/trpc";
import { colors } from "../theme";
import CycleScreen from "./cycle";

type CurrentPhaseOutput = Awaited<
ReturnType<inferRouterClient<AppRouter>["menstrualCycle"]["currentPhase"]["query"]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { OperationResultObservable, TRPCLink } from "@trpc/client";
import type { AppRouter } from "dofek-server/router";
import { useMemo } from "react";
import { View } from "react-native";
import ExperimentsScreen from "../app/experiments";
import { trpc } from "../lib/trpc";
import { colors } from "../theme";
import ExperimentsScreen from "./experiments";

type ExperimentScenario = "empty" | "active";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from "@storybook/react-native";
import { View } from "react-native";
import { within } from "storybook/test";
import LoginScreen from "./login";
import LoginScreen from "../app/login";

type ProvidersResponse =
| "error"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from "@storybook/react-native";
import { View } from "react-native";
import MoreScreen from "../app/more";
import { colors } from "../theme";
import MoreScreen from "./more";

const meta = {
title: "Pages/More",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
createNutritionAnalyticsStoryLink,
nutritionAnalyticsStoryData,
} from "../.storybook/nutrition-analytics-story-link";
import NutritionAnalyticsScreen from "../app/nutrition-analytics";
import { trpc } from "../lib/trpc";
import { colors } from "../theme";
import NutritionAnalyticsScreen from "./nutrition-analytics";

type NutritionAnalyticsStoryScenario = "available" | "error" | "stale-error" | "unavailable";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Meta, StoryObj } from "@storybook/react-native";
import type { ComponentType } from "react";
import { View } from "react-native";
import { ProviderCard } from "../../app/providers/provider-card.tsx";
import { AuthProvider } from "../../lib/auth-context";
import { ProviderCard } from "./provider-card.tsx";

// ── ProviderCard ──
// AuthProvider is resolved to .storybook/mocks/auth-context in web Storybook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type { OperationResultObservable, TRPCLink } from "@trpc/client";
import type { AppRouter } from "dofek-server/router";
import { useMemo } from "react";
import { View } from "react-native";
import { ProviderDangerZone } from "../../app/providers/provider-danger-zone";
import { trpc } from "../../lib/trpc";
import { ProviderDangerZone } from "./provider-danger-zone";

function createMockLink(): TRPCLink<AppRouter> {
return () => () => createMockObservable();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from "@storybook/react-native";
import { View } from "react-native";
import { ProviderDetailActionsCard } from "../../app/providers/provider-detail-actions-card";
import { colors } from "../../theme";
import { ProviderDetailActionsCard } from "./provider-detail-actions-card";

const meta = {
title: "Providers/ProviderDetailActionsCard",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Meta, StoryObj } from "@storybook/react-native";
import { View } from "react-native";
import { within } from "storybook/test";
import { SyncAllControls } from "../../app/providers/sync-all-controls";
import { colors } from "../../theme";
import { SyncAllControls } from "./sync-all-controls";

const meta = {
title: "Providers/SyncAllControls",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { httpBatchLink } from "@trpc/client";
import { View } from "react-native";
import { within } from "storybook/test";
import SettingsScreen from "../app/settings";
import { AuthProvider } from "../lib/auth-context";
import { trpc } from "../lib/trpc";
import SettingsScreen from "./settings";

const settingsModelCards = [
["exponentialMovingAverage", "Training Load Windows", "Past 365 days"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { type OperationResultObservable, TRPCClientError, type TRPCLink } from "
import type { AppRouter } from "dofek-server/router";
import { useMemo } from "react";
import { View } from "react-native";
import TrackingScreen from "../app/tracking";
import { trpc } from "../lib/trpc";
import { colors } from "../theme";
import TrackingScreen from "./tracking";

type TrackingScenario = "available" | "empty" | "loading";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { createFixtureDates } from "./_fixture-dates";
import { createFixtureDates } from "../../app/(tabs)/_fixture-dates";

describe("createFixtureDates", () => {
afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { QueryClient } from "@tanstack/react-query";
import { describe, expect, it } from "vitest";
import { seedFoodStoryQuery } from "../../app/(tabs)/_food-story-fixture";
import { FoodByDateV2Schema } from "../../types/api";
import { seedFoodStoryQuery } from "./_food-story-fixture";

describe("seedFoodStoryQuery", () => {
it("seeds runtime-valid data for the current byDateV2 procedure", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { fireEvent, render, screen } from "@testing-library/react";
import type { ReactNode } from "react";
import { describe, expect, it, vi } from "vitest";
import TabsLayout, { tabsScreenOptions } from "../../app/(tabs)/_layout";
import { getTabIconName, selectedTabBackgroundColor } from "../../lib/tab-selection";
import { colors } from "../../theme";
import TabsLayout, { tabsScreenOptions } from "./_layout";

const { mockPush } = vi.hoisted(() => ({ mockPush: vi.fn() }));

Expand Down
Loading
Loading