neo4j-contrib/neo4j-skills2 files

Neo4j Modeling Skill

Design, review, and refactor Neo4j graph data models. Use when choosing node

Specification
Skill ID
neo4j-contrib/neo4j-skills/neo4j-modeling-skill
Publisher
neo4j-contrib
Repository
neo4j-skills
Installs
0
Files
2
Synced
Sep 23, 2026
How to use it

Open any RiverX project, open the Skills panel in the chat, and search for this identifier. The files are fetched from the source repository at install time.

neo4j-contrib/neo4j-skills/neo4j-modeling-skillInstalls these files
  • README.md
  • SKILL.md

What this skill tells the agent

When to Use

  • Designing graph model from scratch (domain → nodes, rels, props)
  • Reviewing existing model for anti-patterns
  • Deciding node vs property vs relationship vs label
  • Migrating relational or document schema to graph
  • Designing intermediate nodes for n-ary or complex relationships
  • Detecting and mitigating supernode / high-fanout problems
  • Choosing and creating constraints + indexes for a model

When NOT to Use

  • Writing or optimizing Cypher → neo4j-cypher-skill
  • Spring Data Neo4j (@Node, @Relationship) → neo4j-spring-data-skill
  • GraphQL type definitions → neo4j-graphql-skill
  • Importing data (LOAD CSV, APOC import) → neo4j-import-skill

Inspect Before Designing

On existing database, run first — never propose changes without current state:

CALL db.schema.visualization() YIELD nodes, relationships RETURN nodes, relationships;
SHOW CONSTRAINTS YIELD name, type, labelsOrTypes, properties RETURN name, type, labelsOrTypes, properties;
SHOW INDEXES YIELD name, type, labelsOrTypes, state WHERE state = 'ONLINE' RETURN name, type, labelsOrTypes;

If APOC available:

CALL apoc.meta.schema() YIELD value RETURN value;

MCP tool map:

OperationTool
Inspect schemaget-schema
SHOW CONSTRAINTS, SHOW INDEXESread-cypher
CREATE CONSTRAINT ... IF NOT EXISTSwrite-cypher (show + confirm first)

Defaults — Apply to Every Model

  1. Use-case first — list 5+ queries the model must answer before designing
  2. Nodes = entities (nouns) with identity; rels = connections (verbs) with direction
  3. Labels PascalCase; rel types SCREAMING_SNAKE_CASE; properties camelCase
  4. Every node type used in MERGE has a uniqueness constraint on its key property
  5. Add property type constraints (REQUIRE n.prop IS :: STRING) where the type is known — helps the query planner and catches bad writes early
  6. No generic labels (:Entity, :Node, :Thing); no generic rel types (:RELATED_TO, :HAS)
  7. Security labels (used for row-level access control) should start with a common prefix (e.g. Sec) so application code can reliably filter them out of the domain schema
  8. Rel direction encodes semantic meaning — not arbitrary
  9. Inspect schema before proposing any change on an existing database
  10. All constraint/index DDL uses IF NOT EXISTS — safe to rerun
  11. On Neo4j 2026.06+ (Enterprise/Aura, GA): declare the full model in one block with ALTER CURRENT GRAPH TYPE SET { … }, extend it with ALTER CURRENT GRAPH TYPE ADD { … }, instead of individual CREATE CONSTRAINT statements — see neo4j-cypher-skill/references/graph-type.md. On 2026.02–2026.05 the same syntax is preview.

Key Patterns

Node vs Relationship vs Property — Decision Table

QuestionAnswerModel as
Is it a thing with identity, queried as entry point?YesNode
Is it a connection between two things with direction?YesRelationship
Does the connection have its own properties or multiple targets?YesIntermediate node
Is it a scalar always returned with its parent, never filtered alone?YesProperty on parent
Is it a category used for type-based filtering or path traversal?YesLabel (not a property)
Does the same attribute value repeat across many nodes (low cardinality)?YesLabel, not a property node
Is it a fact connecting >2 entities?YesIntermediate node

Property vs Label — Decision Table

