API and Data Flow
How commands and state move between Dashboard, API, and Agent.
This page explains how tug.sh moves state and actions through the control plane.
Runtime sequence
- Agent boots and authenticates with a server token.
- Agent opens outbound WebSocket to
api.tug.shand sends handshake metadata. - Dashboard sends user actions to API REST endpoints.
- API validates permissions and forwards command to the target Agent.
- Agent executes command and returns structured result (
success,logs, optionalpayload). - API updates state and broadcasts events to dashboard clients in real-time.
Key endpoints and data contracts
Server and container state
GET /v1/servers- Returns server list (
id,name,status,ip, capacity fields).
- Returns server list (
GET /v1/servers/:serverID/containers- Returns container snapshot (
id,name,image,ports,status,networks,project_id,log_preview).
- Returns container snapshot (
Runtime actions
POST /v1/servers/:serverID/containers/:containerID/actions- Body:
{ "action": "start|stop|restart|remove", "db_only": false, "remove_volumes": false, "remove_image": false } - API forwards command to Agent and returns command outcome.
- Body:
TugRouter routes
GET /v1/servers/:serverID/apps/tug-router/routes- Returns route list:
{ "items": [{ "domain": "app.example.com", "target": "container-name", "port": 80 }] }
- Returns route list:
POST /v1/servers/:serverID/apps/tug-router/routes- Body:
{ "domain": "app.example.com", "target_container_id": "container-id", "target_port": 80 }
- Body:
DELETE /v1/servers/:serverID/apps/tug-router/routes/:domain- Removes a route and reloads TugRouter config through Agent.
Agent command channel (WebSocket)
- API -> Agent command message example:
{ "type": "container_action", "command_id": "...", "container_id": "...", "action": "restart" }
- Agent -> API command result example:
{ "type": "command_result", "command_id": "...", "success": true, "logs": ["..."], "payload": { ... } }