Kabk Logo

Gem Version License: MIT

Kabk carries the Ruby to Simorgh

The framework-agnostic Ruby backend engine designed exclusively to power the Simurgh Panel.

Installation

Add this line to your application's Gemfile:

gem 'kabk'

Usage

This gem manages the metadata registry, schema manifest generation, server-side validation, pagination, and concurrency control. Kabk is ORM-agnostic and relies on the Adapter pattern to interface with your database (e.g., via Sequel). It operates entirely on plain Ruby hashes and assumes your host application (like Roda or Rails) handles authentication and authorization.

Registering a Resource

require 'kabk'

# Assuming you have a Sequel Model
class NewsItem < Sequel::Model; end

# Kabk automatically detects Sequel models and uses the Kabk::Adapters::SequelAdapter

Kabk.register(name: 'news_item', table: NewsItem) do
  title fa: 'اخبار و اطلاعیه‌ها', en: 'News & Announcements'
  icon 'Newspaper'
  plural_name 'news'
  api_path '/api/admin/news'
  
  field :id, type: :number, form_type: :number, primary_key: true, hidden_in_form: true
  field :title, type: :string, form_type: :text, required: true, validation: { min_length: 5 }
  field :content, type: :string, form_type: :wysiwyg
  field :publish_date, type: :datetime, form_type: :datetime, calendar: :jalali
  
  # Lifecycle Hooks
  before_create do |params, context|
    params["created_by"] = context[:current_user_id]
  end

  after_create do |record, context|
    # trigger background job
  end
end

Generic REST Engine

The Kabk::RestEngine class orchestrates validation and delegates CRUD operations to the configured ORM adapter. It returns standardized raw hashes that your HTTP layer can easily convert to JSON.

engine = Kabk::RestEngine.new('news_item')

# Pagination, Filtering, Sorting, and Hydration are automatic
result = engine.list("page" => 1, "per_page" => 15, "sort" => "-created_at")
# => { success: true, data: [...], meta: { ... } }

# Validation and OCC automatically applied
result = engine.update(1, { "title" => "New Title", "updated_at" => "2026-03-15T11:00:00Z" })

System Configuration (Protocol v1.6.0)

Kabk generates a JSON schema manifest containing dynamic system configuration and UI settings. You can override these defaults by passing a custom hash to the SchemaRenderer. Ensure you inject your authentication endpoints here, as Kabk itself does not provide them.

renderer = Kabk::SchemaRenderer.new(
  system_config: {
    title: { fa: "پنل مدیریت", en: "My Custom Admin" },
    logo_url: "/custom-logo.png",
    endpoints: {
      login: "/auth/admin_login",
      me: "/auth/admin_me",
      logout: "/auth/admin_logout",
      refresh: "/auth/admin_refresh",
      upload: "/api/files"
    }
  }
)
schema = renderer.render

Testing

bundle install
bundle exec rspec