Hierarchy Service
Component Detail
Service Layer
high complexity
backend
1
Dependencies
1
Dependents
5
Entities
0
Integrations
Description
Backend service managing the organizational hierarchy using a closure table pattern in PostgreSQL. Provides efficient ancestor/descendant queries, node creation, node movement between parents, and scoped data aggregation for reports. Enforces row-level security based on the user's JWT organization scope claim.
hierarchy-service
Responsibilities
- Query organization hierarchy using closure table for efficient ancestor/descendant lookups
- Create, update, and move organizations within the hierarchy tree
- Enforce row-level security policies based on user JWT organization scope
- Aggregate statistics from child organizations into parent-level rollups using materialized views
- Validate hierarchy constraints to prevent circular references and orphaned nodes
Interfaces
getHierarchy(orgId): HierarchyTree
getAncestors(orgId): Organization[]
getDescendants(orgId): Organization[]
createChildOrganization(parentOrgId, orgData): Organization
moveOrganization(orgId, newParentOrgId, position): Organization
updateOrganization(orgId, updates): Organization
deleteOrganization(orgId): void
getAggregateStats(orgId): AggregateStats
refreshMaterializedViews(): void
validateHierarchyIntegrity(): ValidationResult
getScopedOrganizations(userScope): Organization[]
isAncestorOf(ancestorId, descendantId): boolean
Relationships
Related Data Entities (5)
Data entities managed by this component