omarchy
by
basecamp

Description: Beautiful, Modern & Opinionated Linux

View basecamp/omarchy on GitHub ↗

Summary Information

Updated 58 minutes ago
Added to GitGenius on September 30th, 2025
Created on June 1st, 2025
Open Issues/Pull Requests: 310 (+0)
Number of forks: 2,016
Total Stargazers: 20,395 (+0)
Total Subscribers: 121 (+0)
Detailed Description

Omarchy is a Ruby on Rails gem developed by Basecamp, designed to provide a simple yet powerful solution for managing hierarchical data within PostgreSQL databases. It offers an elegant `acts_as_omarchy` ActiveRecord extension, allowing developers to easily model and manipulate tree-like structures such as categories, comments, organizational charts, or file systems. Unlike many other hierarchical solutions that rely on complex nested sets or adjacency lists, Omarchy distinguishes itself by leveraging PostgreSQL's specialized `ltree` data type, promising both simplicity in implementation and high performance for common tree operations.

At its core, Omarchy's efficiency stems from its intelligent use of the `ltree` (label tree) extension available in PostgreSQL. Instead of maintaining multiple columns for parent-child relationships or complex left/right boundaries, Omarchy stores the entire path from the root to any given node in a single `path` column of type `ltree`. This path is represented as a sequence of labels, for example, `root.category1.subcategoryA`. The `ltree` data type comes with a rich set of operators and functions specifically optimized for querying hierarchical data, enabling extremely fast lookups for ancestors, descendants, siblings, and subtrees. This approach effectively combines the readability of a materialized path with the performance benefits of a specialized index, making complex tree traversals remarkably efficient.

Integrating Omarchy into a Rails model is straightforward, requiring just a call to `acts_as_omarchy`. Once configured, the model gains a comprehensive API for interacting with the hierarchy. Developers can easily determine relationships using methods like `root?`, `child?`, `parent?`, `ancestor?`, `descendant?`, and `sibling?`. Navigating the tree is equally simple with accessors such as `root`, `parent`, `children`, `ancestors`, `descendants`, and `siblings`. Beyond querying, Omarchy provides robust methods for manipulating the tree structure. Nodes can be re-parented using `move_to_child_of(parent)`, moved to the top level with `move_to_root`, or even reordered amongst their siblings using `move_to_left_of(sibling)` and `move_to_right_of(sibling)`. The gem also includes a `position` column to maintain a specific order among siblings, which can be re-calculated with `reorder_children!`.

To utilize Omarchy, a few prerequisites must be met. Firstly, it is exclusively designed for PostgreSQL databases, as its functionality is entirely dependent on the `ltree` extension. Therefore, the `ltree` extension must be enabled in the database (`CREATE EXTENSION ltree;`). Secondly, the database table for the hierarchical model needs to include two specific columns: `path` of type `ltree` and `position` of type `integer`. Omarchy provides a convenient migration helper, `t.omarchy`, which automatically adds these columns to the table, simplifying the setup process. The gem ensures that all structural changes, such as moving nodes, are wrapped in database transactions, guaranteeing data integrity.

Omarchy's primary advantages lie in its simplicity, performance, and robust feature set. The reliance on `ltree` makes hierarchical queries exceptionally fast, a critical factor for applications dealing with large or frequently accessed tree structures. Its API is intuitive and consistent with ActiveRecord conventions, reducing the learning curve for Rails developers. The transactional nature of its operations provides peace of mind regarding data consistency. Omarchy is ideally suited for a wide array of applications, including content management systems requiring nested categories or tags, forum software with threaded comments, e-commerce platforms with product hierarchies, or any application needing to represent and manage complex relationships in a clear, efficient, and scalable manner. By abstracting away the complexities of `ltree` and providing a clean Rails interface, Omarchy empowers developers to build sophisticated hierarchical features with minimal effort.

omarchy
by
basecampbasecamp/omarchy

Repository Details

Fetching additional details & charts...