platepilot

PlatePilot M1 Adult Logging Implementation Plan

For LLM: REQUIRED SUB-SKILL: Use @.github/prompts/execute-plan.prompt.md to implement this plan task-by-task.

Goal: Deliver a production-quality adult-only logging vertical slice: onboarding, manual food and water entries, asynchronous mock photo analysis, daily totals, history, and offline-safe synchronization.

Architecture: Keep domain behavior behind small interfaces in shared contracts and API application modules. The mobile app owns drafts and an offline command queue; the API owns identity, authorization, persistence, quotas, and accepted records. External systems remain replaceable adapters, with deterministic M0 mocks used until approved credentials exist.

Tech Stack: React Native/Expo Router, React Native Paper, TanStack Query, Zustand, React Hook Form, Zod, NestJS, REST/OpenAPI, Prisma/PostgreSQL, LocalStack S3/SQS, Vitest, React Native Testing Library, Maestro.


Scope

M1 includes:

M1 excludes:

Task 1: Establish M1 Domain Contracts

Files:

Step 1: Write failing tests

Cover:

Step 2: Verify RED

corepack pnpm --filter @platepilot/contracts test

Expected: tests fail because the M1 schemas do not exist.

Step 3: Implement minimal contracts

Use strict Zod objects and inferred TypeScript types. Keep Prisma, HTTP, Expo, and provider types out of this package.

Step 4: Verify GREEN

corepack pnpm --filter @platepilot/contracts test
corepack pnpm --filter @platepilot/contracts typecheck

Expected: all contract tests pass.

Step 5: Commit checkpoint

Only if commit authorization is provided:

git add packages/contracts
git commit -m "feat(contracts): define adult diary and sync models"

Task 2: Complete the Adult-Private Persistence Model

Files:

Step 1: Write failing repository tests

Test through repository interfaces:

Step 2: Verify RED

Start PostgreSQL and run the dedicated integration target:

docker compose up -d postgres
corepack pnpm --filter @platepilot/api test:integration

Expected: tests fail because repositories and diary tables are absent.

Step 3: Implement the minimal schema and adapters

Add adult-scoped meal, food-item, water, and client-operation tables. Use internal UUID primary keys and prefixed public IDs. Add unique and foreign-key constraints for subject, public ID, idempotency key, and ownership.

Step 4: Generate and inspect the migration

corepack pnpm --filter @platepilot/api exec prisma migrate dev --name m1_adult_diary
corepack pnpm prisma:generate

Verify that the migration contains no child/dependent fields and no public photo URLs.

Step 5: Verify GREEN

corepack pnpm --filter @platepilot/api test:integration
corepack pnpm prisma:validate

Step 6: Commit checkpoint

Only with authorization:

git add apps/api/prisma apps/api/src/adult-profile apps/api/src/diary
git commit -m "feat(api): persist private adult diary records"

Task 3: Add Mock Identity and Adult Onboarding

Files:

Step 1: Write failing tests

Cover:

Step 2: Verify RED

corepack pnpm --filter @platepilot/api test -- src/auth src/adult-profile

Step 3: Implement minimal behavior

Use the existing IdentityProvider seam and mock adapter. Keep authorization in an API-owned module rather than controllers.

Step 4: Verify GREEN

corepack pnpm --filter @platepilot/api test
corepack pnpm --filter @platepilot/api typecheck

Step 5: Commit checkpoint

Only with authorization:

git add apps/api/src/auth apps/api/src/adult-profile apps/api/src/app.module.ts
git commit -m "feat(api): add adult onboarding boundary"

Task 4: Implement Manual Meal and Water Logging

Files:

Step 1: Write failing tests

Cover:

Step 2: Verify RED

corepack pnpm --filter @platepilot/api test -- src/diary

Step 3: Implement minimal behavior

Controllers validate transport input and delegate. The diary service owns authorization, idempotency, optimistic concurrency, totals, and repository orchestration.

Step 4: Verify GREEN

corepack pnpm --filter @platepilot/api test
corepack pnpm --filter @platepilot/api test:integration

Step 5: Commit checkpoint

Only with authorization:

git add apps/api/src/diary packages/contracts
git commit -m "feat(api): add manual meal and water logging"

