ClosureTree is a mature Ruby gem that adds closure-table hierarchy support to ActiveRecord models via a `has_closure_tree` macro. It maintains a separate `_hierarchies` table storing ancestor/descendant pairs with generation depth, enabling O(1) SELECTs for ancestors, descendants, siblings, leaves, and roots. The gem handles the full lifecycle: node creation inserts a self-referencing row plus copies of the parent's ancestor rows (2 INSERTs), reparenting rebuilds the affected hierarchy, and destruction cleans up references with configurable dependent behavior (nullify, adopt, destroy, delete_all). It supports STI, UUID primary keys, deterministic numeric ordering with preorder traversal, scoped multi-tenant trees, PostgreSQL schema-qualified tables, and multi-database setups (PostgreSQL/MySQL/SQLite simultaneously). Concurrency safety is provided through the with_advisory_lock gem with customizable lock names and per-instance lock granularity for multi-tenant use cases. The architecture is notably clean: a `ClosureTree::Support` instance (`_ct`) encapsulates all implementation details to avoid polluting the host model's namespace, and focused mixins (Finders, HashTree, Digraphs, DeterministicOrdering, HierarchyMaintenance) are composed by the `has_closure_tree` entry point. The code demonstrates sophisticated cross-database SQL engineering — MySQL uses user variables for gap-free sibling reordering, PostgreSQL uses window functions, and Arel query builders handle adapter-specific quoting. The test suite is exceptional: it runs against Ruby 3.4/4.0, Rails 7.2 through edge, and all three database engines, with concurrency tests, query-count assertions, and shared example suites for both integer and UUID primary keys. The gem is actively maintained with release-please automation, semantic versioning, and a detailed changelog spanning over a decade of development.
d3-flame-graph is a D3.js library for creating interactive flame graphs from hierarchical data. It follows the D3 chart pattern with a closure-based factory function that returns a configurable chart function. The library processes JSON input data representing call stacks or hierarchies and renders them as SVG flame graphs with features like zoom, search, tooltips, and click/hover handlers. It includes specialized color mappers for different profiling contexts (allocation, off-CPU, Node.js, differential) and a smart tooltip component that handles boundary conditions. The architecture is modular with separate concerns for color mapping, tooltip handling, and core layout logic.
@antv/hierarchy is a TypeScript library providing layout algorithms for visualizing hierarchical data. It implements four primary layout types: compact box, dendrogram, indented, and mindmap layouts. The library takes tree-structured data as input and returns positioned nodes with x/y coordinates for rendering. Built with a modular architecture, it separates core tree construction from layout algorithms and directional handling, enabling clean extension and customization. The package is published as an ES module with UMD fallback and includes comprehensive type definitions.
sqlalchemy_mptt is a Python library that provides SQLAlchemy mixins for implementing Modified Preorder Tree Traversal (MPTT) with SQLAlchemy models. It automatically maintains tree structure through SQLAlchemy event listeners, handling insert, update, and delete operations while preserving tree integrity. The library supports multi-tree scenarios, various primary key types, and provides methods for tree traversal, drilldown operations, and path-to-root queries. The architecture centers around the BaseNestedSets mixin class that adds tree-specific columns and methods to SQLAlchemy models, complemented by a TreesManager that handles SQLAlchemy events to automatically maintain lft, rgt, level, and tree_id attributes. The library demonstrates strong engineering practices with a compatibility layer for SQLAlchemy versions, comprehensive test suite, and active maintenance with recent support for SQLAlchemy 2.0 and modern Python versions.
react-sortable-tree is a React component library that provides a drag-and-drop sortable tree view for hierarchical data. It renders nested arrays of nodes with expand/collapse, virtualization via react-virtualized, search with highlighting, theming, and extensive callback hooks for move and visibility changes. The library is not actively maintained; the last release was in 2020, and the README explicitly disclaims maintenance. The codebase is well-architected with clean separation of concerns: pure tree-data utility functions (walk, map, insertNode, etc.) separated from React rendering, a DndManager class that wraps react-dnd, and a theming system. Despite its staleness, the core tree manipulation algorithms are high-quality and extractable for other projects. The library depends on outdated versions of React (16) and react-dnd (11), and uses react-virtualized instead of the more modern react-window.