Skip to content

Package decomposition by capability #56

Closed

Description

@allisonmahmood

Part of #54

Question

Which capability packages does the ported monorepo have, what does each own (tables, migrations, config slice, routes, errors), and what stays a module? Starting proposal: api, auth (tokens, principals, scopes, bearer parsing, minting + quota, revocation), patches (records, versions, upload contract, visits, retention/expiry, pins, moderation, reports), serving (render, headers, CSP, page routes — the seam tiers 1/2 extend), storage, sql (client + migration runner), cli; core shrinks to html-policy + ids; limits and analytics stay modules in apps/server. Where does the expiry sweep live (it spans patches and storage)?

Produces the new CONTEXT-MAP.md contexts and a CONTEXT.md per capability, and the ordered list of per-capability build tickets for the spec. Call grilling and domain-modeling. HITL.

Activity

  1. added
    wayfinder:grilling
    on Aug 28, 2026
  2. allisonmahmood commented on Aug 28, 2026

    @allisonmahmood
    OwnerAuthor

    Resolution (grilled with Allison, 2026-08-28)

    Vocabulary that shaped the cut

    • Runtime with tiers is how execution is named in code and docs (tier 0 = static page, no execution; tiers 1–3 later, out of scope). Serving means serving a patch to the user: guarantees, headers, CSP, page routes. Today serving is what a tier-0 runtime needs; no runtime package exists until a second tier does.
    • Content store = the platform's object store for a patch's bytes (invisible to the author). Reserves the plain word "storage" for the later per-patch file primitive. The package is content-store, not storage.
    • A patch is runtime-agnostic: id, owner, versions, retention clock, pin, quota. Content and what runs it vary by tier; lifecycle (create/update/delete/expire) is written once in patches.

    Packages and what each owns

    package owns
    core shared kernel: html-policy, ids. No services.
    api wire schemas, the HttpApi definition, bearer-middleware definition, derived client. Imports only core + Effect.
    sql @effect/sql-pg layer, Migrator + ledger, embedded-Postgres test layer. Owns no tables.
    auth tokens, principals, self-service mint + mint quota, revocation, bearer parsing; migrations 1–2 (accounts, api_tokens, token_mints); implements the tokens/mint/me API group.
    content-store put/get/delete objects; filesystem (dev) and Azure blob layers. One consumer (patches) but two implementations — kept a package for the layer swap.
    patches records, versions, upload contract (object then row, rollback on failure), visits, retention/expiry, expiry sweep, pins, moderation, draft quota; migrations 3+; implements the patches API group. Depends on content-store, so the sweep has one home and serving never touches bytes.
    serving serving guarantees, headers, CSP, cache-control, page routes (/, /d/*, /healthz) as HttpRouter, trusted-proxy CIDR schema. Reads content through patches.
    analytics the event service (two emitters: auth, patches); PostHog layer; finalizer flush. Expected to grow.
    limits the fixed-window limiter as an Effect service (interface mirrors RateLimiter.consume). Expected to change a lot (billing, abuse, safety net). Quotas are not here: mint quota is auth's, draft quota patches', both DB counts.
    cli unchanged scope; imports api + core.
    apps/server wiring only: composes per-capability Config, stacks layers, schedules the sweep, listens.

    Deleted: packages/config (Effect Config per capability; CIDR schema → serving), packages/db (split into sql + auth + patches), packages/storage (renamed).

    Dependency graph (arrow = 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 — verify in its ticket)
    apps/server ──▶ all
    

    patches never imports auth: handlers receive the principal id from the bearer middleware. Rule amended: a capability with one consumer stays a module unless it has two implementations (content-store).

    Reports are removed (scope change, recorded on the map)

    Reports were PatchPage's free-service safety valve and are the one feature nothing later builds on; they also leak a reader-facing surface (/report/*, the wrapper form) into serving. Self-service mint, pins, expiry, quotas stay — they are foundations.

    Migrations

    Baseline rewritten by owner with patches/patch_versions naming and integer ids (auth 1–2, patches 3+); draft_reports never exists. No prod DB exists, so no rename or mark-applied step — the ledger is simply new.

    CONTEXT.md / ADRs

    Every package gets packages/<name>/CONTEXT.md + packages/<name>/docs/adr/; root docs/adr/ for system-wide. Vocabulary is universal across the project; a package glossary is scoped to prevent context bloat, and the ADRs are the main value for infra-only packages. Each port PR moves its terms out of apps/server/CONTEXT.md so the glossary follows the code; nothing is written ahead of code. Term homes: token/principal/mint/quota/revocation → auth; patch/visit/expiry/sweep/pin/live/moderation/analytics event → patches; serving guarantee → serving; Publishing glossary → cli. Target CONTEXT-MAP.md: contexts auth, patches, serving, cli; kernel core; infra api, sql, content-store, analytics, limits; relationships: cli→api, serving→patches, patches→content-store.

    Build tickets for the spec (one PR each, one agent session each, main stays green)

    1. Remove reports (pre-port, plain TS)
    2. Dev runner
    3. packages/api + --json (Fastify decodes through Schema)
    4. packages/sql (Pg layer, Migrator, test layer)
    5. packages/analytics + packages/limits (ported before their first consumer)
    6. packages/auth (migrations 1–2, tokens/mint/me group)
    7. packages/content-store (rename + layers)
    8. packages/patches (migrations 3+, sweep, patches group; draft → patch rename in tables/code/wire)
    9. packages/serving + apps/server on HttpApi/HttpRouter; delete config, db; Effect lint to error
    10. packages/cli on effect/unstable/cli
    11. Redraw: CONTEXT-MAP.md, remaining CONTEXT.md/ADRs, wipe self-hosting artefacts, retire ADR-0000/0001

    Not built here (context only, not scope): runtime tiers 1–3, primitives, integrations, auth-provider swap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

wayfinder:grilling

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions