Files
HealthLog/src
Marc-André Bombeck 4537ff0d8e feat(medications): add a note to the medication (#1371)
Directions such as "30 to 60 minutes before food" had nowhere to go: a
medication carried no free text of its own, only the notes on a dose
change or a course. The medication now has one note, edited on the last
step of the wizard and shown under the name on the detail page, above
the dose actions on both card variants, under the picked medication in
the log-dose sheet, and per row in the take-all-due list. One
MedicationNote component renders it everywhere, in foreground text.

The note is sealed at rest in Medication.noteEncrypted (migration
0498_medication_note, lock-bounded), with no plaintext column. Create
and update take an optional `note`: trimmed, at most 500 characters, an
empty string or null clears it, absent keeps it. The wizard sends it on
an edit only when it changed, so an unrelated save never clears it. The
list and detail reads strip the ciphertext and answer `note`.

Both ends of the data path carry it: the backup (decrypted in a portable
file, ciphertext in a disaster-recovery file), the restore, the data
export, the key-rotation registry and script, and the MCP medication
schedule, resources and fetch, fenced as user text. The doctor report
and the FHIR export leave it out: it is the person's own reminder, and
the report has no selection for personal prose.

The size baselines rise by the one-line wiring of the field in the
medication page, detail tabs, cards, log-dose sheet, wizard step and
list read; the wizard payload grows by the field's own encode and
hydrate.
2026-11-14 09:30:40 +01:00
..
…

src/

Application source. HealthLog is a Next.js 16 App Router project (output: "standalone", React 19, TypeScript strict). The path alias @/* resolves to this directory. Everything a request touches lives under here; the layout below follows the request flow rather than alphabetical order.

Request flow

client → src/proxy.ts → src/app/<route>/route.ts → src/lib/api-handler.ts → handler body → src/lib/api-response.ts → client
  • proxy.ts — the HTTP edge (Next.js 16's renamed middleware). Public-path allowlist, demo-mode mutation block, server-side onboarding redirect, worker-only refusal, x-request-id + CSP nonce generation, every security header.
  • app/ — App Router pages (RSC by default) and API routes. Every API route wraps its handler in apiHandler. See app/README.md.
  • lib/ — the server/runtime toolkit: apiHandler, auth, crypto, rollups, AI, notifications, pg-boss jobs, integrations, rate limiting. See lib/README.md.
  • components/ — React components (shadcn/ui new-york, kebab-case files). See components/README.md.

Other directories

  • hooks/ — shared React hooks (use- prefix, kebab-case).
  • types/ — shared TypeScript declarations.
  • generated/prisma/ — the generated Prisma client (do not edit; regenerated by prisma generate). Imported as @/generated/prisma.
  • instrumentation.ts — Next.js startup hook; boots the pg-boss worker registry and boot-time backfill queues.
  • __tests__/ — cross-cutting unit tests; most tests live in __tests__/ folders next to the code they cover.

Conventions

The load-bearing ones: RSC by default ("use client" only when a hook/state/browser API needs it); every API route wraps apiHandler and parses its body with Zod safeParse; userId is always narrowed from session or Bearer, never accepted as a body field; TanStack Query keys come only from src/lib/query-keys/; outbound HTTP goes through src/lib/safe-fetch.ts.