Skip to main content

Find Dependencies

// Direct dependencies
MATCH (n {name: 'UserService'})-[:DEPENDS_ON]->(dep)
RETURN dep.name, dep.type

// Transitive dependencies (any depth)
MATCH (n {name: 'UserService'})-[:DEPENDS_ON*]->(dep)
RETURN DISTINCT dep.name, dep.type

Find Dependents

// What depends on this class?
MATCH (dependent)-[:DEPENDS_ON*]->(n {name: 'UserService'})
RETURN DISTINCT dependent.name, dependent.type

Shortest Path

// How are two classes connected?
MATCH path = shortestPath(
  (a {name: 'OrderController'})-[*]-(b {name: 'Database'})
)
RETURN path

Circular Dependencies

// Find cycles in the dependency graph
MATCH path = (n)-[:DEPENDS_ON*2..10]->(n)
RETURN path
LIMIT 10

Most Connected Nodes

// Potential god classes
MATCH (n {type: 'Class'})-[:DEPENDS_ON]->(dep)
RETURN n.name, count(dep) as dependencies
ORDER BY dependencies DESC
LIMIT 20

Orphan Classes

// Potentially dead code
MATCH (n {type: 'Class'})
WHERE NOT ()-[:DEPENDS_ON]->(n)
RETURN n.name, n.filePath

Namespace Contents

// All types in a namespace
MATCH (ns {type: 'Namespace', name: 'MyApp.Services'})-[:CONTAINS]->(type)
RETURN type.name, type.type

Inheritance Tree

// All classes that inherit from a base
MATCH (derived)-[:INHERITS*]->(base {name: 'BaseController'})
RETURN derived.name

Interface Implementations

// All implementations of an interface
MATCH (impl)-[:IMPLEMENTS]->(interface {name: 'IUserService'})
RETURN impl.name, impl.filePath

Method Calls

// What methods does this method call?
MATCH (m {name: 'CreateOrder'})-[:CALLS]->(called)
RETURN called.name, called.type

// What calls this method?
MATCH (caller)-[:CALLS]->(m {name: 'GetUser'})
RETURN caller.name, caller.type