Understand Anything Knowledge Graph Schema: Complete Guide to Node and Edge Types
The Understand Anything knowledge graph schema defines 21 distinct node types and 35 edge types organized into 9 functional categories, all enforced through Zod schemas in packages/core/src/schema.ts.
The Egonex-AI/Understand-Anything repository implements a strict, type-safe knowledge graph schema that powers its AI-driven code understanding engine. This schema standardizes how software artifacts, infrastructure components, and business concepts interconnect within a unified graph structure. All type definitions reside in the core package and are validated using Zod to ensure data integrity across the entire platform.
Node Types in the Understand Anything Schema
The GraphNodeSchema.type field (lines 69–76 of packages/core/src/schema.ts) enumerates the canonical node categories. These nodes represent entities ranging from source code files to abstract business concepts.
Core Software Artifacts
These node types model traditional codebases and programming constructs:
file– A source-code file within the repositoryfunction– A function or method definitionclass– A class or interface declarationmodule– A package or module boundary
Infrastructure and Data Components
These nodes capture deployment artifacts, data stores, and configuration:
service– Deployable units such as containers or podstable– Database tables and persistent storage structuresendpoint– API routes, GraphQL queries, or mutationspipeline– CI/CD workflows or data processing jobsschema– Data schemas including Protobuf, JSON Schema, or OpenAPI definitionsresource– Cloud infrastructure resources managed by Terraform or similar toolsconfig– Configuration values and environment settings
Business and Knowledge Concepts
These types bridge technical implementation with domain knowledge:
concept– Abstract ideas or patternsdomain– Business domain boundariesflow– Business process flowsstep– Individual steps within a business flowarticle– Knowledge base articles and documentationentity– Real-world entities such as persons or organizationstopic– Subject tags or categorical labelsclaim– Assertions, decisions, or hypothesessource– External references to papers, links, or citationsdocument– Documentation files such as READMEs
Edge Types and Relationship Categories
The EdgeTypeSchema (lines 4–14 of packages/core/src/schema.ts) defines 35 edge verbs that describe relationships between nodes. The engine groups these into functional categories to distinguish structural, behavioral, and semantic connections.
Structural Relationships
These edges define code hierarchy and composition:
contains– Parent-child containment (e.g., a file contains functions)importsandexports– Module dependency relationshipsinherits– Class inheritance hierarchiesimplements– Interface implementation
Behavioral and Data Flow Connections
These edges capture runtime interactions and data movement:
calls– Function-to-function invocationsubscribesandpublishes– Event-driven relationshipsmiddleware– Middleware chain connectionsreads_fromandwrites_to– Data access patternstransformsandvalidates– Data processing pipelines
Infrastructure and Domain Mapping
These edges connect technical implementation to deployment and business context:
depends_on,tested_by,configures– Dependency and testing relationshipsdeploys,serves,provisions,triggers– Infrastructure lifecycle eventsmigrates,documents,routes,defines_schema– Schema evolution and documentationcontains_flow,flow_step,cross_domain– Business process modelingrelated,similar_to– Semantic similarity linkscites,contradicts,builds_on,exemplifies,categorized_under,authored_by– Knowledge graph citations and authorship
Working with the Schema in Code
The @understand-anything/core package exports GraphNodeSchema and GraphEdgeSchema for runtime validation and TypeScript type inference.
import { GraphNodeSchema, GraphEdgeSchema } from '@understand-anything/core';
// Create a validated function node
const fnNode = GraphNodeSchema.parse({
id: 'node-123',
type: 'function',
name: 'calculateSum',
filePath: 'src/math.ts',
summary: 'Adds two numbers',
tags: ['math', 'utility'],
complexity: 'simple',
});
// Create an edge representing a function call
const callEdge = GraphEdgeSchema.parse({
source: 'node-123',
target: 'node-456',
type: 'calls',
direction: 'forward',
weight: 0.8,
});
The engine automatically normalizes common aliases to canonical values. For example, type: 'func' normalizes to 'function', and type: 'invoke' normalizes to 'calls'.
import { normalizeGraph, validateGraph } from '@understand-anything/core';
const raw = {
nodes: [{ id: 'n1', type: 'func', name: 'doWork', summary: '', tags: [], complexity: 'easy' }],
edges: [{ source: 'n1', target: 'n2', type: 'invoke', direction: 'to', weight: 1 }],
};
const { data, issues } = validateGraph(normalizeGraph(raw));
// Normalized: type becomes 'function', edge type becomes 'calls', direction becomes 'forward'
Validation and Normalization
The schema enforcement layer resides in packages/core/src/schema.ts alongside packages/core/src/types.ts, which exports TypeScript interfaces derived from the Zod schemas. The normalizeGraph function sanitizes input data by mapping legacy or shorthand aliases to the strict enum values defined in the schema. This ensures that all graph data conforms to the 21 node types and 35 edge types before the validation engine processes relationships.
Summary
- The Understand Anything knowledge graph schema strictly defines 21 node types spanning code, infrastructure, and business domains in
packages/core/src/schema.ts. - 35 edge types categorize relationships into structural, behavioral, data flow, and semantic groups.
- The Zod-based validation system enforces schema compliance and automatically normalizes aliases like
functofunctionorinvoketocalls. - Type definitions are exported from
packages/core/src/types.tsfor consumption across the plugin ecosystem.
Frequently Asked Questions
What file contains the knowledge graph schema definitions?
The canonical schema definitions reside in packages/core/src/schema.ts within the understand-anything-plugin package. This file exports GraphNodeSchema, EdgeTypeSchema, and related Zod validators that enforce the 21 node types and 35 edge types.
How many node and edge types does the schema support?
The schema defines 21 distinct node types ranging from file and function to concept and claim, plus 35 edge types organized into 9 functional categories including structural, behavioral, and knowledge relationships.
Can I use custom node types beyond the defined enums?
No, the schema uses strict Zod enums that reject unknown types during validation. However, the normalization layer in normalizeGraph maps common aliases (like func to function) to the canonical enums, allowing flexibility in input while maintaining strict type safety in the graph.
How does the schema handle edge directionality?
The GraphEdgeSchema includes a direction field that accepts 'forward' or 'backward' values. During normalization, directional aliases like 'to' are automatically mapped to 'forward', ensuring consistent traversal semantics across the knowledge graph.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →