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/slices/create-slice/

name:
create-slice
license:
MIT
description:
Use when creating and configuring Slices in Hanami 2.x, including running `hanami generate slice`, registering slices as modular sub-containers, configuring slice routes, setting up inter-slice dependencies with import/export, and structuring a modular architecture with bounded contexts. Covers slice directory generation, route configuration, cross-slice dependency management, and slice-level container access. Use when building a sub-application, isolating a bounded context, or wiring slice dependencies in a Hanami 2.x project.
metadata:
{"ecosystem_sources":["hanami/hanami","dry-rb/dry-system"],"tags":["slices","modules","bounded-contexts","containers"],"version":"1.0.0"}

create-slice

Use this skill when creating and configuring Hanami 2.x Slices.


Quick Reference

ScenarioApproach
Create a Slicehanami generate slice <name>
Register a SliceAdd to config/app.rb with slice :name, at: "/path"
Define Slice routesCreate slices/<name>/config/routes.rb
Access Slice ActionsRoutes point to slice_name.action_name
Import from another SliceUse import in the Slice class or app config
Export from a SliceUse export in the Slice class
Slice-level containerMyApp::Slices::Api::Container
Access Slice componentsinclude Deps["slices.api.repositories.users"]

Core Rules

  1. Generate a Slice using the Hanami CLI:

    hanami generate slice api

    Creates slices/api/ with subdirectories including config/routes.rb, actions/, views/, and templates/.

    Verify: Run hanami routes and confirm the new slice's routes appear in the output.

  2. Register the Slice in the app:

    # config/app.rb
    # frozen_string_literal: true
    
    module MyApp
      class App < Hanami::App
        slice :api, at: "/api" do
          # Slice-specific configuration
        end
      end
    end
  3. Define Slice routes in slices/<name>/config/routes.rb:

    # slices/api/config/routes.rb
    # frozen_string_literal: true
    
    module MyApp
      module Slices
        module Api
          class Routes < Hanami::Routes
            get "/users", to: "users.index"
            get "/users/:id", to: "users.show"
          end
        end
      end
    end

    Verify: Run hanami routes and confirm /api/users and /api/users/:id are listed.

  4. Access Slice Actions from routes:

    # Full path: /api/users → slices/api/actions/users/index.rb
  5. Import dependencies from another Slice:

    # config/app.rb
    module MyApp
      class App < Hanami::App
        slice :api, at: "/api" do
          import from: :main do
            # Import specific components from the main slice
          end
        end
      end
    end

    Verify: Boot the app (hanami console) and resolve the imported component: MyApp::Slices::Api::Container["main.repositories.users"].

  6. Export Slice components for use by other slices:

    # slices/api/config/slice.rb
    module MyApp
      module Slices
        module Api
          class Slice < Hanami::Slice
            export ["repositories.users"]
          end
        end
      end
    end

    Verify: In hanami console, confirm the consuming slice can resolve the exported key.

  7. Keep Slices self-contained. A Slice should be able to function independently. Minimize cross-slice dependencies.

  8. Use Slices for bounded contexts — common examples include slice :api for public endpoints, slice :admin for dashboards, slice :billing for payments, and slice :main for the default web application.


Common Mistakes

  • Circular slice dependencies: Slices should be acyclic. If Slice A imports from Slice B, Slice B must not import from Slice A.
  • Direct container access across slices: Use import/export for cross-slice communication. Never access Hanami.app["slices.other.component"] directly.
  • Misaligned namespaces: Slice components live under MyApp::Slices::Api::. File paths and module namespaces must align.

Integration

Related SkillWhen to chain
define-routesSlices define their own routes. Master routes before creating slices.
inject-dependenciesCross-slice dependencies use import/export and are injected via Deps.
configure-sliceConfigure slice-level settings and providers after creating the slice.
create-new-slice (workflow)Full workflow for creating and configuring a new slice.

skills

slices

create-slice

README.md

tile.json