CtrlK
BlogDocsLog inGet started
Tessl Logo

igmarin/hanakai-yaku

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

95

1.20x
Quality

95%

Does it follow best practices?

Impact

96%

1.20x

Average score across 45 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

SKILL.mdskills/slices/create-slice/

name:
create-slice
license:
MIT
type:
atomic
description:
Use when creating Hanami Slices — generate a slice with `hanami generate slice [name]`, register it in `config/app.rb` via `slice :name, at: "/path"`, define slice routes in `slices/[name]/config/routes.rb`, configure inter-slice dependencies with `import`/`export` (avoid circular deps: if A imports from B, B must not import from A), and keep slices self-contained for distinct bounded contexts like API, admin, or billing, the main web application. Covers slice directory generation, route configuration, cross-slice dependency management, and slice-level container access.
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
    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
    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

    Routes map to action files under slices/api/actions/ (e.g. /api/usersslices/api/actions/users/index.rb).

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

  4. 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"].

  5. 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.

  6. Keep Slices self-contained and minimize cross-slice dependencies. Use import/export as the formal contract between slices.

  7. Use Slices for bounded contexts — each slice encapsulates a distinct domain concern such as a public API, admin dashboard, billing, or main 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