Skip to main content
Version: 0.3.0

Relationship Pattern Templates

This section provides comprehensive templates and examples for common relationship patterns in graph databases using ageSchemaClient. These patterns help you model complex data relationships efficiently and leverage the power of graph databases.

Pattern Categories

Parent-Child Relationships

Hierarchical data modeling approaches for tree-like structures such as:

  • Organizational hierarchies
  • Category taxonomies
  • File system structures
  • Family trees

Product-Part Relationships

Bill of materials and component hierarchy patterns for:

  • Manufacturing assemblies
  • Software component dependencies
  • Recipe ingredients
  • System architectures

One-to-Many Property Relationships

Attribute modeling strategies for:

  • User preferences and settings
  • Product attributes and specifications
  • Contact information
  • Configuration parameters

Pattern Selection Guide

Use CasePatternBest For
Organizational structureParent-ChildClear hierarchies with single parent
Product assemblyProduct-PartComplex multi-level compositions
User attributesOne-to-Many PropertiesFlexible attribute systems
Social networksMany-to-ManyBidirectional relationships
WorkflowsSequentialProcess flows and state machines

Common Design Principles

1. Vertex vs Edge Properties

  • Vertex properties: Intrinsic attributes of entities
  • Edge properties: Relationship metadata (dates, weights, types)

2. Relationship Direction

  • Outgoing: Natural flow direction (parent → child)
  • Bidirectional: Mutual relationships (friendship)
  • Incoming: Reverse lookups (child → parent)

3. Performance Considerations

  • Index frequently queried properties
  • Consider denormalization for read-heavy patterns
  • Use batch loading for large datasets
  • Optimize traversal patterns

Schema Design Best Practices

Consistent Naming

// Use consistent naming conventions
const schema = {
vertices: {
Employee: { /* properties */ },
Department: { /* properties */ }
},
edges: {
REPORTS_TO: { from: 'Employee', to: 'Employee' },
BELONGS_TO: { from: 'Employee', to: 'Department' }
}
};

Property Validation

// Define clear property constraints
const vertexDefinition = {
properties: {
id: { type: 'string', required: true },
name: { type: 'string', required: true },
created_at: { type: 'string' },
active: { type: 'boolean', default: true }
},
required: ['id', 'name']
};

Relationship Multiplicity

// Document relationship cardinality
const edgeDefinition = {
from: 'Employee',
to: 'Department',
multiplicity: 'many-to-one', // Many employees belong to one department
properties: {
role: { type: 'string' },
start_date: { type: 'string' }
}
};

Next Steps

  1. Choose a Pattern: Select the pattern that best fits your use case
  2. Review Examples: Study the provided code examples and diagrams
  3. Adapt Schema: Modify the templates for your specific domain
  4. Test Queries: Validate your design with representative queries
  5. Optimize Performance: Apply indexing and query optimization techniques

Each pattern section includes:

  • Conceptual overview and use cases
  • Schema definitions with TypeScript types
  • Bulk loading examples
  • Common query patterns
  • Performance optimization tips
  • Real-world examples and variations