# CyberNet × RuView deployment (Bring Your Own Render)

## Accounts and ownership

- CyberNet frontend: Vercel project `cybernetapp` (GitHub repository `MyselfHumayunShariarHimu/CyberNet`, branch `main`).
- Each user supplies their own Render workspace/API key and creates their own gateway + private RuView engine + optional private Operator MCP service from `render.yaml`.
- No central CyberNet Render account is used. Services, secrets, disks, compute and bills remain in the user's Render account.

## Deploy CyberNet frontend

1. Push the project root to the connected GitHub repository.
2. Vercel deploys the static site and the `/api/render/*` serverless proxy from the same repository.
3. Confirm the root `index.html`, `css/`, `js/`, `icons/`, `manifest.json`, `sw.js`, `api/` and `vercel.json` are at repository root.

## Provision the user's Render stack

1. In the user's Render account, create a workspace-scoped API key. Grant only read access for inspection; add service write and deploy permissions only if using the corresponding API actions. Never share the key outside that workspace.
2. In Render, connect the user's GitHub repository and create a Blueprint from `render.yaml`.
3. Select the intended region (the Blueprint currently defaults to Singapore). Gateway and engine must be in the same region for private networking.
4. Review the Blueprint plan before approval. It provisions a public gateway, private `ruvnet/wifi-densepose:latest` engine, private `@ruvnet/ruview` Operator MCP service, generated secret groups, and a persistent disk. Plans and disk incur charges according to Render's current pricing and the user's workspace.
5. Approve the Blueprint sync. Wait for the gateway, sensing engine, and Operator MCP service to reach their expected healthy/ready states; private services may expose limited public health status.
6. In the gateway service's environment, note generated `CYBERNET_ACCESS_TOKEN` (admin/full access, retained for compatibility), `CYBERNET_OPERATOR_TOKEN`, `CYBERNET_READ_TOKEN` and `EDGE_INGEST_TOKEN`. These are generated secrets; do not add them to Git.
7. Set `CYBERNET_ALLOWED_ORIGINS` to a comma-separated exact list of the CyberNet front-end origins (scheme + host + optional port, no paths). If unset, only same-origin browser requests are accepted; command-line bearer clients without an `Origin` header still work.
8. In CyberNet → RuView Core, set the gateway HTTPS URL and the least-privilege token needed: read-only for inspection, operator for the explicit supported mutation routes, admin for MCP tool calls and full API control. In the Render Connection panel, connect the user's separate Render API key to inspect services and trigger deployments.
9. Run the LAN relay on a host that can receive the ESP32 UDP packets and reach the gateway over WSS. Set the gateway WSS URL and `EDGE_INGEST_TOKEN`. Provision each ESP32 node with that LAN host's IP and UDP port 5005.
10. Verify `/healthz` on the gateway, then connect CyberNet to the gateway and verify `/health`, `/api/v1/info`, `/api/v1/nodes`, `/api/v1/sensing/latest`, `/ws/sensing` and `/ws/field`.
11. In RuView Core → Operator MCP, click **Use this gateway MCP**, then **Connect & discover tools**. MCP `tools/call` requires admin scope; the gateway forwards to the private Operator service. Hardware-only tools still require a local/remote host with the board attached.

## Optional direct BLE CSI ingest from the browser

The Device Hub can forward actual GATT notification bytes directly to the user's gateway without a LAN UDP relay. First connect to the ESP32 in the BLE card, allow its service UUID during the browser chooser, then select the exact discovered notify/indicate characteristic. Enter the gateway URL as `wss://YOUR-GATEWAY.onrender.com/edge/ingest` and paste that gateway's `EDGE_INGEST_TOKEN`; CyberNet asks for confirmation, sends the token only in the WSS handshake, and clears the token field after a successful connection. The key is not written to local or session storage.

This path has a strict firmware contract: every selected GATT notification must contain exactly one complete raw CSI UDP packet that the deployed RuView engine accepts, between 1 and 9000 bytes. CyberNet forwards bytes unchanged; it does not infer CSI from arbitrary GATT values, decode firmware framing, reassemble fragments, or synthesize samples. If the device uses chunked or proprietary framing, provide a documented firmware adapter or use the LAN relay path instead. The gateway's `accepted` message confirms that its UDP send call succeeded; verify actual engine ingestion in RuView's live CSI status/recordings.

