Blog
Architecture
October 12, 20258 min

6-level hierarchical groups — the most complex feature of the project

Some features seem simple on paper. "Add groups" — sounds innocent. Then you start digging and realize you've just opened Pandora's box.

TAMSIV supports hierarchical groups up to 6 levels deep. My diving club, for example: Club → Technical Committee → Level 1 → Tuesday Group.

The data model

Each group has a parent_id that points to its parent group. To display the full tree, I use recursive queries (CTE) in PostgreSQL with a WHERE depth < 6 clause as a safeguard.

Four roles, four realities

  • Admin — do everything: create, modify, delete, manage members
  • Manager — manage tasks and memos, assign members
  • Member — create content, view all group content
  • Viewer — read-only

The trap is inheritance. If you are an admin of a parent group, are you automatically an admin of the subgroups? In TAMSIV, the answer is yes — but with nuances.

31 RLS policies

This is the number of Row Level Security policies I had to write for the collaborative schema. Testing 31 policies means at least 31 scenarios. Methodical, tedious, essential.

The HierarchicalGroupPicker component

On the frontend, I built a HierarchicalGroupPicker that displays the tree with indentation, role icons, and an "include subgroups" toggle. This is the feature that took me the most time. But it's also what makes TAMSIV usable for real organizations.