platepilot

PlatePilot M2 Planning and M3 Foundations Implementation Plan (backend)

Goal: Deliver the API side of M2 Planning as a generated weekly meal plan (Monday to Sunday, produced from stored preferences through a mock provider seam, editable, regenerated every Sunday morning, with a synchronized shopping list) plus plan-to-diary confirmation and shared planning, and the M3 foundations the mobile app will consume next: two-adult household invitations and sharing, a mock subscription with a photo-analysis allowance, per-adult export and verified deletion, and calm alerts through the notification seam.

Direction change (2026-09-20, product): the manual planner first built under Task 1 was replaced in place by the generated planner (ADR-0010). Existing item endpoints and SDK operations were kept; preferences, generation, and the shopping list were added.

Architecture: Every capability is a NestJS module shaped like the M1 modules: Zod contracts in packages/contracts, a repository port with a Prisma adapter, an audited service, a controller with hand-written OpenAPI schemas, and colocated unit tests plus an integration test against PostgreSQL. Provider seams stay mock-only (ADR 0003/0005). Nothing is shared between adults without an explicit sharing setting (ADR 0006/0008), plans never become diary facts without confirmation, and the allowance never gates manual entry (ADR 0009).

Tech Stack: NestJS, Zod, Prisma/PostgreSQL, LocalStack S3, Vitest, @hey-api/openapi-ts.

Status (2026-09-20): Tasks 1–7 implemented in the working tree; mobile screens are the mobile agent’s follow-up and consume packages/api-client/src/generated/sdk.gen.ts.


Product rules carried into this plan

Task 1: M2 Planning — apps/api/src/planning

Files: packages/contracts/src/planning.ts (+ test), migration 20260920100211_m2_plan_items, planning.dto.ts, planning.repository.ts, prisma-planning.repository.ts, planning.service.ts, planning.controller.ts, planning.module.ts, planning.service.test.ts, planning.controller.test.ts, planning.repository.test.ts; DiaryService.createPlannedMeal.

Task 1b: Generated weekly meal plans, preferences, shopping list, Sunday job

Files: packages/contracts/src/meal-planning.ts (+ test), packages/provider-contracts MealPlanProvider + DeterministicMealPlanProvider + synthetic recipe library (+ tests), migration 20260920135330_m2_generated_meal_plans, planning-preferences.repository.ts, prisma-planning-preferences.repository.ts, shopping-list.ts, plan-generation.scheduler.ts, extended planning.dto.ts / planning.repository.ts / prisma-planning.repository.ts / planning.service.ts / planning.controller.ts / planning.module.ts, worker wiring, tests (planning.service.test.ts, planning.controller.test.ts, meal-plan.repository.test.ts, shopping-list.test.ts, plan-generation.scheduler.test.ts).

Task 2: Household — apps/api/src/household

Files: packages/contracts/src/household.ts (+ test), migration 20260920101655_m3_household_invitations_sharing, household.dto.ts, household.repository.ts, prisma-household.repository.ts (also implements PlanSharingReader), household.service.ts, household.controller.ts, household.module.ts, three tests; mock identity token local.synthetic-token-b.

Task 3: Subscription and allowance — apps/api/src/subscription

Files: packages/provider-contracts BillingProvider + DeterministicBillingProvider, packages/contracts/src/subscription.ts, migration 20260920102915_m3_subscription_alerts_deletion_receipts (shared with Tasks 5 and 6), environment SUBSCRIPTION_TRIAL_DAYS, SUBSCRIPTION_MONTHLY_ANALYSIS_ALLOWANCE, SUBSCRIPTION_MONTHLY_PRICE_DISPLAY, subscription.* module files and three tests; photo service allowance guard; explicit error code support in the shared error envelope.

Task 4: Export and verified deletion — apps/api/src/adult-data

Files: packages/contracts/src/adult-data.ts, adult-data.* module files and three tests, docs/runbooks/data-export-and-deletion.md.

Task 5: Alerts — apps/api/src/alerts

Files: packages/contracts/src/alerts.ts, alerts.* module files and three tests.

Task 6: Cross-cutting

Definition of Done

Follow-ups