Hierarchy Service
Component Detail
Service Layer
high complexity
backend
0
Dependencies
0
Dependents
2
Entities
0
Integrations
Description
Backend service managing CRUD operations on organization_hierarchy_nodes using a Postgres adjacency list model with self-referential parent_id. Implements recursive CTE queries for subtree retrieval, circular reference prevention, and hierarchy-scoped access control enforcement.
hierarchy-service
Sources & reasoning
The adjacency list model requires backend logic for recursive CTE traversal that cannot run in the client. Circular reference prevention, depth-aware RBAC, and subtree-scoped data queries are non-trivial server-side concerns central to data integrity and Bufdir compliance.
No source references — this artifact was included based on reasoning alone (see above).
Responsibilities
- Create, update, move, and delete hierarchy nodes with circular reference validation
- Resolve full subtree for a given node via recursive Postgres CTE
- Enforce hierarchy-depth-aware access control (regional coordinator sees only own region's chapters)
- Route activity and reporting queries through correct organizational layer
- Validate multi-chapter membership (up to 5 per NHF member) via user_organization_roles
Interfaces
getSubtree(nodeId: string): Promise<HierarchyNode[]>
getAncestors(nodeId: string): Promise<HierarchyNode[]>
createNode(input: CreateNodeInput): Promise<HierarchyNode>
moveNode(nodeId: string, newParentId: string): Promise<HierarchyNode>
deleteNode(nodeId: string): Promise<void>
assignUserToNode(userId: string, nodeId: string, roleId: string): Promise<void>
getUserNodesForOrg(userId: string, organizationId: string): Promise<HierarchyNode[]>
checkCircularReference(nodeId: string, proposedParentId: string): Promise<boolean>
filterActivitiesBySubtree(nodeId: string, filters: ActivityFilter): Promise<Activity[]>
Related Data Entities (2)
Data entities managed by this component