- This is a Bun/Turborepo workspace with the deployable package
@socketo/server, the reusable@socketo/corepackage, and the Node@socketo/clipackage. Cloudflare application code is underapps/server/. - The Worker entrypoint is
apps/server/src/index.ts; it exports theDatabaseDOandServerDODurable Object classes and the Hono fetch handler. ServerDOowns WebSocket lifecycle, subscriptions, presence, and broadcasting per app;DatabaseDOis thedefaultsingleton that stores app credentials/configuration in SQLite.- The public API is mounted at
/app/:keyfor WebSockets and/apps/:key/*for authenticated REST operations; protocol version7is required for WebSocket upgrades.
- Install with
bun install; this repository is pinned to Bun1.3.12and requires Node>=20. - Run all workspace development tasks with
bun run dev; run only the Worker withbun run --filter=@socketo/server dev. - Build everything with
bun run build; build only the Worker withbun run --filter=@socketo/server build. - Build the shared core with
bun run --filter=@socketo/core buildand the CLI withbun run --filter=@socketo/cli build. - Run unit tests with
bun test(44 unit tests, 250 assertions across core and CLI) or focus on core withbun run --filter=@socketo/core test(25 unit tests, 188 assertions). - Start the local CLI with
bun run --filter=@socketo/cli start; it is a standalone Nodewsadapter over@socketo/core. - Deploy only through
bun run --filter=@socketo/server deploy; this runsvite buildbeforewrangler deploy. - Regenerate Cloudflare bindings after changing
apps/server/wrangler.jsoncwithbun run --filter=@socketo/server cf-typegen;apps/server/worker-configuration.d.tsis generated and should not be edited manually. - Run
bunx oxlint .for the configured Oxlint rules;bunx tsc -p apps/server/tsconfig.json --noEmitis the focused typecheck.
- Start the Worker before initializing local data:
bun run --filter=@socketo/server dev. - Run
curl -X POST -H "Authorization: Bearer <ADMIN_API_TOKEN>" http://localhost:8787/migrateafter settingADMIN_API_TOKENinapps/server/.dev.vars; deployed Workers require theADMIN_API_TOKENsecret. - Add an app row through Wrangler Local Explorer at
http://localhost:8787/cdn-cgi/explorer/do/DatabaseDO/default?table=apps; the required fields and defaults are documented inREADME.md. - Database schema migrations are defined in
apps/server/src/database/migrations.tsand executed byDatabaseDO; Wrangler Durable Object class migrations are separately declared inapps/server/wrangler.jsonc.
- Preserve the Durable Object class names and existing migration tags in
apps/server/wrangler.jsonc; changing them can affect deployed object state. - Socket IDs generated across all WebSocket connections follow the official Pusher Channels standard
<int>.<int>(generateSocketId()from@socketo/core). - REST authentication requires the Pusher auth query parameters (
auth_version=1.0,auth_timestampwithin ±600s) and, for POST/PUT/PATCH requests, a matchingbody_md5; seeapps/server/src/api/middlewares/auth-middleware.ts. ServerDOloads and caches app configuration in memory in its constructor viablockConcurrencyWhile. Changes made through Local Explorer may not affect an activeServerDOuntil it restarts, hibernates, or is redeployed. This includeswebhook_endpoints— webhook additions/removals also require a restart to take effect.- Keep Worker/runtime-specific code out of reusable protocol logic.
@socketo/coreowns protocol state, socket ID generation, and validation; the Durable Object and CLI packages provide their respective WebSocket adapters. - Do not format or lint
apps/server/worker-configuration.d.tsas ordinary source; regenerate it with Wrangler instead.