@startuml
title Route Collision Dispatch (After)

skinparam backgroundColor White
skinparam defaultFontColor Black
skinparam sequence {
  ArrowColor Black
  LifeLineBorderColor Black
  LifeLineBackgroundColor #FFFFFF
  ParticipantBorderColor Black
  ParticipantBackgroundColor #E8EEF9
  ActorBorderColor Black
  ActorBackgroundColor #F5F8FF
}

actor "Client" as Client
participant "AthenaAuth::handle_request_inner" as Pipeline
participant "Collision detector\n(method + path)" as Collision #E8F6E8
participant "Plugin dispatcher\nplugin.on_request" as Plugin #D9F0FF
participant "Core dispatcher\nhandle_core_request" as Core #FFD7D7

Client -> Pipeline: Request (normalized path)
Pipeline -> Collision: is_core_plugin_collision?

alt Exact core+plugin collision
  Collision --> Pipeline: yes
  Pipeline -> Plugin: Try plugin handlers first
  alt Plugin handles request
    Plugin --> Pipeline: response
    Pipeline --> Client: plugin response
  else Plugin does not handle
    Plugin --> Pipeline: none
    Pipeline -> Core: fallback to core
    Core --> Pipeline: response
    Pipeline --> Client: core response
  end
else No collision
  Collision --> Pipeline: no
  Pipeline -> Core: Core-first unchanged
  alt Core handles request
    Core --> Pipeline: response
    Pipeline --> Client: core response
  else Core no match
    Core --> Pipeline: none
    Pipeline -> Plugin: normal plugin fallback
    Plugin --> Pipeline: response or none
    Pipeline --> Client: plugin response or 404
  end
end

@enduml
