# Athena WebSocket Gateway (Bun)

A zero-dependency Bun server that exposes `/wss/gateway` and proxies WebSocket messages to the Rust HTTP API. It keeps the full gateway surface area available on a single, high-throughput connection.

## Quick start

```bash
cd apps/wss-gateway
bun install # no deps, but records Bun version
PORT=7070 ATHENA_API_BASE=http://localhost:4052 bun run src/index.ts
```

Then connect a client to `ws://localhost:7070/wss/gateway` and send gateway-shaped JSON messages. A simple example:

```json
{
  "action": "gateway.fetch",
  "client_name": "demo_client",
  "path": "/gateway/fetch",
  "body": { "resource": "users", "filters": {"id": {"eq": 1}} }
}
```

## Runtime knobs

- `PORT` / `ATHENA_WSS_PORT`: WebSocket listener port (default `7070`).
- `ATHENA_API_BASE`: Base URL for the Rust API (default `http://localhost:4052`).
- `ATHENA_API_TIMEOUT_MS`: Upstream HTTP timeout per message (default `15000`).

## Contract

- `action` is used for defaults, but any HTTP path is accepted via `path`.
- `client_name` is propagated as `X-Athena-Client`.
- `headers`, `query`, and `body` are forwarded to the upstream call.
- Responses mirror the upstream HTTP status plus parsed JSON/text payload inside `data.body`.

The HTTP endpoint `/wss/info` returns a small capability document; `/health` and `/ready` report liveness.

## Tests

```bash
cd /Users/floris/Documents/GitHub/athena/apps/wss-gateway
bun test
```
Tests spin up a stub upstream API and a gateway instance on an ephemeral port, exercise `/wss/info`/`/health`, and round-trip a WebSocket `gateway.fetch` call while asserting `X-Athena-Client` propagation.
