$ show samvera/hyrax
Hyrax is a Ruby on Rails engine for building digital repository applications, part of the Samvera community. It provides core functionality for managing scholarly works, collections, file sets, and administrative sets with full lifecycle support: ingest, metadata management, access control (permissions, embargoes, leases), workflow (mediated deposit), analytics (GA4, Matomo), IIIF manifests, fixity checking, and derivatives generation. The architecture is a monolith with a modular actor middleware stack (chain of responsibility) for work creation/update/destroy, dry-transaction steps for resource operations, and a pub/sub event system for decoupled side effects. It supports dual persistence via ActiveFedora (Fedora) and Valkyrie (PostgreSQL, Fedora 6), with migration infrastructure (Wings, Freyja) and a Solr indexing layer. Key entry points include Rails controllers (Blacklight-based search, admin dashboard, API), the actor stack, and transaction steps. The codebase is heavily engineered with reusable patterns but carries significant technical debt from the ongoing migration to Valkyrie, deprecation warnings, and conditional code paths.
The LLM identified 5 files worth highlighting for reuse:
Bottom of the actor middleware stack for work creation, update, and destruction. Handles persistence via Valkyrie or ActiveFedora, publishing events, and managing file sets. The actor pattern is a clean separation of concerns and is reusable across any Rails application needing composable lifecycle operations.
Collection of dry-monad transaction steps (e.g., SaveAccessControl, DeleteResource, AddFileSets) that implement business logic for resource creation, update, deletion, and permission management. These steps are self-contained, testable, and can be reordered or reused in different workflows.
Valkyrie custom query for finding child works of a given resource. Demonstrates the pattern of encapsulating Solr or persistence queries in a dedicated class with a `self.queries` declaration and `find_references` method. This pattern is easily extracted and reused in other Valkyrie-based Rails applications.
Event publisher using dry-events. Emits events like 'object.metadata.updated' and 'object.acl.updated' that are consumed by listeners (e.g., MetadataIndexListener, WorkflowListener). This decouples side effects from core business logic and is a clean, reusable pattern for any Rails app needing event-driven architecture.
Concern that normalizes hash-based compound metadata (e.g., nested attribute pairs) from the database representation into a consistent array structure. Handles the asymmetry between ActiveFedora and Valkyrie storage. This pattern is reusable for any application that needs to normalize complex nested attributes from persistence to application layer.