# Graph Modeling in Neo4j – Technical Overview Neo4j uses a property graph model, composed of: 1. Nodes - Represent entities (things, concepts, objects) - Have: - Labels (to define type/class) - Properties (key-value pairs) 2. Relationship - Represent connections between two nodes - Always directed (from a source node to a target node) - Have: - Type (relationship kind, e.g. SATISFIES) - Properties (key-value pairs, e.g. weight, timestamp) 3. Properties - Stored as key-value pairs on both nodes and relationships - Types: strings, numbers, booleans, arrays, maps # 1. Nodes: Representing Entities In Neo4j, a node is created with: ```cypher CREATE (n:Label {property1: value1, property2: value2}) ``` Example: UHX Entity (Control Logic Unit) ```cypher CREATE (:Entity:Component { id: "CTRL-01", name: "Control Logic Processor", type: "controller", uht: "00700300", traits: ["purposeful", "emits output", "processes logic", "symbolic", "logical"] }) ``` - :Entity is the base label - :Component is a role-specific label - uht encodes the 32-bit semantic identity - traits stores decoded semantics # 2. Relationships: Representing Links In Neo4j, a relationship connects two nodes: ```cypher MATCH (a:Entity {id: "CTRL-01"}), (b:Requirement {id: "REQ-01"}) CREATE (a)-[:SATISFIES {uhr: "0xD0", traits: ["symbolic", "causal", "directional"]}]->(b) ``` Relationship anatomy: - SATISFIES is the relationship type - uhr is the 8-bit hex encoding of semantic meaning - traits is the decoded set of active relationship traits # 3. Neo4j Data Model Summary | | | | ------------ | ------------------------------------------------------------------------------- | | Component | Representation in Neo4j | | Entity | Node with label :Entity and properties like uht, traits, type, etc. | | Relationship | Directed edge with type (e.g., SATISFIES) and properties like uhr, traits, note | | Type/Kind | Labels (:Requirement, :Component, :Test) and property type | | Semantics | Encoded in uht (node) and uhr (relationship) | | Traceability | Modeled via VERIFIES, DEPENDS_ON, COMPOSED_OF, etc. | # 4. Common UHX Operations in Neo4j A. Find all nodes with a specific traits; ```cypher MATCH (n:Entity) WHERE "purposeful" IN n.traits RETURN n ``` B. Trace requirement → component → test: ```cypher MATCH (req:Requirement)<-[:SATISFIES]-(comp:Entity)-[:VERIFIES]->(test:Test) RETURN req.id, comp.id, test.id ``` C. Visualize full system graph: ```cypher MATCH (n)-[r]->(m) RETURN n, r, m ```