     {:automatic, state}
   end
 
+  @doc """
+  Handles events from the `GenStage`, i.e. from the backend
+  to store build events in the database and to propagate them
+  towards the client browsers.
+  """
   def handle_events(events, _from, _state) do
     Logger.debug("Build Channel received #{inspect Enum.count(events)} events")
     Enum.each(events, fn ev -> broadcast_event(ev) end)
     {:noreply, [], nil}
   end
 
+  @doc """
+  Join the channel. For now, there is only the `build:lobby` without
+  any further authorization and differentiation between users, projects
+  and builds.
+  """
   def join("build:lobby", payload, socket) do
     if authorized?(payload) do
       {:ok, socket}

  @doc """
  Broadcast an event. Currently, we use the default topic `build:lobby`.
  """
  def broadcast_event(ev = %BuildEvent{}) do
    BaumeisterWeb.Endpoint.broadcast("build:lobby", "build_event", event_to_map(ev))
  end
  def broadcast_event(ev = {role, action, step}) do
    BaumeisterWeb.Endpoint.broadcast("build:lobby", "old_build_event", event_to_map(ev))
  end

  def event_to_map(%BuildEvent{action: action, data: data, coordinate: coord}) do
    %{"role" => "worker",
      "action" => Atom.to_string(action),
      "data" => "#{inspect data}",
      "coordinate" => "#{inspect coord}"
    }
  end
  def event_to_map({role, action, step}) do


  alias Baumeister.BuildEvent
  alias Baumeister.Observer.Coordinate
  alias BaumeisterWeb.Project
  alias BaumeisterWeb.Build

  @moduledoc """
  The Channel for build events is listener of the EventCenter
