Build your own knowledge graph database
The record store·5 min

Node & relationship records

0 / 1

Everything you build sits on two record types. A Node is an id, a list of labels, and a property map. A Relationship is an id, a type, the ids of its two endpoints, and a property map. Note what a relationship stores: only the endpoint ids, not the node objects — pointers, not copies. That single choice is the seed of index-free adjacency (next chapter).

src/types.ts
export type Value = string | number | boolean | string[];

export interface Node {
  id: number;
  labels: string[];
  props: Record<string, Value>;
}

export interface Relationship {
  id: number;
  type: string;
  startNode: number;   // an id, not a Node
  endNode: number;     // an id, not a Node
  props: Record<string, Value>;
}

You never mint ids. They are pre-assigned in the fixtures (by insertion order in the authoring script: people first, then movies, then relationships in declaration order). You ingest them. This is what makes every expected output in the course reproducible from the committed JSON alone — there is no run-to-run drift in which node is id 0.