NomikNomik

Graph Schema

Complete reference for Nomik's Neo4j graph schema — 17 node types, 19 edge types, properties, constraints, indexes, and Cypher query examples.

All nodes and edges carry a projectId property for multi-project isolation in a single Neo4j database.

Node Types (17)

Graph Node and Edge Schema Map

Code Nodes

LabelKey PropertiesDescription
Filepath, language, hash, size, lineCount, lastParsedSource file
Functionname, filePath, startLine, endLine, params, returnType, isAsync, isExported, isGenerator, decorators, confidence, bodyHashFunction or method
Classname, filePath, startLine, endLine, isExported, isAbstract, superClass, interfaces, decorators, methods, properties, bodyHashClass or interface
Variablename, filePath, line, kind (const/let/var), isExported, valueTypeTop-level variable or constant
Modulename, path, moduleType (file/package/external)Logical module

API Nodes

LabelKey PropertiesDescription
Routemethod, path, handlerName, filePath, middleware, apiTags, apiSummary, apiDescription, apiResponseStatusHTTP endpoint with optional Swagger/OpenAPI metadata
ExternalAPIname, baseUrl, methodsExternal API (Stripe, AWS, etc.)

Data Nodes

LabelKey PropertiesDescription
DBTablename, schema, operationsDatabase table reference
DBColumnname, table, typeDatabase column
EnvVarname, required, defaultValueEnvironment variable

Infrastructure Nodes

LabelKey PropertiesDescription
QueueJobname, queueName, filePath, jobKind (producer/consumer)Job queue task (Bull/BullMQ/Bee-Queue/Agenda/pg-boss)
Metricname, metricType (counter/gauge/histogram/summary), help, filePathPrometheus/OpenTelemetry metric
Spanname, spanKind (server/client/producer/consumer/internal), attributes, filePathOpenTelemetry tracing span
Topicname, broker (kafka/rabbitmq/nats/sqs/sns/pubsub), topicKind (producer/consumer), filePathMessage broker topic/queue
Eventname, eventKind (emit/listen), filePath, namespace, roomEvent bus with Socket.io room/namespace support
CronJobname, schedule, handlerName, filePathScheduled task
SecurityIssuetype, severity, descriptionSecurity finding

Meta Nodes

LabelKey PropertiesDescription
Projectid, name, rootPath, createdAt, updatedAtProject root (no projectId — its id serves as the project identifier)
ScanMetasha, shortSha, message, author, gitDate, scannedAt, fileCount, nodeCount, edgeCountScan metadata per commit

Edge Types (19)

All edges carry a projectId property for multi-project isolation.

Code Relationships

TypeFrom → ToPropertiesDescription
CONTAINSFile → Function/Class/VariableFile defines this symbol
IMPORTSFile → Modulespecifiers, isDefault, isDynamicFile imports from module
EXPORTSModule → Function/Class/VariableisDefault, aliasModule exports this symbol
CALLSFunction → Functionline, columnFunction invocation
DEPENDS_ONFunction → Modulekind (import/call/http/event/env)Dependency relationship
EXTENDSClass → ClassClass inheritance
IMPLEMENTSClass → ClassInterface implementation

Data Relationships

TypeFrom → ToPropertiesDescription
READS_FROMFunction → DBTablequeryDatabase read operation
WRITES_TOFunction → DBTableoperationDatabase write operation
USES_ENVFunction → EnvVarEnvironment variable usage

API Relationships

TypeFrom → ToPropertiesDescription
HANDLESRoute → FunctionmiddlewareRoute handler binding
CALLS_EXTERNALFunction → ExternalAPImethod, endpointExternal API call

Infrastructure Relationships

TypeFrom → ToPropertiesDescription
TRIGGERSCronJob → FunctionscheduleCron triggers the function
EMITSFunction → EventpayloadEvent emission
LISTENS_TOFunction → EventhandlerEvent subscription
PRODUCES_JOBFunction → QueueJobjobNameFunction enqueues a job
CONSUMES_JOBFunction → QueueJobjobNameFunction processes a job
USES_METRICFunction → Metricoperation (inc/dec/set/observe/startTimer/define)Function uses a metric
STARTS_SPANFunction → SpanspanNameFunction starts a tracing span
PRODUCES_MESSAGEFunction → TopictopicNameFunction publishes to a message broker
CONSUMES_MESSAGEFunction → TopictopicNameFunction consumes from a message broker

Cypher Examples