Task 5: Implement Mock Photo-Analysis Workflow

Files:

Step 1: Write failing tests

Cover:

Step 2: Verify RED

corepack pnpm --filter @platepilot/api test -- src/photo src/meal-analysis

Step 3: Implement the deep module

Expose a small PhotoMealService interface. Keep storage, queue, provider, persistence, quota, and retention details behind it. Use LocalStack adapters and deterministic provider mocks only.

Step 4: Verify GREEN

docker compose up -d
corepack pnpm --filter @platepilot/api test
corepack pnpm --filter @platepilot/api test:integration
docker compose down

Step 5: Commit checkpoint

Only with authorization:

git add apps/api/src/photo apps/api/src/meal-analysis apps/api/prisma packages
git commit -m "feat(api): add asynchronous mock photo logging"

Task 6: Add the Generated Mobile Client and Offline Command Queue

Files:

Step 1: Write failing tests

Cover:

Step 2: Verify RED

corepack pnpm --filter @platepilot/mobile test -- src/data/sync-engine.test.ts

Step 3: Implement minimal offline infrastructure

Use an encrypted SQLite-backed store on native builds and a test adapter for Vitest. Keep access tokens in secure storage, never in Zustand or general query persistence. Generate the REST client from OpenAPI rather than hand-copying endpoint types.

Step 4: Verify GREEN

corepack pnpm --filter @platepilot/mobile test
corepack pnpm --filter @platepilot/mobile typecheck

Step 5: Commit checkpoint

Only with authorization:

git add packages/api-client apps/mobile/src/data apps/mobile/package.json
git commit -m "feat(mobile): add offline command synchronization"

Task 7: Build Adult Logging Screens

Files:

Step 1: Write failing component tests

Cover:

Step 2: Verify RED

corepack pnpm --filter @platepilot/mobile test

Step 3: Implement the approved Figma flow

Build from the reviewed design specification and shared tokens. Do not add new product scope while translating designs into code.

Step 4: Verify GREEN

corepack pnpm --filter @platepilot/mobile test
corepack pnpm --filter @platepilot/mobile typecheck
corepack pnpm expo:check

Step 5: Commit checkpoint

Only with authorization:

git add apps/mobile packages/design-tokens
git commit -m "feat(mobile): deliver adult diary experience"

Task 8: Add Privacy-Safe Audit and Operational Signals

Files:

Step 1: Write failing tests

Verify:

Step 2: Verify RED

corepack pnpm --filter @platepilot/api test -- src/audit src/telemetry

Step 3: Implement minimal signals

Keep observability behind a small interface with an in-memory test adapter. Do not connect Sentry or AWS telemetry in M1 local mode.

Step 4: Verify GREEN

corepack pnpm --filter @platepilot/api test
corepack pnpm --filter @platepilot/api typecheck

Step 5: Commit checkpoint

Only with authorization:

git add apps/api/src/audit apps/api/src/telemetry docs/threat-model.md
git commit -m "feat(api): add privacy-safe audit signals"

Task 9: Add End-to-End Acceptance Coverage

Files:

Step 1: Define failing acceptance flows

The flows must prove:

  1. An adult completes onboarding and manually logs a meal and water.
  2. A photo job is queued, completes through the deterministic mock, and remains provisional.
  3. A provider failure exposes retry and manual entry.
  4. Offline commands synchronize after connectivity returns.
  5. A version conflict remains visible until resolved.
  6. The dashboard totals match persisted entries.

Step 2: Verify RED

Run the API/mobile stack and execute the focused Maestro flows. Expected: fail before screens and fixtures exist.

Step 3: Implement only missing acceptance wiring

Do not add planning, households, subscriptions, or real providers.

Step 4: Verify GREEN

Run:

corepack pnpm check
corepack pnpm coverage
corepack pnpm compose:config
corepack pnpm prisma:validate
corepack pnpm expo:check
corepack pnpm cdk:synth

Then run the M1 integration and Maestro suites with PostgreSQL and LocalStack healthy.

Step 5: Commit checkpoint

Only with authorization:

git add .
git commit -m "feat: complete M1 adult logging vertical slice"

M1 Definition of Done