<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mariusz Kapcia on Medium]]></title>
        <description><![CDATA[Stories by Mariusz Kapcia on Medium]]></description>
        <link>https://medium.com/@mariuszkapcia?source=rss-ebbdeac252b7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*k0oB2K_ybDZ2l1L71CWaDg.jpeg</url>
            <title>Stories by Mariusz Kapcia on Medium</title>
            <link>https://medium.com/@mariuszkapcia?source=rss-ebbdeac252b7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 19:52:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mariuszkapcia/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[EventStore configuration per bounded context]]></title>
            <link>https://medium.com/@mariuszkapcia/eventstore-configuration-per-bounded-context-cf17c40bb01f?source=rss-ebbdeac252b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf17c40bb01f</guid>
            <category><![CDATA[bounded-context]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <dc:creator><![CDATA[Mariusz Kapcia]]></dc:creator>
            <pubDate>Thu, 04 Jun 2020 19:54:41 GMT</pubDate>
            <atom:updated>2020-06-23T09:04:37.970Z</atom:updated>
            <content:encoded><![CDATA[<h3>Event store configuration per bounded context</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-po2LxtLiDgK14kDML6AJg.jpeg" /></figure><p>In most of my projects, I’m using or I’m trying to introduce patterns from Domain-Driven Design, Event Sourcing, and CQRS. Most of those patterns are somehow related to the publish-subscribe pattern and it’s not possible to efficiently use them without it. I’m working with Ruby on Rails and my choice is <a href="https://railseventstore.org/">RailsEventStore</a>. Of course, it’s possible to implement a very basic mechanism by ourselves, but if we can use a well-tested solution then why not use it. The general idea behind this article should be applicable for every tool but in the examples, RES will be used.</p><p>Let’s start from the beginning. We start a new project or maybe we want to extract our first <a href="https://medium.com/@mariuszkapcia/rails-architect-masterclass-bounded-contexts-b03a6d01653a">bounded context</a> from existing legacy code. We need to add event store configuration to the project.</p><pre># config/initializers/rails_event_store.rb</pre><pre>Rails.configuration.to_prepare do<br>  Rails.configuration.event_store = RailsEventStore::Client.new<br>end</pre><p>With time, we are able to add more and more domain events and at some point, we can start using them with read-models. At this point, we need to add subscribers to our event store.</p><pre># config/initializers/rails_event_store.rb</pre><pre>event_store.subscribe(<br>  HumanResources::PersonList,<br>  to: [HumanResources::PersonAdded, HumanResources::PersonRemoved]<br>)</pre><p>Everything looks good. Domain events are published from Person aggregate. We are able to write tests separately for the write side (commands/command handlers/aggregates) and the read side (read models/handlers). There is also a place for acceptance tests where we want to use our API and check if we can get the expected response body.</p><p>Now, imagine that our project grows with time and we have not one, but ten bounded contexts and not one read model, but ten per bounded context. In addition, we have different handlers like process managers/sagas or context mappings. Everything is configured inside:</p><pre># config/initializers/rails_event_store.rb</pre><p>It will lead us to a couple of problems. First of all, it’s difficult to manage one big file with the event store configuration. Secondly, there is an even bigger problem that may not be visible at first glance. With one big config, we have only two reasonable ways of using event store in the test environment. We can use all subscribers or none.</p><p>Of course, it’s possible to manually declare which subscribers should be called for every test but it’s not very efficient. It can be especially problematic if we want to test a bounded context in isolation or maybe only communication between two bounded contexts.</p><p>Case with all subscribers has two drawbacks. First is that our overall test time execution will increase significantly and that’s due to running many unnecessary subscribers. Second is that we will need to make sure that all necessary dependencies for every subscriber are ready to use. If our goal is to test bounded context A then we don’t want to do anything related to bounded context B.</p><p>Case without subscribers is not very useful because we are not able to properly test the whole flow.</p><p>What’s the solution? We can split our event store configuration into small configurations per bounded context. Thanks to that, we will be able to easily create new instances of an event store with subscribers from specific bounded contexts.</p><p><strong>Implementation</strong></p><p>We want to create a separate file for every bounded context. In this file, we will only have subscribers related to this bounded context.</p><pre># config/event_store/configure_human_resources_bc.rb</pre><pre>class ConfigureHumanResourcesBoundedContext<br>  def call<br>    event_store.subscribe(<br>      HumanResources::PersonList,<br>      to: [HumanResources::PersonAdded,<br>           HumanResources::PersonRemoved]<br>    )<br>  end</pre><pre>private<br>  <br>  attr_reader :event_store<br>  <br>  def initialize(event_store)<br>    @event_store = event_store<br>  end<br>end</pre><pre># config/event_store/configure_accounting_bc.rb</pre><pre>class ConfigureAccountingBoundedContext<br>  def call<br>    event_store.subscribe(<br>      Accounting::OverdueInvoiceList,<br>      to: [Accounting::InvoiceAdded,<br>           Accounting::InvoiceDueDatePassed]<br>    )<br>  end</pre><pre>private<br>  <br>  attr_reader :event_store<br>  <br>  def initialize(event_store)<br>    @event_store = event_store<br>  end<br>end</pre><p>Now we need to put everything together. This part is done in our initializer.</p><pre># config/initializers/rails_event_store.rb</pre><pre>require_relative &#39;../event_store/configure_human_resources_bc&#39;<br>require_relative &#39;../event_store/configure_accounting_bc&#39;</pre><pre>Rails.configuration.to_prepare do<br>  Rails.configuration.event_store.tap |event_store|<br>    ConfigureHumanResourcesBoundedContext.new(event_store).call<br>    ConfigureAccountingBoundedContext.new(event_store).call<br>  end<br>end</pre><p>Our default configuration is still the same. However, thanks to that change we are able to easily test bounded contexts in isolation. In our test file, we can add a method like below and pass it further to the command handler/process manager/or some other service initializer.</p><pre>def event_store<br>  @event_store ||= begin<br>    RailsEventStore::Client.new.tap do |event_store|<br>      ConfigureHumanResourcesBoundedContext.new(event_store).call<br>    end<br>  end<br>end</pre><p>It’s also possible to use code like this if we prefer it:</p><pre>allow(Rails.configuration)<br>  .to receive(:event_store)<br>  .and_return(event_store)</pre><p><strong>Summary</strong></p><p>Today we’ve learned common problems with event store configuration and how to tackle it. The proposed solution is very elastic. In addition to bounded contexts, we can introduce separate files for context mappings. It’s also possible to split it even further into specialized subscribers inside one bounded context if we need it.</p><p>A different solution for this problem is to use separate event stores for every bounded context but that’s a topic for another time.</p><p>Thanks for reading and have a nice day!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf17c40bb01f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Server-side user account verification with a text message and a one-time password.]]></title>
            <link>https://medium.com/@mariuszkapcia/server-side-user-account-verification-with-a-text-message-and-a-one-time-password-8596229f7b76?source=rss-ebbdeac252b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/8596229f7b76</guid>
            <category><![CDATA[one-time-password]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Mariusz Kapcia]]></dc:creator>
            <pubDate>Wed, 03 Jun 2020 21:07:45 GMT</pubDate>
            <atom:updated>2020-06-09T09:45:46.297Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uFu4qxr9j4gBsrZ4f2aiKA.jpeg" /></figure><p>Recently one of our clients asked us to improve the registration process in the mobile application. The current solution is based on text messages and deep links. Users need to click on a link in a text message to verify the account and be redirected to the mobile application. This solution has a few disadvantages:</p><ul><li>It’s old. It was popular a few years ago.</li><li>There are many problems with deep links handling on the mobile application side. Most operating systems suggest browsers as the default application to open such links, which shouldn’t be surprised, and it’s super easy to accidentally choose it.</li><li>Some operating systems don’t support it at all.</li></ul><p>So, what’s the modern way of solving this problem? It’s called one-time passwords. Instead of a deep link, we send a special password/code inside the text message. This code is later parsed by the mobile application and automatically used in a verification process. No action is required from the user.</p><p>To achieve this we need two things:</p><ul><li>Ability to send text messages from the server.</li><li>The correct format of generated text messages.</li></ul><p><strong>Twilio</strong></p><p>One possible way of sending text messages is to integrate our server with <a href="https://www.twilio.com/">Twilio</a> API. It’s super easy thanks to <a href="https://github.com/philm/twilio">Twilio gem</a>. All we need is to create a new account on the Twilio webpage, create one phone number from which text messages will be sent, and copy API credentials. The process is very easy and intuitive so we will skip it. Let’s see how we can use this gem.</p><pre>client = Twilio::REST::Client.new(account_sid, auth_token)<br>client.messages.create(body: &#39;Example message&#39;, to: &#39;&#39;, from: &#39;&#39;)</pre><p>The credentials needed to create an instance of the Twilio client consists of account_sid and auth_token. We can find both on the Twilio account panel webpage. We also need our created phone number from which we want to send our messages. It should be used with from attribute. For obvious reasons, there is an empty string above. The last thing is to attribute which represents the phone number of our recipient.</p><p><strong>Message format</strong></p><p>Message format requirements are a little different for Android and iOS but it’s possible to combine them into one message format. In the case of iOS, there is a lot of magic going on. It’s not possible to find any details in the <a href="https://developer.apple.com/documentation/security/password_autofill/enabling_password_autofill_on_a_text_input_view">documentation</a> regarding the message format but it’s a good idea to use keywords passcode or code. Android is much better. We need to generate a hash string that will represent our mobile application and include it somewhere in our message. Detailed instructions on how to generate that hash can be found <a href="https://developers.google.com/identity/sms-retriever/verify#computing_your_apps_hash_string">here</a>. The overall length of the message shouldn’t be longer than 140 characters. Here is one example of a generated message with a password 21562624:</p><pre>Your <em>ApplicationName</em> passcode is: 21562624 jD23AvBdbR5</pre><p>Password/code itself can consist of anything we want, but it’s a good idea to generate a possibly user-friendly password because in some cases the user will need to type it manually.</p><p><strong>How to use it?</strong></p><p>We need two API endpoints. One for creating a user session and user account, if this is the first time user is in our system, we will create a user account. Second for verifying the password if it’s correct. The simplified version can be seen below.</p><pre>class SessionsController &lt; ActionController::API<br>  def create<br>    phone_number = params[:phone_number]<br>    user         = User.find_by(phone_number: phone_number)<br>    if user.nil?<br>      user = CreateUserAccount.call(SecureRandom.uuid, phone_number)<br>    end<br>    code = GenerateUserVerificationCode.call(user.id)<br>    SendVeriticationMessage.call(user.id, phone_number, code)<br>    head :no_content<br>  end</pre><pre>def verify<br>    user = User.find_by(verification_code: params[:code])<br>    if user.nil?<br>      raise InvalidVeriticationCode<br>    end<br>    render json: { session: GenerateUserSession.call(user.id) }, <br>           status: :ok<br>  end<br>end</pre><p>It would also be very nice to add a few security additions:</p><ul><li>The expiration time for verification code. There is no reason to keep those codes valid forever. We can invalidate them after a few minutes.</li><li>Only one code can be valid at the same time. Every time we generate new verification code we want to invalidate all old codes.</li><li>We can also rate-limit access to our API to prevent brute-force attacks.</li></ul><p><strong>Summary</strong></p><p>We have all the necessary information to build API for the mobile application with one-time password support. To quickly recap, we know how to send text messages via Twilio API, how to generate properly formatted messages with passwords, and how to handle the basic flow of requests.</p><p>Thanks for reading and have a nice day!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8596229f7b76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to handle one big request as a batch of small commands.]]></title>
            <link>https://medium.com/@mariuszkapcia/how-to-handle-one-big-request-as-a-batch-of-small-commands-f45dc4107865?source=rss-ebbdeac252b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f45dc4107865</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <dc:creator><![CDATA[Mariusz Kapcia]]></dc:creator>
            <pubDate>Tue, 02 Jun 2020 21:31:17 GMT</pubDate>
            <atom:updated>2020-06-03T13:52:05.171Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D8p6Li8Iv5Fw-5PYHDaUjQ.jpeg" /></figure><p>This is a rather common situation in my projects. We have a back-office web application to give our clients the option to manage mobile application content. The specification is very similar between projects. There are many tabs, tables, and plenty of big forms with 10 or even more attributes. It’s a common practice to combine unrelated attributes into one huge form with one save button. That leads to significant differences between UI and our domain.</p><p>Today we will talk about how to fit this into Domain-Driven Design patterns. At first, it may look like there is no problem. We can create one big command with all attributes received from the front-end via API and pass it to the command handler. Unfortunately in most cases, attributes are related to different domain models and we need more than one command to properly handle this situation. We can also have a situation where all attributes are from one domain model but there is no strong connection between them e.g., avatar and password. In such cases, we also want to split attributes into independent commands.</p><p>Let’s define our goal. Following actions needs to be performed:</p><ul><li>Conversion of API parameters into <a href="https://medium.com/@mariuszkapcia/rails-architect-masterclass-value-object-fb5c53b8e600">value objects</a> or at least into correct types. We don’t want to have integers and booleans as strings. This part is not covered in the article.</li><li>API parameters validation. We want to make sure that everything is correct before creating commands. People have different opinions on that subject. I think that commands should be created with proper attributes. Creating command with invalid attributes is like allowing the user to perform invalid action and we don’t want that.</li><li>We don’t want to validate the same attributes over and over with every change. Let’s say we have a group of validations responsible for the user profile. If we are changing only the password then what’s the point of validating other attributes.</li><li>Last but not least, we want to create a list of commands which should be performed on our system. The command should be created only if something changed.</li></ul><p>Now we need to think about how this should be implemented. There are many options, but we would like to use something similar to FormObject pattern with few additions. We can continue with a profile example and try to imagine end result.</p><pre>class ProfileForm &lt; Form<br>  command Users::ChangeAvatar<br>  command Users::ChangePassword</pre><pre>  validation_options skip_unchanged_attributes: true</pre><pre>  validates :avatar_url,<br>            presence: { message: &#39;avatar_url_is_missing&#39; }<br>  validates :password,<br>            presence: { message: &#39;password_is_missing&#39; }<br>  validates :password_confirmation,<br>            presence: { message: &#39;password_confirmation_is_missing&#39;}</pre><pre>  validate :password_confirmation, :password_confirmation_match</pre><pre>  private</pre><pre>  def password_confirmation_match<br>    if !password.eql?(password_confirmation)<br>      errors.add(<br>        :password_confirmation,<br>        &#39;password_confirmation_mismatch&#39;<br>      )<br>    end<br>  end<br>end</pre><p>We want to use standard ActiveModel validations and be able to specify a list of commands related to this form. There is also an option to skip validation of unchanged attributes. In one case we need to validate such attributes and it’s when we adding new domain models. The default value of this option can be set to true or false depending on our needs and we can change it anytime we need. The last difference is with validate method. Normally this method is used with one parameter but we need to know which attribute is validated by the block. That’s the reason for the additional attribute name.</p><p>What about usage and public interface? We have two use cases. One is for creating a completely new domain model. In this case, we don’t have any existing domain models to use with our form. We will apply changes to the form, verify if all validations passed, build a command list, and perform them on our system.</p><pre>form = UserRegistrationForm.new<br>form.apply_changes(params)<br>form.verify!<br>form.build_commands!.each do |cmd|<br>  <a href="https://github.com/arkency/command_bus/">command_bus</a>.call(cmd)<br>end</pre><p>In the second case, we want to update the existing domain model. There is one difference in the code. We will create our form with existing domain model. Thanks to that we will be able to tell if something changed.</p><pre>user_profile = find_user_profile(params[:user_id])<br>form = ProfileForm.new(user_profile)<br>form.apply_changes(params)<br>form.verify!<br>form.build_commands!.each do |cmd|<br>  command_bus.call(cmd)<br>end</pre><p>Let’s implement it! We will split it into smaller pieces to make things easier.</p><p><strong>Command</strong></p><p>We need to start with a command implementation. We will use the <a href="https://dry-rb.org/gems/dry-struct/1.0/">dry-struct</a> gem for this purpose. It’s pretty straight forward. Command is a base class with simple error handling and ChangeAvatar with ChangePassword are our commands.</p><pre>require &#39;dry-struct&#39;</pre><pre>class Command &lt; Dry::Struct<br>  Invalid = Class.new(StandardError)</pre><pre>def self.new(*)<br>    super<br>  rescue Dry::Struct::Error =&gt; error<br>    raise Invalid, error<br>  end<br>end</pre><pre>module Users<br>  class ChangeAvatar &lt; Command<br>    attribute :avatar_url, Types::Strict::String<br>  end<br>end</pre><pre>module Users<br>  class ChangePassword &lt; Command<br>    attribute :password,              Types::Strict::String<br>    attribute :password_confirmation, Types::Strict::String<br>  end<br>end</pre><p><strong>Form</strong></p><p>Let’s start with a very basic class. We include ActiveModel validations and declaring custom validation error class.</p><pre>class Form<br>  include ActiveModel::Model<br>  include ActiveModel::Validations<br>  include ActiveModel::Conversion</pre><pre>  class ValidationError &lt; StandardError<br>    attr_reader :errors</pre><pre>    def initialize(errors)<br>      @errors = errors<br>    end<br>  end<br>end</pre><p>Now let’s take care of a command list. We need to build setters and getters for every command attribute and save list of attributes and commands for later use.</p><pre>def self.command(cmd_class)<br>  cmd_attributes = cmd_class.schema.keys.map(&amp;:name)<br>  cmd_attributes.each do |attribute|<br>    send(:attr_accessor, attribute)<br>  end</pre><pre>  @attributes ||= []<br>  @attributes  += cmd_attributes<br>  @attributes   = @attributes.uniq</pre><pre>  @commands          ||= {}<br>  @commands[cmd_class] = cmd_attributes<br>end</pre><p>Command is a class method but validations are done on an instance so we need a way to pass this data to the instance</p><pre>def self.attributes<br>  @attributes<br>end</pre><pre>def self.commands<br>  @commands<br>end</pre><pre>def attributes<br>  self.class.attributes<br>end</pre><pre>def commands<br>  self.class.commands<br>end</pre><p>Next are validation options. We need to set default values and implement setter with getter.</p><pre>def self.validation_options(options)<br>  @options ||= {}<br>  @options.merge!(options)<br>end</pre><pre>def self.options<br>  @options ||= { skip_unchanged_attributes: false }<br>end</pre><pre>def options<br>  self.class.options<br>end</pre><p>Now we need to override validates and validate methods from ActiveModel. The reason for this is that we want to be able to validate only changed attributes. To achieve this we need to dynamically add and remove validations. The idea is to keep aliases for original methods and save all declared validations for later use.</p><pre>class &lt;&lt; self<br>  alias_method :activemodel_validates, :validates<br>  alias_method :activemodel_validate, :validate<br>end<br>def self.validates(*attributes)<br>  @validations ||= []<br>  @validations.push(attributes)<br>  self<br>end</pre><pre>def self.validate(*args, &amp;block)<br>  if args[0].class.eql?(Symbol)<br>    @custom_validations ||= []<br>    @custom_validations.push(args)<br>    self<br>  else<br>    super<br>  end<br>end</pre><p>We also need getters to get those validations when the time comes right.</p><pre>def self.validations<br>  @validations<br>end</pre><pre>def self.custom_validations<br>  @custom_validations<br>end</pre><pre>def validations<br>  self.class.validations<br>end</pre><pre>def custom_validations<br>  self.class.custom_validations<br>end</pre><p>Okay, we are about halfway through. We have all the necessary things on a class level. Now let’s focus on instance methods. First is initialization. We want to assign a default value for every attribute we have in our form. Of course, it will happen only when an object is provided.</p><pre>def initialize(object = nil)<br>  @changed_attributes = []<br>  attributes.each do |attribute|<br>    assign_value(attribute, object.try(:[], attribute))<br>  end<br>end</pre><pre>def assign_value(attribute, value)<br>  send(&quot;#{attribute}=&quot;, value)<br>end</pre><p>Next thing is to apply changes from API parameters. We want to skip unknown attributes from parameters and save which attributes actually changed the value. For those attributes, we will create commands later.</p><pre>def apply_changes(params)<br>  params.each do |attribute, value|<br>    attribute = attribute.to_sym<br>    next unless attribute.in?(attributes)<br>    if value_changed?(attribute, value)<br>      @changed_attributes += [attribute]<br>    end<br>    assign_value(attribute, value)<br>  end<br>  self<br>end</pre><pre>def value_changed?(attribute, new_value)<br>  send(attribute) != new_value<br>end</pre><p>Right now we can check if all validations are passing. This is the part where we need to check if we want to validate all attributes or only changed and decide which validations should be called. ActiveModel method clear_validators! is needed because we can use the same instance of our form many times with different params. If everything is fine we will return nil. In case of any errors, we will raise an exception.</p><pre>def verify!<br>  return if valid?<br>  raise ValidationError, errors.to_hash.map { |k,v| v }.flatten<br>end</pre><pre>def valid?<br>  self.class.clear_validators!<br>  skip = options[:skip_unchanged_attributes]<br>  validations.each do |validation|<br>    next if skip &amp;&amp; validation[0].in?(@changed_attributes)<br>    self.class.activemodel_validates(*validation)<br>  end<br>  custom_validations.each do |validation|<br>    next if skip &amp;&amp; validation[0].in?(@changed_attributes)<br>    self.class.activemodel_validate(*validation[1])<br>  end<br>  super<br>end</pre><p>The last step is to prepare a list of commands. If any of the command attributes have changed then we want to create an instance of this command.</p><pre>def build_commands!<br>  commands.map do |command, attributes|<br>    next if (@changed_attributes &amp; attributes).length.eql?(0)<br>    build_command(command, attributes)<br>  end.compact<br>end</pre><pre>def build_command(command, attributes)<br>  attributes = attributes.map do |attribute|<br>    [attribute, fetch_value(attribute)]<br>  end<br>  command.new(Hash[attributes])<br>end</pre><pre>def fetch_value(attribute)<br>  send(attribute)<br>end</pre><p>That’s it! That was quite a journey. The whole code can be seen <a href="https://gist.github.com/mariuszkapcia/f6dbcccf20c742a6f1a2bcf5f4cf9a50">here</a>.</p><p><strong>Extensions</strong></p><p>That’s the first iteration of this idea. It can be extended with new features:</p><ul><li>Use a list of domain models and not only one.</li><li>Use command_context object with build_commands! method to specify current user information.</li><li>Use command_policy object with build_commands! method to check if the user has all the necessary privileges to perform this command.</li></ul><p><strong>Summary</strong></p><p>As we said at the beginning, there are many ways to handle those requirements. The nice thing about this solution is that logic is in one place and we don’t have to copy/paste the same thing over and over from one application service to another. We are able to reuse validations and we don’t need to think about making sure that any unnecessary command was performed.</p><p>Thanks for reading and have a nice day!</p><p><strong>Examples</strong></p><p>Here you can find my <a href="https://github.com/mariuszkapcia">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f45dc4107865" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to implement a simple API for ‘Sign in with Apple’]]></title>
            <link>https://medium.com/@mariuszkapcia/how-to-implement-a-simple-api-for-sign-in-with-apple-ffa7f06e32c7?source=rss-ebbdeac252b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffa7f06e32c7</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[cqrs]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <category><![CDATA[sign-in-with-apple]]></category>
            <category><![CDATA[event-sourcing]]></category>
            <dc:creator><![CDATA[Mariusz Kapcia]]></dc:creator>
            <pubDate>Mon, 01 Jun 2020 22:08:37 GMT</pubDate>
            <atom:updated>2020-06-02T12:17:44.462Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k6A96OsiO7u-Aci2h1g60g.jpeg" /></figure><p>Most of the projects I’m working on right now are related to mobile applications and Ruby on Rails backend. Today we will talk about what needs to be done on your server to support mobile ‘Sign in with Apple’ feature. Our goal is to create a simple API that will allow registration and login process to our system using Apple account and mobile application.</p><p>The first thing we need to do is to read <a href="https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api">the documentation</a> to know if there will be any communication between our system and Apple servers and how to implement it. After a quick read, we will know two things:</p><ul><li>We need to fetch Apple’s public key for verifying token signature.</li><li>We need to verify Identity Token which will be sent to us from the mobile application together with nonce. The verification process is described <a href="https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api/verifying_a_user">here</a> and we can do it by ourselves or use <a href="https://github.com/nov/apple_id">AppleId</a> gem.</li></ul><p>Let’s start by implementing a simple AppleService which will be responsible for all the things described above. We will use the AppleId gem because there is no reason to implement that logic from scratch.</p><pre>AppleError = Class.new(StandardError)</pre><pre>class AppleService<br>  def fetch_profile<br>    decoded_token  = @validator.decode(@id_token)<br>    verified_token = decoded_token.verify!(client: client_id, verify_signature: true, nonce: @nonce)<br>    parse_profile(verified_token)<br>  rescue AppleID::IdToken::VerificationFailed<br>    raise AppleError.new(&#39;Invalid token&#39;)<br>  end</pre><pre>private</pre><pre>def initialize(id_token, nonce)<br>    @id_token  = id_token<br>    @nonce     = nonce<br>    @validator = AppleID::IdToken<br>  end</pre><pre>def client_id<br>    &#39;mobile-application-identifier&#39;<br>  end</pre><pre>def parse_profile(verified_token)<br>  {<br>    id:            verified_token.sub,<br>    email:         verified_token.email,<br>    private_email: verified_token.is_private_email,<br>    name:          &#39;&#39;<br>  }<br>end</pre><p>Service has one public method fetch_profile where identity token is verified and decoded. The whole process is handled by AppleId gem. Here are a few things worth mentioning:</p><ul><li>There is no full nameinside the identity token which was a big surprise for me. Unfortunately, we will need to get this value from the mobile application.</li><li>The nonce is not required but it will increase overall security so it is worth adding.</li><li>Apple allows to flag user email address as private and in such cases, the email attribute will contain Apple generated alias which later can be used to send messages to the user. There is a separate attribute to indicate if the email address is private or not.</li><li>ClientId is an identifier of mobile application and you need to ask a mobile developer for it.</li></ul><p>Now we can take care of the necessary things around it. We will use concepts from Domain-Driven Design to make things a little more interesting.</p><p><a href="https://medium.com/@mariuszkapcia/rails-architect-masterclass-bounded-contexts-b03a6d01653a"><strong>Bounded context</strong></a></p><p>This context will be responsible for managing user accounts. We have many possible names: Access, Users, Identity&amp;Access. Bounded contexts are represented as modules in Ruby on Rails application.</p><pre>module Users<br>end</pre><p><strong>Command</strong></p><p>We need one command responsible for registration. We will skip validations to keep things clean but feel free to includeActiveModelor <a href="https://dry-rb.org/gems/dry-struct/1.0/#:~:text=dry%2Dstruct%20is%20a%20gem,for%20defining%20typed%20struct%20classes.">dry-struct</a>.</p><pre>module Users<br>  class RegisterNewUserFromApple<br>    attr_accessor :id<br>    attr_accessor :apple_id<br>    attr_accessor :fullname<br>    attr_accessor :email<br>    <br>    def initialize(id:, apple_id:, fullname:, email:)<br>      @id       = id<br>      @apple_id = apple_id<br>      @fullname = fullname<br>      @email    = email<br>    end<br>  end<br>end</pre><p><strong>Domain event</strong></p><p>We also need one domain event to represent the fact of user registration. It’s good practice to validate event schema. Here we use <a href="https://github.com/deseretbook/classy_hash">ClassyHash</a> gem but dry-struct will work too. In some cases, it’s also worth introducing failure events but we don’t need it here.</p><pre>module Users<br>  class UserRegisteredFromApple &lt; RailsEventStore::Event<br>    SCHEMA = {<br>      uuid:     String,<br>      fullname: String,<br>      email:    String,<br>      apple_id: String,<br>    }.freeze</pre><pre>    def self.strict(data:)<br>      ClassyHash.validate(data, SCHEMA)<br>      new(data: data)<br>    end<br>  end<br>end</pre><p><strong>Aggregate</strong></p><p>Depends on the approach we can treat registration as part of Useraggregate or we can create a separate aggregate for the registration process only and create User aggregate later. We will handle all event-related things with <a href="https://railseventstore.org/">RES</a> gem.</p><p>There is a simple validation if the user is already registered and if everything is fine thenUserRegisteredFromAppledomain event is published.</p><pre>module Users<br>  class User<br>    include AggregateRoot</pre><pre>    HasBeenAlreadyRegistered = Class.new(StandardError)</pre><pre>    def initialize(id)<br>      @id    = id<br>      @state = :unregistered<br>    end</pre><pre>    def register_from_apple(fullname, email, apple_id)<br>      raise HasBeenAlreadyRegistered if @state.in?([:registered])<br>      <br>      apply(Users::UserRegisteredFromApple.strict(data: {<br>        id:       @id,<br>        fullname: fullname,<br>        email:    email,<br>        apple_id: apple_id,<br>      }))<br>    end</pre><pre>    private</pre><pre>    def apply_user_registered_from_apple(_event)<br>      @state = :registered<br>    end<br>  end<br>end</pre><p><strong>Command handler</strong></p><p>Now we need to load our aggregate and handle the registration command. This part is done by a command handler. Here you can also validate command and run different policies required to check if a command can be performed. We can make sure that users will be unique thanks to using an email address as part of the stream name.</p><p>Communication between commands and command handlers can be implemented with a <a href="https://github.com/arkency/command_bus/">command bus</a>.</p><pre>module Users<br>  class OnRegisterNewUserFromApple<br>    def call(cmd)<br>      repository = AggregateRoot::Repository.new<br>      repository.with_aggregate(User.new(cmd.id), stream_name(cmd.email) do |user|<br>        user.register_from_apple(cmd.fullname, cmd.email, cmd.apple_id)<br>      end<br>    end</pre><pre>    private</pre><pre>    def stream_name(email)<br>      &quot;Users::User$#{email}&quot;<br>    end<br>  end<br>end</pre><p><strong>Read model</strong></p><p>Our domain model is event-sourced so we need a read model to represent a cached list of registered users. It’s not very efficient to load all aggregates in the system and check who is registered. We also shouldn’t keep view related data inside aggregate. To make this work, the event store should be configured first.</p><pre>module Users<br>  class RegisteredUsersReadModel<br>    def call(event)<br>      case event<br>      when Users::UserRegisteredFromApple<br>        User.create!(<br>          id:       event.data[:id],<br>          email:    event.data[:email],<br>          fullname: event.data[:fullname],<br>          apple_id: event.data[:apple_id],<br>        )<br>      end<br>    end</pre><pre>    def find(id)<br>      User.find_by(id: id)<br>    end<br>    <br>    def find_by_apple_id(apple_id)<br>      User.find_by(apple_id: apple_id)<br>    end<br>  end<br>end</pre><p><strong>Application service</strong></p><p>We introduce an application service to keep controller action as clean as possible. Service is responsible for checking if there is a need to create a new user account or only generate a session for an existing user. Implementation of GenerateSession service is not part of this blogpost.</p><pre>class CreateAppleSession<br>  def call(token, nonce, fullname)<br>    apple_profile = Users::AppleService<br>      .new(token, nonce).fetch_profile<br>    user = Users::RegisteredUsersReadModel<br>      .new<br>      .find_by_apple_id(apple_profile[:id]<br>    user_id = user.try(:id) || SecureRandom.uuid<br>   <br>    if user.nil?<br>      apple_profile.merge!(name: fullname)<br>      command_bus.call(register_user_from_apple(user_id, apple_profile))<br>    end</pre><pre>    user_session = Users::GenerateSession.new.call(user_id)<br>    { user_id: user_id, user_session: user_session } <br>  end</pre><pre>  private</pre><pre>  def register_user_from_apple(user_id, apple_profile)<br>    Users::RegisterNewUserFromApple.new(<br>      id:       user_id,<br>      fullname: apple_profile[:fullname],<br>      email:    apple_profile[:email]<br>      apple_id: apple_profile[:apple_id]<br>    )<br>  end<br>end</pre><p>The only thing left is the controller and routes. It’s pretty straight forward and nobody should have problems with it.</p><p><strong>What’s more to do?</strong></p><p>Of course, we need to implement a mobile application part, but that topic is for another time. If we want to send emails to generated Apple aliases then we need to use <a href="https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_js/communicating_using_the_private_email_relay_service">Private Email Relay Service</a> and we need to properly configure our domain in Apple Developer Center.</p><p><strong>More DDD content</strong></p><p>If you want to see how to implement other DDD patterns in Ruby on Rails you can check out my sample applications and bounded contexts <a href="https://github.com/mariuszkapcia">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffa7f06e32c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails Architect MasterClass: Value Object]]></title>
            <link>https://medium.com/@mariuszkapcia/rails-architect-masterclass-value-object-fb5c53b8e600?source=rss-ebbdeac252b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb5c53b8e600</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <category><![CDATA[value-objects]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Mariusz Kapcia]]></dc:creator>
            <pubDate>Mon, 17 Dec 2018 16:41:04 GMT</pubDate>
            <atom:updated>2018-12-18T12:07:03.018Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6pmEjXppsTM2VGA2dPmezw.jpeg" /></figure><p>We have started the third week of the class and this week we are learning about tactical patterns in Domain-driven design for instance, <a href="https://martinfowler.com/bliki/ValueObject.html">Value Object</a>, Entity, and <a href="https://martinfowler.com/bliki/DDD_Aggregate.html">Aggregate</a>. In addition, as part of our homework, we have started implementing our first Ruby on Rails application with DDD, CQRS, and Event Sourcing.</p><p>Let’s start with Value Object.</p><p><strong>What is Value Object?</strong></p><p>Value object is an immutable object without any history or distinct identity. It is represented and compared by value (combination of its attributes). If you want to change value object you have to create a new instance with new attributes.</p><p>Let’s stop here for a moment and try to visualize this concept. We can think about numbers. A number is represented by the value for example, 9. We do not have any additional identity here. We can add two numbers and we will get a completely new number for example, 9 + 1 = 10. When we are looking at 10 we do not have any history of changes, we do not know if it was created by adding 5 + 5 or maybe 2 + 8. After each operation, we have a new instance without any history or distinct identity.</p><p>There are many examples of more complex value objects for instance,Amount, VatRate, Position, Deadline, and so on. A simple example of FullName value object can be seen below.</p><pre>class FullName<br>  include Comparable</pre><pre>  InvalidValue = Class.new(StandardError)</pre><pre>  attr_reader :first_name, :last_name</pre><pre>  def initialize(first_name, last_name)<br>    raise InvalidValue if first_name.blank? || last_name.blank?</pre><pre>    @first_name = first_name<br>    @last_name  = last_name<br>  end</pre><pre>  def &lt;=&gt;(other)<br>    self.class == other.class &amp;&amp;<br>    first_name == other.first_name &amp;&amp;<br>    last_name  == other.last_name ? 0 : -1<br>  end</pre><pre>  def first_name<br>    first_name<br>  end</pre><pre>  def last_name<br>    last_name<br>  end</pre><pre>  def to_s<br>    &quot;#{first_name} #{last_name}&quot;<br>  end<br>end</pre><p><strong>What are the benefits of using Value Objects?</strong></p><p>Let’s say you want to stop using primitive types for example, String or Integer in one part of the system and start using value objects. Why is it a better approach?</p><p>Value objects are very handy for several reasons:</p><ul><li>We are able to reduce the number of passed parameters between layers and classes. In theFullName example, we do not have to pass two strings for first name and last name everywhere. Instead, we can use one parameter full_name. Maybe one parameter does not sound like a lot but in a more complex scenario, this number can be much bigger.</li><li>We can have simple validations here for instance, checking if first_name is present or if latitude is not out of bounds. Thanks to that you do not have to wonder if the value is correct or not in other places. If value object was created then it’s correct.</li><li>Value object is a good place for encapsulating simple logic related to attributes for example, formatting or applying vat rate to the amount and of course all kinds of operations for example, addition, subtraction, and comparison.</li><li>Value object is a well-defined unit which represents a small part of our system and thanks to that we can easily test it in one place.</li><li>With value objects, we can add more domain/business meaning to our code. We are not using random Integer but Deadline. It has a meaning in our domain. Thanks to that our communication with business people is easier.</li></ul><p><strong>Summary</strong></p><p>I am using value objects in my projects and it really helped with readability and maintainability of the whole system. I was surprised how some parts of the code can be simplified thanks to this technique.</p><p>If you want to see how to implement other DDD patterns in Ruby on Rails you can check out my sample application <a href="https://github.com/mariuszkapcia/project-management-app">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb5c53b8e600" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Event storming]]></title>
            <link>https://medium.com/@mariuszkapcia/event-storming-efa7129596c5?source=rss-ebbdeac252b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/efa7129596c5</guid>
            <category><![CDATA[eventstorming]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <dc:creator><![CDATA[Mariusz Kapcia]]></dc:creator>
            <pubDate>Sun, 16 Dec 2018 16:18:35 GMT</pubDate>
            <atom:updated>2018-12-16T17:34:05.275Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*st1_Yi4Bvmflfps_AH4IMg.jpeg" /></figure><p>In my last blogpost about <a href="https://medium.com/@mariuszkapcia/rails-architect-masterclass-bounded-contexts-b03a6d01653a">bounded contexts</a>, I mentioned technique called event storming. Here I want to present more details and explain how your team can benefit from it.</p><p><a href="https://www.eventstorming.com/">Event storming</a> was proposed by <a href="https://twitter.com/ziobrando">Alberto Brandolini</a> and can be described as an interactive workshop with a lot of sticky notes. It can be used to achieve different goals from designing event-driven systems to better understating underlying business processes in your domain.</p><p>Before you can start you need a few things:</p><ul><li>At least 4 different colors of sticky notes. Each color will represent different concept from DDD world as you can see in the image below.</li><li>Large, empty wall for sticking notes preferably in a room without chairs. During this workshop, everyone should stand.</li><li>Team you can work with. You should invite client, domain experts, and people from your company. It’s crucial to have people from different departments with different perspectives. Thanks to that you will be able to generate more questions during the meeting and understand the domain better.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ffuq6Re7Nhue8bnICA5NRQ.png" /><figcaption>Each color represents different concept.</figcaption></figure><p>Now when you have all set up it’s time to explain the rules. You start with a blank wall which represents a timeline of our system/domain/process. The goal is to represent the system as detailed as you can and you are using sticky notes to do that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1sEKHrCg9oxY-xis2XBkLg.png" /><figcaption>Things on the left happened before things on the right.</figcaption></figure><p>Meeting consists of several phases:</p><ol><li>In the first phase, you want to focus on domain events. One helpful technique here is to think about one domain event and then think what must happen before this event to make this possible. A simple example can be <em>OrderSent</em>. Before we can send an order we need to process payment so we need <em>PaymentAuthorized</em>. What do we need to authorize payment? We need to submit a new order, and so on. During this phase, you should produce as much domain events as you can.</li><li>In the second phase, you have to think what action/command caused every domain event. Actions are usually represented by verbs, for example, <em>DeliverOrder</em>, <em>RefundPayment</em>, <em>AddProductToOrder</em>.</li><li>The third phase is about aggregates. Aggregate is responsible for decision making. You need to decide which commands should be grouped together and can be handled by the same aggregate.</li><li>One additional phase you can do is about read models. It’s sometimes helpful to think what kind of read models you will need and put this on the wall.</li></ol><p>At this point, your wall will be full of sticky notes and it should look more or less like in the image below (of course with much more sticky notes).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2S59pe_f15d9fh0QOG06Ew.png" /><figcaption>Basic example of interactions between different layers from DDD.</figcaption></figure><p>One thing you can notice by looking at the wall is that some sticky notes are more grouped together/related than others. That’s the sign of bounded context. A really nice thing about event storming is that you can use it to identify bounded contexts in your system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i7Xd2BLChI9mzFVmDG_wfA.png" /><figcaption>Two independent bounded contexts represented by sticky notes.</figcaption></figure><p>Detecting bounded contexts is only one of the reasons to do event storming session. Maybe you are not interested in the whole system and you prefer to focus on one business process or one small part of the system. This technique scales really well and can be used in different scenarios.</p><p><strong>Is it worth doing without domain experts?</strong></p><p>Very often you can hear that event storming without domain experts doesn’t have any sense. I agree that you can achieve way more and probably much faster with domain experts but it’s not a complete waste of time without them. Event storming session without domain experts can still be very useful in organizing domain knowledge or even documenting the system.</p><p>In our company, we don’t have very often access to domain experts but we organize event storming sessions anyway. After each session, we know something more about our domain and we are able to ask more questions to the client.</p><p><strong>Summary</strong></p><p>You have basic knowledge about event storming and you are ready to prepare your first event storming session. I strongly encourage you to try at least one time and see on your own if it’s worth it or not. In my opinion, this is a great tool that can be used in many different situations.</p><p>If you want to learn more you can read <a href="https://www.eventstorming.com/book/">this</a> book written by Alberto.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efa7129596c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails Architect MasterClass: Bounded Contexts]]></title>
            <link>https://medium.com/@mariuszkapcia/rails-architect-masterclass-bounded-contexts-b03a6d01653a?source=rss-ebbdeac252b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/b03a6d01653a</guid>
            <category><![CDATA[bounded-context]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <dc:creator><![CDATA[Mariusz Kapcia]]></dc:creator>
            <pubDate>Sun, 09 Dec 2018 21:38:20 GMT</pubDate>
            <atom:updated>2018-12-11T11:15:10.003Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tTav7IQUfUN9BrMo3sQyIA.jpeg" /></figure><p>In the first week of the course, we had an introduction to the idea of bounded contexts. Currently, in the second week, we are learning more details about this concept and how to apply it in real-life projects.</p><p><a href="https://martinfowler.com/bliki/BoundedContext.html">Bounded context</a> is one of the strategical patterns in Domain-driven design. Most projects are split horizontally as you can see in the image below and it’s called layered architecture. We have different layers for business logic, presentation, and persistence. Number of layers depends on a project but the main idea here is to group our components/classes inside those layers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*obquNYJoxC4ayqa0xGMhRw.png" /></figure><p>Such architecture is perfectly fine, but over time with each new functionality, it’s harder to maintain. The problem here is that we have to focus on the whole system to modify even a small part of it. Bounded context can be described as vertical separation. We can still have layers in each bounded context but in addition, we separate our code vertically into independent units which can work on their own. Thanks to that, we can work on one small part of the system and forget about everything else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EnaAC8TZsOVZlWCwh1pEsw.png" /></figure><p>Of course such unit should contain related components which are used to solve one or more problems. Simple examples of bounded contexts are:</p><ul><li><em>Identity</em>, responsible for users management, authentication, and sometimes authorization.</li><li><em>Notifications</em>, responsible for sending emails, push notifications, text messages.</li><li><em>Accounting</em>, responsible for managing finances.</li><li><em>Ordering</em>, responsible for placing new orders, applying discounts, choosing a payment method, and so on.</li></ul><p><strong>How bounded contexts interact with each other?</strong></p><p>After introducing bounded contexts we need a way to propagate information between them. In event-driven systems, <a href="https://martinfowler.com/eaaDev/DomainEvent.html">domain events</a> are published. Domain event represents a fact from our system, for example, <em>OrderSubmitted</em><strong> </strong>or<strong> </strong><em>ReservationCancelled</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jH9eW8amn0OChqN8a3mECw.png" /></figure><p>Bounded context can publish their own events and subscribe to events from other contexts. In the example above <em>Ordering</em> bounded context is publishing <em>OrderSubmitted</em> domain event and <em>Notifications</em> bounded context is sending email to the customer as a result.</p><p><strong>How can we detect bounded context?</strong></p><p>There are many techniques to identify bounded context but unfortunately, there is no silver bullet here. It’s one of those things you need to practice and over time it’s easier to see if some part of the system is a good candidate for a bounded context.</p><p>Below you can find my top three techniques I’m using in my daily work:</p><ul><li>Consider if such bounded context can exist as independent microservice. Very often distributed systems are not built as microservices but as distributed monoliths. It basically means that if one service is down then the others can’t work properly. If your bounded context can’t work on their own then it’s not a good candidate.</li><li>Try to imagine your system in the real world, with physical persons. What kind of persons do you need? In most cases, you will see that you need people from different departments and these departments can be represented as bounded contexts.</li><li><a href="https://www.eventstorming.com/">Event storming</a>. I will write another blogpost about this technique.</li></ul><p>That’s it for now. I hope you liked it. There is a lot of new things here and I only scratched the surface. I think this topic is worth learning. In my opinion, the whole team can benefit from this technique.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b03a6d01653a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails Architect MasterClass]]></title>
            <link>https://medium.com/@mariuszkapcia/rails-architect-masterclass-f0ec0b440a05?source=rss-ebbdeac252b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0ec0b440a05</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[event-sourcing]]></category>
            <category><![CDATA[cqrs]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <dc:creator><![CDATA[Mariusz Kapcia]]></dc:creator>
            <pubDate>Sun, 02 Dec 2018 14:38:51 GMT</pubDate>
            <atom:updated>2018-12-10T10:01:29.781Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rails Architect MasterClass: Let’s begin!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3FaG7dU4v3BafNSJNGRSYA.jpeg" /></figure><p>Recently I joined a new online course <a href="https://arkency.com/masterclass/">Rails Architect MasterClass</a> organized by <a href="https://arkency.com/">Arkency</a>. You can see the whole description in the link above but, in brief, the main goal is to learn techniques related to Domain-driven design, <a href="https://martinfowler.com/bliki/CQRS.html">CQRS</a>, and <a href="https://martinfowler.com/eaaDev/EventSourcing.html">Event Sourcing</a>. After this, you will be able to use those techniques in new projects and existing legacy code base.</p><p>The course is divided into 12 weeks. Each week is about a different topic with lots of materials and exercises to do. In this mini-series, I will try to post at least one blogpost per week about current topics, what I’ve learned and if I like it or not. So let’s start..</p><h4>Week 1</h4><p>It’s mostly an introduction and setup. We are using three tools:</p><ol><li><a href="https://teachable.com/">Teachable</a> as an online platform for accessing materials and exercises. We received an invitation and simple instructions on how to use it.</li><li><a href="https://slack.com/">Slack</a> for communication. This is the place where we can ask all our questions and talk to each other. We have a few channels for different topics to help organize and to group communications.</li><li><a href="https://zoom.us/">Zoom</a> for live meetings. Once every two weeks, there will be a live meeting during which we can talk about our problems/challenges and help each other.</li></ol><p>When configuration is done we can start watching materials. I would say it can be divided into two groups:</p><ol><li>A short introduction to the course and why it’s worth learning those things.</li><li>Learning what is <a href="https://martinfowler.com/bliki/BoundedContext.html">bounded context</a> and how to detect them in your system.</li></ol><p>The last thing was homework. Our first task was to introduce ourselves, talk about our experience with Ruby on Rails but also with others technologies. The second part of this homework was to try to detect bounded contexts in your current project or in your side project.</p><p>That’s all for the first week. I’m pretty excited about it and I hope I will learn a lot of new things during those 12 weeks.</p><p>See you soon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0ec0b440a05" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>