@startuml
participant Client
participant "API" as API
participant "Server" as Server
Client -> API: fetchUser(id, callback)
activate API
API -> Server: GET /users/{id}
activate Server
Server --> API: Response (data)
deactivate Server
API ➞ Client: callback(data)
deactivate API
@enduml
Key Conventions
Callback Registration:
Show the callback passed as a parameter in the initial call (e.g., fetchData(callback)).
Asynchronous Symbol:
Use ➞ (PlantUML: -->) or ⟶ to distinguish from synchronous calls (→).
Time Delays:
Explicitly mark delays with ... or labels like "after 1s".
Anonymous Callbacks:
Label the callback message as onComplete(), then(), or callback().
Error Handling:
Add a separate callback path for errors:
plaintext
API ➞ Client: onError(err)
Tools & Notation
PlantUML: Use --> for async callbacks.
Mermaid: Use -->> for async messages.
UML Standard: Dashed line with stick arrowhead (➞).
Anti-Patterns to Avoid
Using synchronous arrows (→) for callbacks.
Omitting the time gap between call and callback.
Not showing callback registration in the initial call.
By following these practices, your sequence diagram will clearly communicate the asynchronous control flow of JS callbacks.