GitHub - servactory/servactory: Powerful Service Object for Ruby applications

Servactory

A set of tools for building reliable services of any complexity.

Gem version Release Date Downloads Ruby version

๐Ÿ“š Documentation

See servactory.com for comprehensive documentation, including:

  • Detailed guides for all features
  • Advanced configuration options
  • Best practices and patterns
  • Migration guides
  • API reference

Building reliable services shouldn't be complicated. Servactory provides a battle-tested framework for creating service objects with:

  • ๐Ÿ›ก๏ธ Type Safety - Enforce types on inputs and outputs, catch errors early
  • โœ… Built-in Validation - Rich validation DSL with custom rules
  • ๐Ÿงช Test-Friendly - RSpec matchers and service mocking helpers
  • ๐Ÿ“Š Structured Output - Consistent Result object pattern
  • ๐Ÿ”ง Highly Configurable - Extensions, helpers, and custom options
  • ๐Ÿ“š Well Documented - Comprehensive guides and examples

๐Ÿš€ Quick Start

Installation

Define service

class Users::Authenticate < Servactory::Base
  input :email, type: String
  input :password, type: String

  output :user, type: User

  make :authenticate!

  private

  def authenticate!
    if (user = User.authenticate_by(email: inputs.email, password: inputs.password)).present?
      outputs.user = user
    else
      fail!(message: "Authentication failed", meta: { email: inputs.email })
    end
  end
end

Usage in controller

class SessionsController < ApplicationController
  def create
    service = Users::Authenticate.call(**session_params)

    if service.success?
      session[:current_user_id] = service.user.id
      redirect_to service.user
    else
      flash.now[:alert] = service.error.message
      render :new, status: :unprocessable_entity
    end
  end

  private

  def session_params
    params.require(:session).permit(:email, :password)
  end
end

๐Ÿงฉ Ecosystem

  • Stroma โ€” A foundation for building modular, extensible DSLs in Ruby
  • OpenTelemetry Instrumentation โ€” Automatic tracing of service calls and actions with span attributes and failure detection

๐Ÿค Contributing

We love contributions! Check out our Contributing Guide to get started.

Ways to contribute:

  • ๐Ÿ› Report bugs and issues
  • ๐Ÿ’ก Suggest new features
  • ๐Ÿ“ Improve documentation
  • ๐Ÿงช Add test cases
  • ๐Ÿ”ง Submit pull requests

๐Ÿ™ Acknowledgments

Special thanks to all our contributors!

๐Ÿ“„ License

Servactory is available as open source under the terms of the MIT License.