Dry::Facts
EventSourcing ruby toolkit, somewhat based on dry-rb primitives. Opinionated. Raw.
Rationale
People dont know or understand software projects, people navigate themselves through software projects. To effectively navigate through structure and mutable state of big systems - programmers need sub-systems to be isolated. Usable incapsulation - barriers have to be visible and hard to break. Readability matters - declarative readable code wins.
Goals
- General EventSourcing toolkit for Ruby
- Ability to generate GraphQL interface to Bounded Contexts
- Idiomatic human-friendly API/DSL
- Explore data-primitives-first approach minimize usage of Classes and inheritance
Basic concepts
Example module structure:
# Bounded Context - isolated autonomous module
# it governs own state
# and encapsulates interactions with outer world
module AccountManagementContext
# State of the context is derived from persisted facts
module Events
Corrected
SignedUp
SignedIn
SignedOut
PasswordResetLinkRequested
PasswordResetLinkSent
PasswordUpdated
end
# Commands modify state by persisting events and
# encapsulate behaviors
module Commands
Correct
SignUp
SignIn
SignOut
PasswordResetTokenRequest
PasswordResetTokenSend
PasswordReset
end
# Queries allow read access of context's state
# for inner and outer usage
# multiple storages of various types may be used
module Queries
IsEmailAvialable
AccountByUUID
AccountByEmail
AccountByPasswordResetToken
AccountByEmailAndEncryptedPassword
IsValidAuthTokenForAccount
IsValidPasswordResetTokenForAccount
end
# Aggregates are optionally post-processed
# collections of events, used for representation of data
module Aggregates
Account
end
end
Installation
Add this line to your application's Gemfile:
gem 'dry-facts'
And then execute:
$ bundle
Or install it yourself as:
$ gem install dry-facts
Usage
See example usage in test/dummy_app
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Active development is visible in develop
branch.
Bug reports and pull requests are welcome on GitHub at https://github.com/andriytyurnikov/dry-facts.
License
The gem is available as open source under the terms of the MIT License.