Skip to content

Concepts

Graph

A graph is a registry, named author/name. author is the 64-character public key that signs it and name is the registry name, such as social/main. A registry can hold ordinary files next to graph data: only assets whose name ends in .graph.jsonl are read as graph data.

Segment

A segment is one .graph.jsonl asset: a list of statements, one per line. A graph is the union of the segments in the registry's current manifest. Segments are declarative: a segment states what is true while it is published. To change a fact, publish the segment again. To withdraw facts, remove the segment.

Statement

A statement declares a node or an edge.

  • A node has an id, labels and properties.
  • An edge has a type, a source node, a target node, an optional key and properties. An edge is identified by (type, from, to, key), so use key for parallel edges of one type.

Edges may point to ids that no segment declares. The missing node then exists with no labels and no properties. This lets a graph refer to nodes of another graph.

Merging

Within a graph, segments are applied in order of asset name:

  • labels of a node are the union over all segments
  • for each property, the segment whose name sorts last wins

Prefix names with numbers (10-people.graph.jsonl, 20-overrides.graph.jsonl) to make the order explicit.

Across graphs in one query, the first graph listed wins for each property, and labels are the union. Listing your own graph first means nobody else's graph can override your properties.

System nodes

Each graph also contains the structure of its registry. System labels, edge types and properties start with an underscore, and segments cannot use that prefix, so they cannot be forged by a segment.

Node id Label Properties
author:<public key> _Author _pubkey
registry:<author>/<name> _Registry _name, _version
asset:<event id> _Asset _name, _type, _size, and _intent if one is set
content:sha256:<digest> _Content _cid
Edge From To
_PUBLISHES author registry
_CONTAINS registry asset
_HAS_CONTENT asset content

Because content nodes are identified by digest, two registries that publish the same bytes meet at the same node when queried together. Your own edges may point to system nodes, for example to describe an asset or an author.

Provenance

Every node and edge carries sources: the asset:<event id> of each segment that stated it, or manifest:<event id> for system statements. An asset id is the id of an event signed by the author, so a source always leads back to a signature.

Version and root

A loaded graph has a version and manifest id, taken from the registry, and a root: the Merkle root over a header line followed by every statement in sorted order. The header binds the author, registry name, version and manifest id. Two services that loaded the same registry state have the same root, whatever order they read it in.

An intent changes the statements of an asset without a new manifest, so the root can change while the version stays the same.

Loading rules

graphd reads each configured registry at an interval and applies a new state only if all of these hold:

  1. The registry reader returns a complete state.
  2. The registry has no conflicting manifests.
  3. The version is not lower than the last one applied, and the same version has the same manifest.
  4. Every segment matches its size, SHA-256 identifier and Merkle root.
  5. Every segment parses, and the graph is within the configured limits.

A new state is applied as a whole or not at all. If any check fails, the last good state keeps being served and the reason appears under error in GET /v1/graphs.

Revocation

If the author revokes all published versions, the graph becomes empty except for its author and registry nodes. If the author revokes one asset, that segment's statements disappear.