How brayden/pubsub works
1. Project shape
- This is a small TypeScript-based Cloudflare Workers project named pubsub.
- The repository is centered around an edge runtime service with Durable Objects for stateful coordination, which strongly suggests a pub/sub or MQTT-style broker implementation.
2. Runtime boundary
- src/index.ts is the main worker entry point.
- wrangler.jsonc and worker-configuration.d.ts indicate the app is deployed and bound through the Cloudflare Workers platform.
- The worker is the public ingress: it receives requests and delegates stateful behavior to Durable Objects.
3. Stateful core
- src/durable-objects/topic.ts and src/durable-objects/client.ts are the two main stateful subsystems.
- topic.ts likely manages per-topic coordination, subscription lists, and message fan-out.
- client.ts likely manages per-client/session state such as connection lifecycle, identity, or delivery bookkeeping.
- These two Durable Objects form the main architectural boundary between stateless request handling and persistent coordination.
4. Request/message flow
- Incoming traffic enters the worker in src/index.ts.
- The worker likely resolves the relevant Durable Object instance by topic or client identity, then forwards the request/message to it.
- Durable Objects then handle state transitions and coordination without needing an external database.
5. Protocol/domain model
- src/types/mqtt.ts indicates a dedicated MQTT protocol/domain type layer.
- That suggests protocol packets, message shapes, or broker semantics are represented explicitly rather than as ad hoc objects.
- The architecture is therefore protocol-aware, not just generic pub/sub.
6. Shared configuration types
- src/types/env.ts defines the worker’s runtime environment contract.
- This is the boundary for Cloudflare bindings, secrets, and Durable Object namespaces.
- In architecture terms, it separates platform configuration from broker logic.
7. Client-facing surface
- index.html and mqtt.html are static HTML assets at the repo root.
- They likely serve as a minimal UI/demo harness for interacting with the worker or MQTT broker.
- These files are ancillary, not the core runtime, but they show there is a browser-facing interaction path.
8. No traditional backend datastore
- There is no evidence of a database, queue, or cache layer in the tree.
- Persistent/stateful behavior appears to be handled primarily by Cloudflare Durable Objects.
- That makes the system edge-native and self-contained.
9. Operational/deployment tooling
- package.json, pnpm-lock.yaml, and tsconfig.json define the build and TypeScript toolchain.
- wrangler.jsonc is the deployment and environment definition for Cloudflare.
- The architecture is therefore "TypeScript app + Cloudflare runtime" rather than a separate app server plus infrastructure stack.
10. Likely architectural diagram framing
- A useful diagram would show:
- browser/client or MQTT client on the left,
- Cloudflare Worker as the entry edge,
- two Durable Object classes as stateful coordination nodes,
- shared type definitions and Cloudflare env bindings as the internal contract layer.
- The key design idea is stateless ingress, stateful coordination in Durable Objects.
Main entry points: index.ts Worker · topic.ts Topic DO · client.ts Client DO · env.ts Env Types
Components 13
Client surface
Browser-facing demo and entry pages
Edge runtime
Cloudflare Worker entrypoint and request handling
- Worker · Cloudflare Worker request entry and orchestration layer
src/index.ts - Dispatch · Resolves requests into the correct stateful target
- Cloudflare Workers · Edge runtime and Durable Objects platform boundary
Stateful core
Durable Objects that coordinate pub/sub state
Shared contracts
Protocol and environment types shared across runtime boundaries
- MQTT Types · Protocol packet and message shapes
src/types/mqtt.ts - Env Types · Worker environment and binding definitions
src/types/env.ts
Tooling
Build and deployment configuration
- Wrangler · Cloudflare deployment and binding configuration
wrangler.jsonc - Worker Types · Generated Cloudflare worker type declarations
worker-configuration.d.ts - Package · Project scripts and dependency metadata
package.json - TS Config · TypeScript compiler settings
tsconfig.json
Connections 17
- Web UI → Worker: calls · Browser page interacts with the worker
- MQTT UI → Worker: calls · MQTT-oriented page interacts with the worker
- Worker → Dispatch: routes · Worker classifies inbound requests and forwards them
- Dispatch → Topic DO: topic flow · Topic-related work is delegated to topic state
- Dispatch → Client DO: client flow · Client/session-related work is delegated to client state
- Topic DO → MQTT Types: uses · Topic coordination uses MQTT protocol structures
- Client DO → MQTT Types: uses · Client coordination uses MQTT protocol structures
- Worker → Env Types: binds · Worker reads its platform environment contract
- Topic DO → Env Types: binds · Topic DO depends on configured bindings
- Client DO → Env Types: binds · Client DO depends on configured bindings
- Wrangler → Cloudflare Workers: configures · Deployment file defines the runtime boundary
- Worker Types → Cloudflare Workers: types · Type declarations mirror the platform runtime
- Package → TS Config: builds · Project scripts rely on TypeScript compilation
- Package → Wrangler: deploys · Project tooling targets Cloudflare deployment
- Worker → Cloudflare Workers: runs on · Entrypoint executes inside the Cloudflare edge runtime
- Topic DO → Cloudflare Workers: persists on · Stateful coordination is hosted by Durable Objects
- Client DO → Cloudflare Workers: persists on · Client state is hosted by Durable Objects