# ADR-022: Composite foreign keys for node references ## Status Accepted ## Context Edges reference source and target nodes. A simple `sourceNodeId` FK would work but doesn't capture the composite key model. ## Decision Edges reference nodes via composite FKs: `(graphId, sourceNodeKey) → (nodes.graphId, nodes.key)`. This ensures referential integrity within a graph and cascades node deletions to connected edges. ## Consequences - Deleting a node cascades to all its edges - Edges cannot reference nodes in a different graph - Composite FKs match the metagraph identity model `(graphId, key)` ## References - [sqlite-host.md](../sqlite-host.md)