Skip to Content
Athanor

Alembic

The RSC data graph the product is built on: Relay's good ideas, colocated fragments, masking, batched loading, per-entity caching, without a GraphQL runtime.

Alembic is a Relay-shaped data graph for React Server Components. It gives you Relay's good ideas — colocated fragments, masking, opaque record access, batched loading, per-entity caching with derived invalidation — without a GraphQL runtime, because in an RSC + Effect codebase the component tree is the query and React is the executor.

This is the practical guide. The design record, including every reversal and why it stands, is in DECISIONS.md.

What it does for you

Two guarantees, and everything below exists to make them true:

  1. Nodes cache on load. Reading an entity goes through one shared use cache entry per entity, keyed by its global id. A client shown in five lists plus a detail page is one cached row, not six copies.
  2. Mutations invalidate what they touched. A write records which entities it changed, and the cache tags are derived from the node registry — you never write a tag string.

The consequence worth internalising: collections cache membership, nodes cache entities. A list holds ordered ids; each row resolves through its own entry. So editing one client busts one entry, not the list — and no two copies of a row can disagree.

Prerequisites

  • Next.js with cacheComponents: true (Alembic's caching is Next's use cache)
  • Effect 4
  • A way to run an Effect — Alembic owns no runtime and never will

The public surface

App code imports Alembic through its exports and nothing else:

ImportWhat you get
@athanor/alembic/definedefine<Ctx>(): the builder
@athanor/alembic/fragmentFragment.of, fragment, FragmentData
@athanor/alembic/viewview, match
@athanor/alembic/node, /field, /connection, /mutationthe declaration types
@athanor/alembic/global-idthe global-id codec
@athanor/alembic/requestRequestCache
@athanor/alembic/writesupdated, created, deleted, mask
@athanor/alembic/streamed, /subscription, /react/subscriptionlive frames
@athanor/alembic/testingtestRuntime

The engine's internals are not exported on purpose. If you reach for one, the surface is missing something: extend the surface, do not widen the exports.

Where things go

server/athanor/
  alembic.ts            define<Ctx>() — the builder, and nothing else
  schema.ts             objects, the roots, the `graph` value (types list) and build({ … })
  runtime.ts            the process runtime
  override.ts           the AsyncLocalStorage test seam
  cached.ts             the one `use cache` function
  action.ts             action() / revalidate() helpers
  nodes/*.ts            one node per file
  objects/*.ts          objects that are not the viewer (admin, …)
  mutations/*.ts        mutations, grouped by domain

app/…/query.ts          a query, beside the render root that runs it
components/…            views, beside the components that render them
app/…/_actions/action.ts   "use server" — your endpoint surface, in one readable file
app/…/_actions/*.ts        thin form actions: parse the form, call the endpoint, shape the state

On this page