# photon-hq/spectrum-ts architecture

> Architecture diagram of the GitHub repository photon-hq/spectrum-ts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/photon-hq/spectrum-ts
- Repository: https://github.com/photon-hq/spectrum-ts

## Overview

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: [`packages/core/src/index.ts`](https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/index.ts) (Core), [`packages/spectrum-ts/src/index.ts`](https://github.com/photon-hq/spectrum-ts/blob/main/packages/spectrum-ts/src/index.ts) (Spectrum TS), [`packages/imessage/src/index.ts`](https://github.com/photon-hq/spectrum-ts/blob/main/packages/imessage/src/index.ts) (iMessage), [`scripts/release/publish.ts`](https://github.com/photon-hq/spectrum-ts/blob/main/scripts/release/publish.ts) (Tooling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_core["Core runtime"]
  node_n_core["Core<br/>[index.ts]"]
  node_n_content["Content model<br/>message-primitives<br/>[types.ts]"]
  node_n_fusor["Fusor<br/>event-runtime<br/>[core.ts]"]
  node_n_platform["Platform API<br/>platform-definitions<br/>[define.ts]"]
  node_n_webhook["Webhooks<br/>verify-deserialize<br/>[deserialize.ts]"]
  node_n_utils["Core utils<br/>shared-helpers<br/>[stream.ts]"]
end

subgraph group_grp_providers["Provider adapters"]
  node_n_imessage["iMessage<br/>provider-adapter<br/>[index.ts]"]
  node_n_telegram["Telegram<br/>provider-adapter<br/>[index.ts]"]
  node_n_slack["Slack<br/>provider-adapter<br/>[index.ts]"]
  node_n_whatsapp["WhatsApp<br/>provider-adapter<br/>[index.ts]"]
end

subgraph group_grp_adapters["Framework adapters"]
  node_n_elysia["Elysia<br/>framework-adapter<br/>[index.ts]"]
  node_n_express["Express<br/>framework-adapter<br/>[index.ts]"]
  node_n_fastify["Fastify<br/>framework-adapter<br/>[index.ts]"]
  node_n_hono["Hono<br/>framework-adapter<br/>[index.ts]"]
end

subgraph group_grp_facade["SDK facade"]
  node_n_sdk["Spectrum TS<br/>sdk-facade<br/>[index.ts]"]
end

subgraph group_grp_terminal["Terminal interface"]
  node_n_terminal["Terminal<br/>[index.ts]"]
end

subgraph group_grp_docs_examples["Docs and examples"]
  node_n_docs["Docs<br/>documentation<br/>[README.md]"]
  node_n_example["Basic example<br/>usage-example<br/>[index.ts]"]
end

subgraph group_grp_tooling["Tooling"]
  node_n_tooling["Tooling<br/>build-release<br/>[publish.ts]"]
end

node_n_sdk -->|"re-exports"| node_n_core
node_n_sdk -->|"re-exports"| node_n_imessage
node_n_sdk -->|"re-exports"| node_n_telegram
node_n_sdk -->|"re-exports"| node_n_slack
node_n_sdk -->|"re-exports"| node_n_whatsapp
node_n_core -->|"defines"| node_n_content
node_n_core -->|"orchestrates"| node_n_fusor
node_n_core -->|"authors"| node_n_platform
node_n_core -->|"verifies"| node_n_webhook
node_n_core -->|"shares"| node_n_utils
node_n_imessage -->|"normalizes"| node_n_content
node_n_imessage -->|"adapts"| node_n_core
node_n_telegram -->|"adapts"| node_n_core
node_n_slack -->|"adapts"| node_n_core
node_n_whatsapp -->|"adapts"| node_n_core
node_n_elysia -->|"hosts"| node_n_core
node_n_express -->|"hosts"| node_n_core
node_n_fastify -->|"hosts"| node_n_core
node_n_hono -->|"hosts"| node_n_core
node_n_terminal -->|"interfaces"| node_n_core
node_n_docs -->|"documents"| node_n_core
node_n_example -->|"consumes"| node_n_core
node_n_tooling -->|"builds"| node_n_sdk
node_n_tooling -->|"publishes"| node_n_docs

click node_n_core "https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/index.ts"
click node_n_content "https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/content/types.ts"
click node_n_fusor "https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/fusor/core.ts"
click node_n_platform "https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/platform/define.ts"
click node_n_webhook "https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/webhook/deserialize.ts"
click node_n_utils "https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/utils/stream.ts"
click node_n_imessage "https://github.com/photon-hq/spectrum-ts/blob/main/packages/imessage/src/index.ts"
click node_n_telegram "https://github.com/photon-hq/spectrum-ts/blob/main/packages/telegram/src/index.ts"
click node_n_slack "https://github.com/photon-hq/spectrum-ts/blob/main/packages/slack/src/index.ts"
click node_n_whatsapp "https://github.com/photon-hq/spectrum-ts/blob/main/packages/whatsapp-business/src/index.ts"
click node_n_elysia "https://github.com/photon-hq/spectrum-ts/blob/main/packages/elysia/src/index.ts"
click node_n_express "https://github.com/photon-hq/spectrum-ts/blob/main/packages/express/src/index.ts"
click node_n_fastify "https://github.com/photon-hq/spectrum-ts/blob/main/packages/fastify/src/index.ts"
click node_n_hono "https://github.com/photon-hq/spectrum-ts/blob/main/packages/hono/src/index.ts"
click node_n_sdk "https://github.com/photon-hq/spectrum-ts/blob/main/packages/spectrum-ts/src/index.ts"
click node_n_terminal "https://github.com/photon-hq/spectrum-ts/blob/main/packages/terminal/src/index.ts"
click node_n_docs "https://github.com/photon-hq/spectrum-ts/blob/main/docs/README.md"
click node_n_example "https://github.com/photon-hq/spectrum-ts/blob/main/examples/basic/index.ts"
click node_n_tooling "https://github.com/photon-hq/spectrum-ts/blob/main/scripts/release/publish.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_core,node_n_content,node_n_fusor,node_n_platform,node_n_webhook,node_n_utils,node_n_tooling toneBlue
class node_n_imessage,node_n_telegram,node_n_slack,node_n_whatsapp toneAmber
class node_n_elysia,node_n_express,node_n_fastify,node_n_hono toneMint
class node_n_sdk toneRose
class node_n_terminal toneIndigo
class node_n_docs,node_n_example toneTeal
```

## Components

### Core runtime

Shared domain model, normalization, orchestration, and webhook handling.

- [Core](https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/index.ts): runtime-core · Platform-agnostic domain model and orchestration layer for Spectrum. · `packages/core/src/index.ts`
- [Content model](https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/content/types.ts): message-primitives · 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](https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/fusor/core.ts): event-runtime · Runtime glue for auth, event parsing, websocket/webhook handling, and provider orchestration. · `packages/core/src/fusor/core.ts`
- [Platform API](https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/platform/define.ts): platform-definitions · Authoring and build helpers for defining providers and platform capabilities. · `packages/core/src/platform/define.ts`
- [Webhooks](https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/webhook/deserialize.ts): verify-deserialize · Webhook event verification and deserialization into core events. · `packages/core/src/webhook/deserialize.ts`
- [Core utils](https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/utils/stream.ts): shared-helpers · 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](https://github.com/photon-hq/spectrum-ts/blob/main/packages/imessage/src/index.ts): provider-adapter · Most elaborate provider with local and remote modes, attachments, groups, streaming, and identity resolution. · `packages/imessage/src/index.ts`
- [Telegram](https://github.com/photon-hq/spectrum-ts/blob/main/packages/telegram/src/index.ts): provider-adapter · Provider integration for config, client, inbound/outbound messages, reactions, spaces, and webhooks. · `packages/telegram/src/index.ts`
- [Slack](https://github.com/photon-hq/spectrum-ts/blob/main/packages/slack/src/index.ts): provider-adapter · Compact Slack integration focused on auth and message handling. · `packages/slack/src/index.ts`
- [WhatsApp](https://github.com/photon-hq/spectrum-ts/blob/main/packages/whatsapp-business/src/index.ts): provider-adapter · 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](https://github.com/photon-hq/spectrum-ts/blob/main/packages/elysia/src/index.ts): framework-adapter · Thin Elysia integration for Spectrum webhook/event handling. · `packages/elysia/src/index.ts`
- [Express](https://github.com/photon-hq/spectrum-ts/blob/main/packages/express/src/index.ts): framework-adapter · Thin Express integration for Spectrum webhook/event handling. · `packages/express/src/index.ts`
- [Fastify](https://github.com/photon-hq/spectrum-ts/blob/main/packages/fastify/src/index.ts): framework-adapter · Thin Fastify integration for Spectrum webhook/event handling. · `packages/fastify/src/index.ts`
- [Hono](https://github.com/photon-hq/spectrum-ts/blob/main/packages/hono/src/index.ts): framework-adapter · 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](https://github.com/photon-hq/spectrum-ts/blob/main/packages/spectrum-ts/src/index.ts): sdk-facade · 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](https://github.com/photon-hq/spectrum-ts/blob/main/packages/terminal/src/index.ts): terminal-interface · 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](https://github.com/photon-hq/spectrum-ts/blob/main/docs/README.md): documentation · Product and capability documentation spanning core concepts and provider setup. · `docs/README.md`
- [Basic example](https://github.com/photon-hq/spectrum-ts/blob/main/examples/basic/index.ts): usage-example · Minimal runtime loop showing app creation, message consumption, and replies. · `examples/basic/index.ts`

### Tooling

Build, release, generation, and test-support infrastructure.

- [Tooling](https://github.com/photon-hq/spectrum-ts/blob/main/scripts/release/publish.ts): build-release · Workspace build, release, generation, and test-support automation. · `scripts/release/publish.ts`

## Connections

- 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.
