How photon-hq/spectrum-ts works
1. Repository shape
- This is a TypeScript monorepo for Spectrum, a multi-channel agent runtime.
- The repo is organized around one core runtime, several platform/provider packages, thin framework adapters, docs, examples, and release/build automation.
2. Primary architectural boundary: platform-agnostic core
- packages/core is the center of the system.
- It defines the shared domain model for spaces, users, messages, content blocks, webhooks, and platform capabilities.
- It also contains the “authoring” layer for building platform definitions and the runtime pieces that orchestrate provider behavior.
3. Message/content model is a first-class subsystem
- packages/core/src/content/* contains the canonical content types Spectrum understands: text, markdown, replies, edits, attachments, polls, reactions, read receipts, typing indicators, voice, avatars, groups, contacts, custom payloads, and unsend.
- This layer is where platform-specific features are normalized into common message primitives, and where fallback behavior is likely implemented for platforms with weaker feature support.
4. Event ingestion and dispatch flow
- Incoming events enter through provider-specific webhooks, local feeds, or sockets and are normalized into the core event model.
- The app then exposes an async message stream (app.messages in the README) for agent logic.
- Outbound actions flow back through the same abstraction: reply, send, edit, react, mark read, stream text, typing, and unsend are expressed in core terms and translated by the provider.
5. Provider packages are the transport/adapter layer
- packages/imessage, packages/slack, packages/telegram, and packages/whatsapp-business each implement the platform-specific side of the architecture.
- These packages handle auth, message formatting, webhook verification, reactions, polls, media, URL redaction, and other channel-specific mechanics.
- They are the concrete boundary between Spectrum’s shared abstractions and external APIs/datastores.
6. iMessage is the most elaborate provider
- packages/imessage has both local and remote paths.
- The local/* files suggest a mode that talks to a local iMessage database/API and handles local inbound/send flows.
- The remote/* tree suggests a cloud or service-backed mode with client/API wrappers, attachment handling, group events, streaming text, markdown, and identity resolution.
- This package is the clearest example of Spectrum supporting both self-hosted and hosted deployment paths.
7. Telegram, Slack, and WhatsApp Business are thinner provider implementations
- packages/telegram is split into client/config, inbound, outbound, webhook, reactions, and space handling.
- packages/slack is relatively compact, centered around auth and message handling.
- packages/whatsapp-business focuses on auth, messages, and polls.
- These packages indicate a pattern: provider-specific protocol handling, with core translating those events into the shared runtime model.
8. Framework adapters expose Spectrum to HTTP servers
- packages/elysia, packages/express, packages/fastify, and packages/hono are thin integration packages.
- Their role is to make Spectrum’s webhook/event handling usable inside different server frameworks without changing the core runtime model.
- These are boundary adapters, not separate business logic layers.
9. spectrum-ts is the batteries-included façade
- packages/spectrum-ts is the top-level package exposed to consumers in the README.
- It re-exports core functionality and provider entry points under stable import paths like spectrum-ts/providers/imessage.
- It also contains authoring/provider-shim logic, so the package can work as an umbrella SDK while still allowing smaller installs via scoped packages.
10. Terminal support is a standalone interface
- packages/terminal provides a terminal-based interaction surface with a small protocol and binary resolution layer.
- This is another example of Spectrum treating “interface” as a pluggable boundary, not just web or webhook traffic.
11. Docs and examples are part of the product architecture
- docs/ is extensive and organized by platform and feature, which reflects the core domain model: messages, reactions, replies, webhooks, spaces/users, and platform-specific setup.
- examples/basic shows the minimal runtime loop: create the app with credentials and providers, then consume inbound messages and respond.
- The docs also double as a map of supported capabilities per platform.
12. Build, release, and generation tooling
- The repo uses bun, turbo, tsdown, vitest, and biome.
- There are generation scripts for emoji and package manifests, plus release scripts for versioning and publishing.
- GitHub workflows handle CI, docs publishing, previews, and releases, indicating a packaged SDK ecosystem rather than a single deployed service.
13. Test strategy
- Each package has focused tests, while packages/test-support provides shared fixtures/utilities for cloud, platform, webhook, timing, and Vitest support.
- The tests emphasize provider behavior, inbound/outbound conversions, webhook verification, and core normalization rules.
- This reinforces that the important architectural risk is cross-platform consistency.
14. Net effect
- Spectrum is best understood as a core runtime plus provider adapters architecture.
- The key diagram should show: external channels and platform APIs on one side, provider packages in the middle, the shared core runtime as the normalization/orchestration layer, and user code consuming a unified message/space API on the other side.
Main entry points: src/index.ts Core · src/index.ts Spectrum TS · src/index.ts iMessage · publish.ts Tooling
Components 19
Core runtime
Shared domain model, normalization, orchestration, and webhook handling.
- Core · Platform-agnostic domain model and orchestration layer for Spectrum.
packages/core/src/index.ts - Content model · Canonical message/content types and normalization for text, replies, edits, attachments, polls, reactions, receipts, typing, voice, avatars, groups, contacts, custom payloads, and unsend.
packages/core/src/content/types.ts - Fusor · Runtime glue for auth, event parsing, websocket/webhook handling, and provider orchestration.
packages/core/src/fusor/core.ts - Platform API · Authoring and build helpers for defining providers and platform capabilities.
packages/core/src/platform/define.ts - Webhooks · Webhook event verification and deserialization into core events.
packages/core/src/webhook/deserialize.ts - Core utils · Common helpers for streams, identifiers, telemetry, media, markdown, cloud, and storage.
packages/core/src/utils/stream.ts
Provider adapters
Channel-specific transports and protocol translations.
- iMessage · Most elaborate provider with local and remote modes, attachments, groups, streaming, and identity resolution.
packages/imessage/src/index.ts - Telegram · Provider integration for config, client, inbound/outbound messages, reactions, spaces, and webhooks.
packages/telegram/src/index.ts - Slack · Compact Slack integration focused on auth and message handling.
packages/slack/src/index.ts - WhatsApp · WhatsApp Business integration for auth, messages, and polls.
packages/whatsapp-business/src/index.ts
Framework adapters
Thin server-framework integrations for webhook/event handling.
- Elysia · Thin Elysia integration for Spectrum webhook/event handling.
packages/elysia/src/index.ts - Express · Thin Express integration for Spectrum webhook/event handling.
packages/express/src/index.ts - Fastify · Thin Fastify integration for Spectrum webhook/event handling.
packages/fastify/src/index.ts - Hono · Thin Hono integration for Spectrum webhook/event handling.
packages/hono/src/index.ts
SDK facade
Umbrella package that re-exports core and providers under stable paths.
- Spectrum TS · Umbrella package that re-exports core and provider entry points under stable import paths.
packages/spectrum-ts/src/index.ts
Terminal interface
Standalone terminal interaction surface and binary resolution.
- Terminal · Terminal-based interaction surface with protocol and binary resolution.
packages/terminal/src/index.ts
Docs and examples
User-facing documentation and minimal usage examples.
- Docs · Product and capability documentation spanning core concepts and provider setup.
docs/README.md - Basic example · Minimal runtime loop showing app creation, message consumption, and replies.
examples/basic/index.ts
Tooling
Build, release, generation, and test-support infrastructure.
- Tooling · Workspace build, release, generation, and test-support automation.
scripts/release/publish.ts
Connections 24
- Spectrum TS → Core: re-exports · Facade exposes core runtime and shared types.
- Spectrum TS → iMessage: re-exports · Facade publishes provider entry points.
- Spectrum TS → Telegram: re-exports · Facade publishes provider entry points.
- Spectrum TS → Slack: re-exports · Facade publishes provider entry points.
- Spectrum TS → WhatsApp: re-exports · Facade publishes provider entry points.
- Core → Content model: defines · Core owns the canonical content/message model.
- Core → Fusor: orchestrates · Core runtime coordinates provider behavior and event flow.
- Core → Platform API: authors · Core provides platform definition and build helpers.
- Core → Webhooks: verifies · Core validates and deserializes incoming webhook payloads.
- Core → Core utils: shares · Core uses common helpers for runtime support.
- iMessage → Content model: normalizes · Provider maps platform-specific features into shared message primitives.
- iMessage → Core: adapts · Provider implements Spectrum's shared runtime contract.
- Telegram → Core: adapts · Provider implements Spectrum's shared runtime contract.
- Slack → Core: adapts · Provider implements Spectrum's shared runtime contract.
- WhatsApp → Core: adapts · Provider implements Spectrum's shared runtime contract.
- Elysia → Core: hosts · Framework adapter embeds Spectrum webhook handling.
- Express → Core: hosts · Framework adapter embeds Spectrum webhook handling.
- Fastify → Core: hosts · Framework adapter embeds Spectrum webhook handling.
- Hono → Core: hosts · Framework adapter embeds Spectrum webhook handling.
- Terminal → Core: interfaces · Terminal surface connects into the shared runtime boundary.
- Docs → Core: documents · Docs explain the shared runtime model and capabilities.
- Basic example → Core: consumes · Example demonstrates the minimal consumer loop.
- Tooling → Spectrum TS: builds · Tooling packages, publishes, and verifies the SDK ecosystem.
- Tooling → Docs: publishes · Tooling supports docs generation and deployment.