Authentication Pipeline

๐ŸŽฌ Mermaid Sequence Diagram - Generated by GenServerVirtualTime
This diagram was automatically generated from simulation trace events.
sequenceDiagram api->>auth: {:check_auth, :user123} auth->>database: {:check_auth, :user123} database->>api: {:auth_ok, :token456} api->>auth: {:check_auth, :user123} auth->>database: {:check_auth, :user123} database->>api: {:auth_ok, :token456} api->>auth: {:check_auth, :user123} auth->>database: {:check_auth, :user123} database->>api: {:auth_ok, :token456} api->>auth: {:check_auth, :user123} auth->>database: {:check_auth, :user123} database->>api: {:auth_ok, :token456}

๐Ÿ’ป Model Source Code

This is the Elixir code that defines the actor simulation model:

# Create a pipeline with message forwarding
forward = fn msg, state ->
  {:send, [{state.next, msg}], state}
end

simulation =
  ActorSimulation.new(trace: true)
  |> ActorSimulation.add_actor(:api,
    send_pattern: {:periodic, 100, {:check_auth, :user123}},
    targets: [:auth]
  )
  |> ActorSimulation.add_actor(:auth,
    on_receive: forward,
    initial_state: %{next: :database}
  )
  |> ActorSimulation.add_actor(:database,
    on_receive: fn
      {:check_auth, _user}, state ->
        {:send, [{:api, {:auth_ok, :token456}}], state}

      _, state ->
        {:ok, state}
    end
  )
  |> ActorSimulation.run(duration: 400)