hierarchy
Generic tree structure with parent-child relationships
Hierarchy enables components to build tree structures with parent-child relationships. It provides circular reference prevention, archive cascade to descendants, and position-based sibling ordering. Use for container hierarchies, folder structures, or any nested organizational model.
1
Ports
1
Schemas
0
Hooks
4
Events
01
Ports
02
Schemas
Defines
Uses
No external schemas used
03
Hooks
No hooks declared
04
Events
- NodeArchived v1
- NodeUnarchived v1
- NodeMoved v1
- SiblingsReordered v1
05
Stories
06
Examples
from psp.platform.hierarchy import InMemoryHierarchyTree, HierarchyReaderPort
class ContainerRepository:
def __init__(self, hierarchy: HierarchyReaderPort):
self._hierarchy = hierarchy
def get_breadcrumb(self, container_id: UUID) -> list[str]:
ancestors = self._hierarchy.get_ancestors(
container_id, include_self=True
)
return [self._get_name(a.id) for a in reversed(ancestors)]
Use hierarchy for task container organization.
tree = InMemoryHierarchyTree(max_depth=10)
# Create folder structure
root = uuid4()
tree.register_node(root)
documents = uuid4()
tree.register_node(documents, parent_id=root)
# Get depth
depth = tree.get_depth(documents)
print(f"Depth: {depth}") # 1
Organize documents in nested folders.
from psp.platform.hierarchy import InMemoryHierarchyTree
tree = InMemoryHierarchyTree()
# Archive subtree
archived_ids = tree.archive_subtree(container_id)
# Get and publish events
for event in tree.pop_events():
print(f"Event: {type(event).__name__} for {event.node_id}")
Publish events after archiving a subtree.
API Reference
This component mounts routes under /v1/hierarchy.
View OpenAPI specification