Skip to content

feat(api): scaffold @gbfm/api with Effect HttpApi health contract#136

Closed
guidefari wants to merge 10 commits into
prodfrom
feat/migrate-effect-http-api
Closed

feat(api): scaffold @gbfm/api with Effect HttpApi health contract#136
guidefari wants to merge 10 commits into
prodfrom
feat/migrate-effect-http-api

Conversation

@guidefari

Copy link
Copy Markdown
Owner

Step 1 of the Hono -> Effect HttpApi migration tracked in `docs/migration-effect-http-api.md` (Migration Order step 1: "Create packages/api with contract for health group — proves the pattern").

What

  • New leaf workspace package `packages/api` (depends only on `effect@4.0.0-beta.93`) so server-only code cannot leak into the www client bundle by mistake.
  • Health group contract (`live` /health/live, `ready` /health/ready, `check` /health) with Effect `Schema` response/error shapes preserving the current Hono behavior.
  • Shared `ReadinessCheckFailedError` (`Schema.TaggedErrorClass`, `httpApiStatus: 500`) — Phase 2 error-port starter.
  • Contract unit tests in `packages/api` proving endpoint shape, schema decode/encode, error tagging, and the typed `HttpApiClient` interface compiles.
  • Behavior-preserving integration test in `apps/vps` characterizing the current Hono health endpoints as a migration safety net before the serving topology changes (Step 2).

Why this is safe

No runtime server behavior changes. `apps/vps` does not yet import `@gbfm/api`; nothing serves the new contract. This only establishes the shared contract and a baseline test so the subsequent serving-topology change (Step 2) can be validated against captured behavior.

Verification

  • `bun --filter='@gbfm/api' typecheck` — clean
  • `bun --filter='@gbfm/vps' typecheck` — clean
  • `bun run lint` / `bun run format` — clean
  • `packages/api` tests — 8/8 passing

Note

`bun precommit` currently fails on a pre-existing `@gbfm/www` typecheck error in `src/lib/spotify-pkce.ts` (9 errors on a clean `prod` checkout, unrelated to this PR). Root-level `bun run typecheck` will surface that independently; it is not introduced here.

Next (out of scope for this PR)

Step 2: wire `HttpRouter.toWebHandler` + Hono wildcard fallback + better-auth route + background forks + shutdown, porting the health handlers to `HttpApiBuilder.group` and validating the serving topology in prod.

guidefari added 10 commits July 6, 2026 09:11
Step 1 of the Hono -> Effect HttpApi migration (docs/migration-effect-http-api.md).

- New leaf workspace package packages/api so server-only code cannot leak
  into the www client bundle. Depends only on effect (4.0.0-beta.93).
- Health group contract: live (/health/live), ready (/health/ready), and
  check (/health) endpoints with response schemas preserving the current
  Hono behavior (live -> { ok: true }, ready/check -> { dbConnected: true }).
- Shared ReadinessCheckFailedError (Schema.TaggedErrorClass, httpApiStatus
  500) for the readiness 500 path; first of the Phase 2 error ports.
- Contract unit tests (packages/api) verify endpoint shape, schema decode
  rejects, error tagging/encoding, and the typed HttpApiClient interface.
- Behavior-preserving integration test (apps/vps) characterizes the current
  Hono health endpoints as a migration safety net (status, body, 5s cache,
  rate-limit exclusion) before the serving topology changes in Step 2.
The packages/api contract test duplicated the vps health integration test
at the boundary (e.g. { ok: true } decodes) and the rest was internal-shape
noise (endpoint names, schema internals, error encoding). User-facing
behavior parity belongs at the HTTP boundary, which the vps curl-style
integration test already captures as the migration baseline.

Step 2 will run the same request->response spec against the Effect
HttpApiBuilder server to prove parity without duplicating assertions.
@guidefari

Copy link
Copy Markdown
Owner Author

Closing to restart clean. Scope crept past Step 1 (contract-only) into Step 2 territory (serving topology: app.ts, routes.ts, index.ts, runtime/services.ts, sentry, OTel) in the same PR, and the test approach went sideways -- a hand-rolled curl/assertion script (scripts/api-test/health.ts) duplicating what the vitest integration test already covers, instead of just extending that test. Redoing this in smaller, single-purpose check-ins per the revised step breakdown in docs/migration-effect-http-api.md (steps 1a/1b, 2a/2b/2c, 3a/3b, ...). Branch/commits stay around for reference, not deleting anything.

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.

1 participant