Impact Analysis

What breaks if I modify processPayment?
MATCH (target)
WHERE (target.name = $name OR target.id = $name)
  AND target.projectId = $projectId
WITH target LIMIT 1
CALL apoc.path.subgraphNodes(target, {
  relationshipFilter: "<CALLS|<HANDLES|<TRIGGERS|<DEPENDS_ON|<LISTENS_TO",
  maxLevel: $maxDepth
}) YIELD node
WHERE node <> target AND node.projectId = $projectId
RETURN COALESCE(node.name, node.path) as name,
       labels(node)[0] as type,
       COALESCE(node.filePath, node.path) as filePath

Dead Code Detection

Functions never called
MATCH (f:Function)
WHERE NOT (f)<-[:CALLS]-() AND NOT (f)<-[:HANDLES]-()
  AND f.name <> 'constructor'
  AND f.projectId = $projectId
WITH f
WHERE NOT f.filePath ENDS WITH '.tsx'
  AND NOT f.filePath ENDS WITH '.jsx'
OPTIONAL MATCH (parent:File)-[:CONTAINS]->(f)
WITH f, parent
WHERE parent IS NULL
   OR (NOT parent.path ENDS WITH 'index.ts'
       AND NOT parent.path ENDS WITH 'index.js')
OPTIONAL MATCH (parent)-[:CONTAINS]->(cls:Class)
WHERE cls.methods CONTAINS ('"' + f.name + '"')
WITH f, cls
WHERE cls IS NULL
RETURN f.name as name, f.filePath as filePath

Duplicate Code Detection

Functions with identical bodyHash
MATCH (f:Function)
WHERE f.bodyHash IS NOT NULL AND f.projectId = $projectId
  AND (f.endLine - f.startLine) >= 3
WITH f.bodyHash as bodyHash,
     collect({name: f.name, filePath: f.filePath}) as funcs,
     count(*) as cnt
WHERE cnt > 1
RETURN bodyHash, cnt as count, funcs as functions
ORDER BY cnt DESC

Circular Dependency Detection

Circular imports between modules
MATCH cycle = (a:Module)-[:IMPORTS*2..6]->(a)
WHERE a.projectId = $projectId
RETURN [n IN nodes(cycle) | n.name] as cyclePath

Constraints and Indexes

Uniqueness Constraints

CREATE CONSTRAINT file_id IF NOT EXISTS FOR (f:File) REQUIRE f.id IS UNIQUE;
CREATE CONSTRAINT function_id IF NOT EXISTS FOR (f:Function) REQUIRE f.id IS UNIQUE;
CREATE CONSTRAINT class_id IF NOT EXISTS FOR (c:Class) REQUIRE c.id IS UNIQUE;
CREATE CONSTRAINT route_id IF NOT EXISTS FOR (r:Route) REQUIRE r.id IS UNIQUE;
CREATE CONSTRAINT module_id IF NOT EXISTS FOR (m:Module) REQUIRE m.id IS UNIQUE;
CREATE CONSTRAINT variable_id IF NOT EXISTS FOR (v:Variable) REQUIRE v.id IS UNIQUE;
CREATE CONSTRAINT project_id IF NOT EXISTS FOR (p:Project) REQUIRE p.id IS UNIQUE;

Search Indexes

CREATE INDEX file_path IF NOT EXISTS FOR (f:File) ON (f.path);
CREATE INDEX function_name IF NOT EXISTS FOR (f:Function) ON (f.name);
CREATE INDEX function_filepath IF NOT EXISTS FOR (f:Function) ON (f.filePath);
CREATE INDEX class_name IF NOT EXISTS FOR (c:Class) ON (c.name);
CREATE INDEX route_path IF NOT EXISTS FOR (r:Route) ON (r.path);

Project Isolation Indexes

CREATE INDEX file_project IF NOT EXISTS FOR (f:File) ON (f.projectId);
CREATE INDEX function_project IF NOT EXISTS FOR (f:Function) ON (f.projectId);
CREATE INDEX class_project IF NOT EXISTS FOR (c:Class) ON (c.projectId);
CREATE INDEX module_project IF NOT EXISTS FOR (m:Module) ON (m.projectId);
CREATE INDEX route_project IF NOT EXISTS FOR (r:Route) ON (r.projectId);
CREATE INDEX variable_project IF NOT EXISTS FOR (v:Variable) ON (v.projectId);

All constraints and indexes are auto-initialized on startup via schema/init.ts.