# ClosureTree/closure_tree

Easily and efficiently make your ActiveRecord models support hierarchies

Repository: https://github.com/ClosureTree/closure_tree
Canonical: https://ross.abutalabs.com/products/closure_tree
Homepage: http://closuretree.github.io/closure_tree/
Language: Ruby
License: MIT
License Family: permissive
Topics: closure-tree, ruby, nested-hashes, tree-structure, rails, activerecord, ancestry, nested-set, hierarchy, hierarchies, descendants, parent, child
Last push: 2026-08-05T19:26:01+00:00

## Health v2 (maintenance only)
Score: 97/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 96, release rhythm 96, longevity 100
- inputs: {"age_days": 5586, "days_push": 28, "days_rel": 28, "gap_med": 30.0, "n_releases_24m": 11}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 1944, forks 248 (observed 2026-08-28T04:05:57.604838+00:00)

## What it is
A Ruby gem that lets ActiveRecord models act as nodes in a tree data structure using the closure table pattern. It provides highly efficient single-query reads and writes for hierarchical data like tags, threaded comments, and CMS page graphs.

## Use cases
- store hierarchical data like tags or categories in Rails
- model threaded comments with parent-child relationships
- fetch all descendants of a node in one query
- find or create a node by its ancestry path
- render tree structures as nested hashes or Graphviz DOT format
- manage user referral hierarchies

## When to choose
- you use ActiveRecord 7.2+ and need performant tree queries
- you need fast ancestor/descendant/sibling lookups in a single SELECT
- you need concurrency-safe hierarchy mutations
- you want STI support within a hierarchy

## When to avoid
- you are not using Ruby on Rails or ActiveRecord
- you need support for ActiveRecord versions older than 7.2
- your hierarchy is shallow and simple enough for a basic parent_id column
- you use a database other than MySQL, PostgreSQL, or SQLite

## Facets
- artifact type: library
- maturity: active
- function: orm, database, data-science
- domain: databases, web-development, developer-tools
- platform: ruby, jvm
- tags: activerecord, closure-table, tree-structure, hierarchy, rails, nested-hashes, ancestry, nested-set

## Member repositories
- ClosureTree/closure_tree (main) score 97

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:05:57.604838+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T03:07:59.580400+00:00, confidence not recorded.
  - readme: https://github.com/ClosureTree/closure_tree (fetched 2026-08-28T04:05:57.604838+00:00, sha 51bb47e34d32)
  - homepage: http://closuretree.github.io/closure_tree/ (fetched 2026-08-29T10:46:59.780293+00:00, sha 4436b823ec60)
- Data as of 2026-08-30T08:39:29.467469+00:00.