For cross-origin use, add the exact HTTPS CyberNet origin to `CYBERNET_ALLOWED_ORIGINS` and redeploy the gateway. The gateway continues to enforce the edge token and Origin allowlist. Browser support for Web Bluetooth varies by browser and OS; the Device Hub's actual data path requires a secure context and a compatible browser.

## Security / network notes

- The public gateway exposes HTTPS/WSS only. The RuView engine remains a private service.
- The LAN relay bridges UDP to authenticated WSS; the gateway forwards UDP over Render's private network to the RuView engine. Keep both services in the same Render region/workspace.
- Do not expose the private RuView service publicly to avoid the relay.
- Rotate generated gateway tokens if exposed. The operator token permits only the documented gateway allowlist; the read token cannot mutate. MCP tool calls require the full admin token because upstream tool annotations are not trusted as an authorization boundary.
- The gateway applies 120 requests/minute per client IP across RuView/MCP proxy routes; tune this in `server/index.js` only after reviewing capacity and abuse risk.
- Render API key entry in CyberNet is memory-only. Disconnect or close the tab to clear it. The Vercel proxy forwards it per request and does not persist it.
- The browser cannot open UDP sockets. Do not remove the LAN relay from the CSI data path.

## Troubleshooting

- Gateway `401`: confirm the `CYBERNET_ACCESS_TOKEN` in CyberNet exactly matches the gateway environment.
- Edge relay `401`: confirm `EDGE_INGEST_TOKEN` and use the `/edge/ingest` WSS path.
- No CSI frames: check the node's target IP/UDP port, relay logs, gateway WSS connectivity, and whether any other process has bound UDP 5005 on the LAN host.
- Gateway `502`: verify the private service is healthy, same-region private networking is available, `RUVIEW_PRIVATE_HOST` resolves, and RuView listens on configured ports.
- Operator MCP `503`: the Operator service is not configured or has not started. Check `RUVIEW_MCP_PRIVATE_HOST`, the private service logs, and the `@ruvnet/ruview` package command. A local MCP host can be used instead for USB-only tools.
- Operator MCP `401`: use the gateway's `CYBERNET_ACCESS_TOKEN` in CyberNet, not the Render API key.
- Render API `403`: the connected API key may lack the required workspace permission or the operation is not on the CyberNet allowlist.
- Android USB: use Chrome over HTTPS, an OTG adapter and a supported USB-serial interface; if the device is claimed by a system driver, WebUSB cannot access it.
- Android Bluetooth: use a browser exposing Web Bluetooth; choose a device in the browser prompt and supply custom service UUIDs before connecting. Only GATT notify/indicate values are streamed. The browser cannot enumerate/change the Android system hotspot or Wi-Fi network; join the same hotspot manually and test the node IP.
- BLE CSI bridge shows WSS connection but no acknowledged frames: select the correct subscribed characteristic, verify that one notification is a complete RuView-compatible datagram, confirm the gateway Origin allowlist and `EDGE_INGEST_TOKEN`, then check RuView engine ingestion separately. A gateway UDP acknowledgement alone is not proof of CSI parsing or sensing.

## Optional Android-only relay host (Termux)

The CyberNet web page can control the USB board through WebUSB where the Android browser/USB adapter permits it. It cannot bind a UDP socket itself. If you want the same Android phone to receive CSI UDP and tunnel it to Render, install Termux from its official F-Droid/GitHub distribution, then run the included Python relay in Termux:

```sh
pkg update && pkg install python
python -m pip install 'websockets>=14,<16'
# Put edge/ruview-udp-tunnel.py on the phone, then:
export CYBERNET_GATEWAY='https://YOUR-GATEWAY.onrender.com'
export EDGE_INGEST_TOKEN='YOUR_EDGE_INGEST_TOKEN'
export CSI_LISTEN='0.0.0.0'
export CSI_PORT='5005'
python ruview-udp-tunnel.py
```

Provision the ESP32 target IP to the phone's current LAN/hotspot IP and UDP port 5005. Android hotspot/client isolation, battery optimization, Wi-Fi sleep and Termux background restrictions can interrupt reception; keep Termux foregrounded and test the UDP path. This is an optional native helper process, not a browser-only capability. A separate always-on LAN host is more reliable for production.
