Example: Company Structure
This example models an organization with departments, employees, reporting lines, skills, and management hierarchy.
Source: examples/company_structure.py.
Data Model
Nodes:
(:Company {name, founded, industry, size})(:Department {name, budget})(:Person:Employee {name, title, email, hire_date, salary})(:Skill {name})
Relationships:
(:Department)-[:PART_OF]->(:Company)(:Employee)-[:WORKS_IN {since}]->(:Department)(:Employee)-[:WORKS_AT {since}]->(:Company)(:Employee)-[:REPORTS_TO]->(:Employee)(:Department)-[:MANAGES]->(:Department)(:Employee)-[:HAS_SKILL {years}]->(:Skill)
Build the Graph
from grafito import GrafitoDatabase
db = GrafitoDatabase(":memory:")
techcorp = db.create_node(
labels=["Company"],
properties={"name": "TechCorp", "founded": 2010, "industry": "Technology", "size": "large"},
)
engineering = db.create_node(labels=["Department"], properties={"name": "Engineering", "budget": 5_000_000})
db.create_relationship(engineering.id, techcorp.id, "PART_OF")
Queries
Organizational Hierarchy
Department Headcount
Employees with a Skill
Reporting Chain
current = engineer1
while True:
managers = db.get_neighbors(current.id, direction="outgoing", rel_type="REPORTS_TO")
if not managers:
break
current = managers[0]
Try It
Run the full example: