Hive realtime lives inDocumentation Index
Fetch the complete documentation index at: https://docs.tuturuuu.com/llms.txt
Use this file to discover all available pages before exploring further.
apps/hive-realtime. It is a Bun WebSocket service used
only by Hive; do not replace it with Supabase Realtime.
Required Environment
HIVE_REALTIME_TOKEN_SECRET: preferred shared HMAC secret used byapps/webto mint short-lived join tokens and byapps/hive-realtimeto validate them. If this is not set, both services fall back to the existing platform Supabase service secret from the sharedapps/webenvironment. This keeps Hive deployable with the same Supabase setup asapps/web, while still allowing operators to rotate Hive realtime signing independently later.HIVE_REALTIME_URL: internal server URL used byapps/webandapps/hivewhen they need the service-side endpoint.NEXT_PUBLIC_HIVE_REALTIME_URL: browser-facing WebSocket URL, normallywss://hive.tuturuuu.com/realtimein production.- Supabase credentials already used by
apps/web, especiallyNEXT_PUBLIC_SUPABASE_URLwithSUPABASE_SECRET_KEY.SUPABASE_SERVER_URLmay still override the server-side URL when the deployment needs a Docker-internal Supabase origin.
apps/hive shares the same Supabase setup as apps/web. Docker runtime env
comes from .env.local with the same apps/web/.env.local fallback, and the
production Hive image receives the web_env BuildKit secret during next build
so prerendered auth routes can resolve NEXT_PUBLIC_SUPABASE_URL and related
platform Supabase variables.
Local production-style servers (Turbo)
From the repo root, Turbo runs workspace dependency builds first, then starts each process (seeturbo.json tasks @tuturuuu/hive#serve:hive and
@tuturuuu/hive-realtime#serve:hive-realtime):
bun serve:hive— production Next server for Hive on port7814(requires a priornext buildoutput; Turbo schedulesbuildbeforeserve:hive).bun serve:hive-realtime— Bun WebSocket server (default port7815viaPORT).
Blue/Green Deployment
docker-compose.web.prod.yml runs hive-blue, hive-green, and
hive-realtime with the same production Supabase environment as apps/web.
scripts/docker-web/blue-green.js promotes Hive with the same active color as
web and waits for the target Hive color before proxy handoff.
The generated nginx config routes:
hive.tuturuuu.com/to the activehive-{color}satellite app on port7814.hive.tuturuuu.com/realtimetohive-realtimeon port7815.
7814, so a Cloudflare tunnel
mapping hive.tuturuuu.com to localhost:7814 still goes through the
blue/green proxy instead of bypassing it to a stale single Hive container.
scripts/watch-blue-green-deploy.js watches the Hive Dockerfiles, package
manifests, realtime source files, and docker-compose.web.prod.yml; changes to
these files trigger the watcher container refresh path.
Protocol
Clients connect with a short-lived token fromPOST /api/v1/hive/servers/:serverId/realtime-token. Tokens include user ID,
server ID, role, expiry, and event scopes.
Accepted client messages are typed commands:
block.placeblock.removeobject.placeobject.removeobject.movenpc.movenpc.confignpc.decisionserver.metadataselectionpresence.join
apply_hive_world_event(...)
RPC so stale revisions are rejected before broadcast. Revision conflicts are a
normal editor sync condition, not an operational error. The web API checks the
current revision before calling the RPC, and the RPC returns an empty result for
last-moment conflicts instead of raising hive_revision_conflict; this prevents
stale editors from flooding Postgres logs and database usage.
The Hive client also serializes world-edit saves and applies a short cooldown
after a conflict. If a user edits against an old revision, Hive reloads the
latest snapshot and waits for the next explicit edit instead of immediately
retrying a rebased mutation loop.
When an edit is accepted by the central API first, the Hive app emits
world.event.applied to the WebSocket service. The realtime service validates
that the token server ID matches the event server ID, then broadcasts the event
and full accepted world snapshot to that server room. This keeps other clients
from resurrecting deleted blocks by refetching a stale snapshot before the
accepted revision is visible.