# 5.3.3 Device Identity Registration and Presence

This diagram shows how a signed-in user registers a browser as a device and how presence is maintained after realtime connection.

```mermaid
sequenceDiagram
    autonumber
    participant User as Signed-in User
    participant Web as WebApp Controller
    participant Devices as POST /devices/register
    participant DB as devices + device_links
    participant Token as Device Token
    participant Socket as Socket.IO Gateway

    User->>Web: submit onboarding role + name
    Web->>Devices: register device
    Devices->>DB: insert devices row
    Devices->>DB: auto-link to opposite-role devices if present
    Devices-->>Web: return device + deviceToken
    Web->>Web: persist saved device record
    Web->>Socket: connect with device token
    Socket->>DB: mark device online
    Web->>Socket: periodic heartbeat
    Socket->>DB: update lastSeenAt and status
    Socket-->>Web: connection + heartbeat acknowledgements
```
