@startuml
    participant "Loculus Frontend / User" as frontend #LightCyan
    participant "(Pre-)Processing Pipeline" as processing #LightGreen
    participant "Loculus Backend" as backend #Orange
    database "Database" as DB

    frontend -> backend: submit initial sequence data
    alt Sequence and Metadata Files are valid
        backend -> frontend: response with accessions
        backend -> DB: Store initial sequence data
        backend -> DB: set status to 'RECEIVED'
    else Sequence and Metadata Files are invalid
        backend -> frontend: response with error
    end

   note right of frontend
      In the following we assume initial raw sequence data are valid
   end note

    loop until no processing errors

        processing -> backend: Query initial/edited sequence data
        backend -> DB: Query initial/edited sequence data
        backend -> DB: Set status from 'RECEIVED' to 'IN_PROCESSING'
        DB --> backend: initial/edited sequence data
        backend --> processing: initial/edited sequence data

        processing -> backend: submit processed sequence data
        alt validation errors occur
            backend -> processing: response with validation errors
             note right of frontend
                  Validation error are probably only redeemable by changing the pre-processing pipeline
                  In the following we assume that no validation error occurred
               end note
        end loop

        backend -> DB: Store processed sequence data
        backend -> DB: set status to 'PROCESSED'

        frontend -> backend: query processed sequence data with errors
        frontend -> frontend: address errors and edit sequence data

        frontend -> backend: submit edited sequence data
        backend -> DB: store edited sequence data
        backend -> DB: set status to 'RECEIVED'
    end loop


    frontend -> backend: Query processed sequence data
    backend -> DB: Query processed sequence data
    DB -> backend: processed sequence data
    backend -> frontend: processed sequence data

    frontend -> backend: approve processed sequence data
    backend -> DB: set status from 'PROCESSED' to 'APPROVED_FOR_RELEASE'

@enduml