Use label whenUse property when
Values are few, fixed, used as traversal filters (WHERE n:Active)Values are many, dynamic, or unique per node
You traverse by type (MATCH (n:VIPCustomer))You filter by value (WHERE n.tier = 'vip')
Category drives index selectionFine-grained value drives range scans
Example: :Active, :Verified, :PremiumExample: status, score, email

Rule: adding a label is cheap; scanning all :Label nodes is fast. Never model high-cardinality values as labels.


Intermediate Node Pattern

Use when a relationship needs its own properties, connects >2 entities, or is independently queryable.

Before (relationship with property — limited):

(Person)-[:ACTED_IN {role: "Neo"}]->(Movie)
// Cannot query roles independent of movies

After (intermediate node — queryable, extensible):

(Person)-[:PLAYED]->(Role {name: "Neo"})-[:IN]->(Movie)
// MATCH (r:Role) WHERE r.name STARTS WITH 'Neo' RETURN r

Employment overlap example:

// Find colleagues who overlapped at same company
MATCH (p1:Person)-[:WORKED_AT]->(e1:Employment)-[:AT]->(c:Company)<-[:AT]-(e2:Employment)<-[:WORKED_AT]-(p2:Person)
WHERE p1 <> p2
  AND e1.startDate <= e2.endDate AND e2.startDate <= e1.endDate
RETURN p1.name, p2.name, c.name

Promote relationship to intermediate node when:

  • Relationship has >2 properties
  • Relationship is the subject of another query
  • Multiple entities share the same connection context
  • You need to connect >2 entities in one fact

Relational → Graph Migration Table

Relational constructGraph equivalentNotes
Table rowNodeOne label per table (add more as needed)
Column (scalar)Node property
Primary keyUniqueness constraint propertyUse tmdbId, not id (too generic)
Foreign keyRelationshipDirection: from dependent → referenced
Many-to-many junction tableIntermediate nodeEspecially if junction has own columns
Junction table (no own columns)Direct relationshipSimpler; upgrade to intermediate node later
NULL FK (optional relation)Absent relationshipNo node created; absence is the signal
Polymorphic FK (Rails-style)Multiple labels or relationship typesSplit into type-specific rels
Self-referential FKSame-label relationship:Employee {managerId} → (e)-[:REPORTS_TO]->(m)
Audit/history columnsIntermediate versioning nodeSee References for versioning pattern

Supernode Detection and Mitigation

Detect:

// Find top-10 highest-degree nodes
MATCH (n)
RETURN labels(n) AS labels, elementId(n) AS id, count{ (n)--() } AS degree
ORDER BY degree DESC LIMIT 10

Node with degree >> median for its label = supernode candidate. Any node with >100K relationships will degrade traversal queries that pass through it.

Causes:

  • Domain supernodes: airports, celebrities, popular hashtags — unavoidable
  • Modeling supernodes: gender, country, status modeled as nodes with millions of edges — avoidable

Mitigation strategies (in priority order):

StrategyWhen to useImplementation
Query directionDirectional asymmetry existsQuery from low-degree side; exploit direction
Relationship type splitSupernode serves multiple roles:FOLLOWS + :FAN instead of single :RELATED_TO
Label segregationSupernode conflates entity types:Celebrity vs :User → query only relevant subtype
Bucket patternTime-series or high-volume event nodesSee below
Avoid modelingLow-cardinality categoricalsUse label instead of node (:Active not (:Status {name:"Active"}))
Join hintQuery tuning last resortUSING JOIN ON n in Cypher

Bucket pattern (time-series / high-volume):

// Instead of: (:User)-[:VIEWED]->(:Page) (millions of rels per user)
// Bucket by hour:
(u:User)-[:VIEWED_IN]->(b:ViewBucket {userId: u.id, hour: '2025-04-28T14'})-[:VIEWED]->(p:Page)

// Query last hour's views without traversing full history:
MATCH (u:User {id: $uid})-[:VIEWED_IN]->(b:ViewBucket {hour: $hour})-[:VIEWED]->(p)
RETURN p.url

Naming Conventions

ElementConventionGoodBad
Node labelPascalCase, singular noun:Person, :BlogPost:person, :blog_posts, :Entity

Use this skill in a project

Open any RiverX project, search the Skills panel for neo4j-contrib/neo4j-skills/neo4j-modeling-skill, and install it in one click.

Use this skill