Skip to content

refactor: extract TodayPage and Worker god files - #44

Merged
sarthakagrawal927 merged 3 commits into
mainfrom
refactor/extract-today-and-worker
Aug 16, 2026
Merged

refactor: extract TodayPage and Worker god files#44
sarthakagrawal927 merged 3 commits into
mainfrom
refactor/extract-today-and-worker

Conversation

@sarthakagrawal927

Copy link
Copy Markdown
Member

Why

src/worker.ts (2,186 lines) and src/pages/TodayPage.tsx (2,091 lines) were unreviewable hubs. Domain libs were fine; the composition roots were not.

What

Behavior-preserving extract only. No food-entry, auth, or D1 SQL semantic changes.

Workersrc/worker.ts stays the Wrangler/Hono composition root (wrangler.jsonc main unchanged). Route groups move to src/worker/:

  • auth.ts — health, Better Auth, native handoff, session/MCP middleware
  • account.ts — profile, bootstrap, cycles, MCP tokens, journal export
  • journal.ts — foods, entries, water, medications, weights
  • reads.ts — dashboard and history
  • mcp.ts — MCP GET reads
  • db.ts / http.ts / types.ts — shared mapping, validation, app types

TodayTodayPage remains the router export. Sections and hook live under src/pages/today/:

  • useTodayPage.ts — load, optimistic log, undo, editors
  • launchpad, daily actions, summary/remaining, water, medications, timing, log, entry sheet

Source tests now scan the Worker modules instead of a single file.

Closes #43

Line counts

File Lines
src/worker.ts 52
src/worker/account.ts 471
src/worker/auth.ts 181
src/worker/db.ts 397
src/worker/http.ts 81
src/worker/journal.ts 524
src/worker/mcp.ts 334
src/worker/reads.ts 266
src/worker/types.ts 13
src/pages/TodayPage.tsx 312
src/pages/today/useTodayPage.ts 890
src/pages/today/TodayEntrySheet.tsx 399
other src/pages/today/* 76–160

Checks

  • pnpm test — 169 passed
  • pnpm test:coverage — thresholds held
  • tsc app + worker
  • biome format + lint
  • knip unused baseline unchanged

Out of scope: native rewrite, coverage-floor raises, deploys.

Keep worker.ts as the Hono composition root and TodayPage as the router
export. Route groups move under src/worker/; Today sections and hook
move under src/pages/today/. Food-entry behavior, auth, and D1 SQL
semantics are unchanged.

Closes #43
Move entry-sheet state, effects, and handlers into useTodayEntrySheet
with module-scope helpers so useTodayPage is a composer under the 616
line cap. Lift worker route handlers out of register* wrappers and
group a couple of Today panel props so complexity stays at 30 violations.
@sarthakagrawal927
sarthakagrawal927 merged commit a39c82e into main Aug 16, 2026
2 checks passed
@sarthakagrawal927
sarthakagrawal927 deleted the refactor/extract-today-and-worker branch August 16, 2026 18:29
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.

Extract TodayPage and Worker god files into focused modules

1 participant