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:
- Nodes cache on load. Reading an entity goes through one shared
use cacheentry per entity, keyed by its global id. A client shown in five lists plus a detail page is one cached row, not six copies. - 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'suse 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:
| Import | What you get |
|---|---|
@athanor/alembic/define | define<Ctx>(): the builder |
@athanor/alembic/fragment | Fragment.of, fragment, FragmentData |
@athanor/alembic/view | view, match |
@athanor/alembic/node, /field, /connection, /mutation | the declaration types |
@athanor/alembic/global-id | the global-id codec |
@athanor/alembic/request | RequestCache |
@athanor/alembic/writes | updated, created, deleted, mask |
@athanor/alembic/streamed, /subscription, /react/subscription | live frames |
@athanor/alembic/testing | testRuntime |
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.
The builder, then the graph
Declare against a builder, build once from the roots.
Declare a node
Identified, batched over one service, cached once per entity, gated per read.
Fragments and views
The mask is the return type; a view is a fragment that renders itself.
Queries
Where a page's boundaries are, and why nothing above an edge waits on it.
Do's and don'ts
The rules that keep the graph honest, with the reason each exists.
Common mistakes
Symptom to cause.
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