Repository navigation
Description
Charted on the Effect v4 port map (2026-08-28). This issue is the migration spec: every shape decision the port implements, assembled from the map's Notes and the closed tickets, which hold the detail. The build runs from the sub-issues below, one PR and one agent session each; main stays green throughout. Mid-port decisions go back to the map as grilling tickets, not into PR threads.
What the port is
Move the server, packages and CLI from Fastify / hand-rolled pg / commander onto Effect 4 (4.0.0-rc.112, pinned through the pnpm catalog, HTTP/HttpApi/SQL/CLI from effect/unstable/*), and re-cut the monorepo into packages by capability so each can be swapped or extended on its own — above all serving, which the tier 1 and 2 runtimes will build on.
Faithful means: how readers experience served pages and how agents experience the CLI and HTTP API is preserved. Internals are free to be simpler; the port is also a clean-up. Self-hosting is over: Patchy Cloud is the only deployment, and everything that existed for an operator goes.
Target layout
Decided on Package decomposition by capability.
| package | owns |
|---|---|
core |
shared kernel: html-policy, ids. No services. |
api |
wire schemas (Schema.Class), the HttpApi definition, the bearer-middleware definition, the derived HttpApiClient. Imports only core + Effect. |
sql |
@effect/sql-pg layer, Effect Migrator + ledger, embedded-Postgres test layer. Owns no tables. |
auth |
tokens, principals, self-service mint + mint quota, revocation, bearer parsing; migrations 1–2; the tokens/mint/me API group. |
content-store |
put/get/delete objects; filesystem (dev) and Azure blob layers. Renamed from storage — "storage" is reserved for the later per-patch file primitive. |
patches |
records, versions, upload contract, visits, retention/expiry, the expiry sweep, pins, moderation, patch quota; migrations 3+; the patches API group. |
serving |
serving guarantees, headers, CSP, cache-control, page routes (/, /d/*, /healthz) as HttpRouter, trusted-proxy CIDR schema. Reads content through patches, never bytes. |
analytics |
the event service (emitters: auth, patches), PostHog layer, finalizer flush under 3 s. |
limits |
the fixed-window limiter as an Effect service whose interface mirrors RateLimiter.consume. Quotas are not here (mint quota is auth's, patch quota patches'). |
cli |
unchanged scope; imports api + core. |
apps/server |
wiring only: per-capability Config, the layer stack, the forked sweep, listen. |
Deleted: packages/config (Effect Config per capability), packages/db (split into sql + auth + patches), packages/storage (renamed). Imports:
cli ──▶ api ──▶ core
auth ──▶ api, sql, analytics, limits
patches ──▶ api, sql, analytics, content-store
serving ──▶ patches (+ limits only if a page rate limit survives reports removal)
apps/server ──▶ all
patches never imports auth: handlers receive the principal from the bearer middleware. A capability with one consumer stays a module unless it has two implementations (content-store).
Vocabulary: execution is a runtime with tiers (tier 0 = static page); serving is serving a patch to the user; a patch is runtime-agnostic (id, owner, versions, retention clock, pin, quota). draft → patch is renamed wherever the port touches.
Shape decisions
Settled while charting (map Notes) and on the closed tickets. Each build ticket names the ones it implements.
- HTTP.
/api/*is anHttpApidefined inpackages/api; each capability implements its own group withHttpApiBuilder.group. Pages are plainHttpRouterroutes owned byserving. The observable status contract of the pre-routing target classification (400/404/414) and of auth-before-body (no double rate-limit debit) is kept, implemented as one raw middleware plus one API-group middleware; Fastify'srewriteUrl/Symbol-marked request/preBody*flags are dropped. The 401 body stays{ ok: false, error }— a plainSchema.Struct+HttpApiSchema.status(401), no_tagon the wire (vertical slice). - SQL.
@effect/sql-pg+SqlSchema;sql.withTransactionfor the four manual transactions; row decoding through Schema in one module per capability so the pending native-client type change (int8→bigint, timestamps→epoch ms) lands in one place. Effect'sMigrator(Migrator.make({})fromeffect/unstable/sql, notPgMigrator.layer) withfromRecordcomposing per-package records: one global integer id sequence, duplicates fail, all pending steps in one transaction underACCESS EXCLUSIVE, ledgerschema_migrations(migration_id integer, name, created_at).prepare: falsereserved for the Neon pooler (vertical slice). - Postgres only. The JSON-file driver is deleted; embedded-postgres is the dev and test store. No production database exists, so the baseline migrations are rewritten by owner with
patches/patch_versionsnaming and integer ids (auth1–2,patches3+);draft_reportsnever exists. ADR. - Reports are removed (scope change on #56): PatchPage's free-service valve, nothing later builds on it, and it leaks a reader-facing surface into
serving. Mint, pins, expiry and quotas stay as foundations. - CLI (CLI contract on Effect cli):
effect/unstable/cli; exit-code ladder by who has to act — 0 ok, 1local, 2rejected, 3unreachable, 130 interrupted, nothing else;--jsonand--api-urlare global flags; JSON failure is{ ok: false, error, kind }on stderr, success one stdout document in theapiwire shape;--api-url>.local/dev/env(walk up from cwd) >PATCHY_API_URL>~/.patchy> default, resolved by oneInstanceservice; Effect's signal mapping, terminal restore as a scope finalizer; defects are oneUnexpected error:line, stack only at--log-level debug. esbuild bundle needs thecreateRequirebanner. One ADR CLI contract for agents. - Config. Effect
Configper capability,Redactedsecrets, fail on the first missing key. Trusted-proxy CIDRs stay aSchemainserving(HttpMiddleware.xForwardedHeadershas no allow-list). TheConfigPascalCase rename is a known upcoming RC break. - Tests.
@effect/vitest:it.layershares one fresh, migrated embedded-Postgres database per block,it.effectper case,HttpApiTest.groupsfor API routes,NodeHttpServer.layerTestfor what a socket sees,TestClockfor the clock,Scopefor anything closed by hand, faults injected by an alternate layer, never a mock. Template:packages/effect-slice/src/slice.test.tsonprototype/effect-slice(README lists the gotchas).app.test.tssplits by capability as each ports. - Limiter, sweep, analytics. Limiter semantics kept (
Retry-After, fails closed at 10k keys) behind an interface mirroringRateLimiter.consume, so a Redis-backed swap is a layer change. Sweep isEffect.repeat(job, Schedule.spaced("1 hour"))forked in the server scope. Analytics is a service whose finalizer flushes under 3 s; PostHog stays. - Wire schemas and docs. Schemas live in
packages/api;docs/API.mdis rendered fromOpenApi.fromApiby a small local renderer and pinned by a test. - Guardrails (landed): Effect pinned via catalog + overrides, Dependabot RC PRs labelled
effect-rc-bump(#57);@effect/language-servicediagnostics failtypecheck, with the whole-file Node rules (nodeBuiltinImport,globalConsole,globalDate,globalRandom,globalTimers,globalFetch,cryptoRandomUUID) left atwarningfor each port ticket to promote for its package (#58); the two review specs are repo skills/code-reviewloads (#59);AGENTS.mdhas the## Effectsection (#61, PR docs(agents): tell agents how Effect is written here #67). Still to land: the two t3code ESLint rules written locally (namespace imports for service modules, no manual runtimes in tests, no schema compile in hot paths) — with theservingticket. - Dev runner (Local dev environment, supervisor prototype): an Effect 4 CLI under
scripts/,pnpm dev; per-worktree ports from a path hash and state in.local/dev/; idempotent, daemonised start that migrates and seeds;status/stop/logs/reset;--dry-run --jsonprints thePlan; each service spawned witheffect/unstable/processin one scope; seed = one dev company + one token written to.local/dev/env.
Rules every port PR follows
- Service conventions:
.agents/skills/effect-service-conventions/SKILL.md— one file per service (errors/schemas,Context.Servicetag with the interface inline,make,layer); namespace imports at service boundaries;Schema.TaggedErrorwith structured fields andcause; dependencies from the environment, never constructor arguments;runPromise/ManagedRuntimeonly at the server and CLI entrypoints and at the thin seam between a ported package and one not yet moved. - Seams: a ported package is consumed by unported code through a thin
Effect.runPromiseadapter, deleted by the PR that ports the consumer. No long-lived port branch. - Glossary follows the code: the PR that moves a capability moves its terms out of
apps/server/CONTEXT.mdintopackages/<name>/CONTEXT.mdand writespackages/<name>/docs/adr/where a decision meets the ADR tests. Nothing is written ahead of code. Expected system-wide ADRs (rootdocs/adr/): Postgres-only, theapicontract package, CLI contract for agents. - Lint: promote the language-service warnings to
errorfor each package as it ports; the two Effect ESLint rules land withserving. - Rename what you touch:
draft → patch— on the wire whenpackages/apiis created (one wire break, not two; decided on filing), in tables and code whenpatchesports. - Read first:
node_modules/effect/AGENTS.mdandai-docs/; upstreamMIGRATION.md;~/Dev/t3codefor conventions. - Review:
/code-reviewwith theeffect-service-conventionsspec on every port PR;ui-consistencywhen rendered HTML or CSS moves.
Build order
One sub-issue each, filed ready-for-agent, blocking wired as native dependencies (the real ones, so independent tickets can run in parallel; the numbering is the recommended order).
- Remove reports (pre-port, plain TS)
- Dev runner — the first Effect 4 code and the harness every later PR is smoked on
packages/api+--jsonon every command (Fastify decodes through Schema as the interim adapter)packages/sql— Pg layer, Migrator, test layerpackages/analytics+packages/limitspackages/authpackages/content-storepackages/patchespackages/serving+apps/serveron HttpApi/HttpRouter; deleteconfig,db; Effect lint toerrorpackages/clioneffect/unstable/cli- Redraw
CONTEXT-MAP.md, remainingCONTEXT.md/ADRs, wipe self-hosting artefacts, retire ADR-0000/0001
Known unknowns (not blocking)
- A shared rate-limiter store for multi-replica production — surfaces with deployment work.
- Neon specifics once production points at it: transaction-mode pooler (
prepare: false), scale-to-zero dropping sessions. - Two merged-but-unreleased Effect breaks are planned for: the
@effect/sql-pgnative client types and theConfigPascalCase rename. RC bumps follow the runbook inAGENTS.md.
Out of scope
Feature-by-feature keep/drop of PatchPage-isms (except reports); deployment target, replicas, hosting, release channel; auth replacement, tier 1/2 runtimes, the integration layer; self-hosting in any form.
Activity
allisonmahmood commentedon Sep 2, 2026
migration done
allisonmahmood commentedon Sep 2, 2026
Built. All eleven build tickets (#69–#79) are closed and their PRs merged on main: #80–#90. The known unknowns above (multi-replica limiter store, Neon pooler and scale-to-zero, the two unreleased Effect breaks) are not blocking and move to whichever map takes on deployment.