CtrlK
BlogDocsLog inGet started
Tessl Logo

igmarin/hanakai-yaku

Curated library of atomic AI agent skills for Hanami, dry-rb, and ROM Ruby development. Covers actions, slices, repositories, relations, changesets, providers, DI, operations, TDD, CLI, views, routing, and validation. Shared Ruby process skills have moved to ruby-core-skills. Uses Markdown + Front-matter architecture.

92

1.33x
Quality

94%

Does it follow best practices?

Impact

92%

1.33x

Average score across 35 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

SKILL.mdskills/db/create-repository/

name:
create-repository
license:
MIT
description:
Use when creating ROM Repositories in Hanami 2.x, including CRUD operations, defining custom queries, configuring associations, setting up aggregate roots, entity mapping, transaction handling, and implementing the Repository as your domain persistence layer. Relevant for database access, rom-rb relations, sequel adapter setup, and wiring repositories into actions via dependency injection.
metadata:
{"ecosystem_sources":["rom-rb/rom","rom-rb/rom-sql","hanami/hanami-db"],"tags":["db","rom","repositories","persistence"],"version":"1.0.0"}

create-repository

Use this skill when creating ROM Repositories that encapsulate domain-level persistence logic in Hanami 2.x.


Quick Reference

ActionApproach
Create RepositoryInherit from Hanami::DB::Repo[:relation_name]
Inject Repositoryinclude Deps["repos.user_repo"]
Execute transactionrepo.transaction { ... } (details in REPOSITORIES.md)

Core Rules

  1. Create the Repository file: Place repositories under app/repos/:

    # app/repos/user_repo.rb
    module MyApp
      module Repos
        class UserRepo < Hanami::DB::Repo[:users]
        end
      end
    end
  2. Inject into Actions: Inject repositories using the container dependency injection (Deps):

    # app/actions/users/index.rb
    class Index < MyApp::Action
      include Deps["repos.user_repo"]
    
      def handle(request, response)
        response.render(view, users: user_repo.all)
      end
    end
  3. Add domain methods: Write specific read and write methods to isolate your actions from raw relation access:

    def active
      users.active.to_a
    end
    
    def find_by_email(email)
      users.by_email(email).one
    end
  4. Use transactions for multi-step writes: Wrap mutations in transaction blocks. For details and Failure result handling, see REPOSITORIES.md.

    transaction do
      accounts.update(from_id, balance: from_account.balance - amount)
      accounts.update(to_id,   balance: to_account.balance + amount)
    end
  5. Map to custom Entities: Configure the struct_namespace to automatically map SQL relation rows to custom Entity domain models. See REPOSITORIES.md.

    class UserRepo < Hanami::DB::Repo[:users]
      struct_namespace MyApp::Entities
      auto_struct true
    end
  6. Do not expose Relations directly: Actions must fetch and modify data via Repositories. Bypassing repositories to query relations directly in actions/views is an anti-pattern.


Integration

Related SkillWhen to chain
define-relationdefine-relation — Relations map table schemas before repositories query them.
define-entitydefine-entity — Represents the struct objects returned by the repository.
create-actionActions inject repositories to read/write data.
write-rom-specTest repository methods inside in-memory ROM database specs.

skills

README.md

tile.json