# zhuiyueya/dsh-im-gateway architecture

> Architecture diagram of the GitHub repository zhuiyueya/dsh-im-gateway, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zhuiyueya/dsh-im-gateway
- Repository: https://github.com/zhuiyueya/dsh-im-gateway

## Overview

dsh-im-gateway is a DeepSeek Harness plugin that connects chat platforms to coding-agent sessions. A user message enters through a channel adapter, is authorized and routed by the gateway into an agent session, and agent replies return through the gateway to the originating chat. The product also provides channel setup and lifecycle management, session commands, remote approvals, interactive questions, media handling, and chat-bound scheduled reminders. Core flow links follow the documented architecture; unsampled subsystem links are included only where the README or excerpts support them.

Main entry points: [`src/core/gateway.ts`](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/gateway.ts) (IM gateway), [`src/manager.ts`](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/manager.ts) (Channel manager), [`src/channels`](https://github.com/zhuiyueya/dsh-im-gateway/tree/main/src/channels) (Channel adapters), [`src/core/router.ts`](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/router.ts) (Session router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_channels["Chat channels"]
  node_channel_adapters["Channel adapters"]
  node_channel_registry["Channel registry<br/>[index.ts]"]
end

subgraph group_gateway["Gateway runtime"]
  node_gateway_core["IM gateway<br/>[gateway.ts]"]
  node_message_merge["Message merge<br/>[merge.ts]"]
  node_message_format["Message formatting<br/>[format.ts]"]
  node_message_split["Reply splitting<br/>[split.ts]"]
  node_access_control["Access control<br/>[approval.ts]"]
end

subgraph group_sessions["Session handling"]
  node_session_router["Session router<br/>[router.ts]"]
  node_workspace_state[("Workspace preferences<br/>[index.ts]")]
end

subgraph group_interactions["Agent interactions"]
  node_approval_bridge["Approval bridge<br/>[approval.ts]"]
  node_question_bridge["Question bridge<br/>[questions.ts]"]
  node_cron_registry["Chat reminders<br/>[cron.ts]"]
  node_cron_time["Schedule calculation<br/>[cron-time.ts]"]
end

subgraph group_management["Channel management"]
  node_plugin_entry["Plugin entry<br/>[index.ts]"]
  node_channel_manager["Channel manager<br/>[manager.ts]"]
  node_provisioning["Channel provisioning<br/>[provisioning.ts]"]
  node_channel_state[("Channel state<br/>[manager.ts]")]
end

node_user(("Chat user"))
node_platforms(("Chat platforms"))
node_dsh_agent(("DSH agent"))

node_user -->|"sends message"| node_platforms
node_platforms -->|"delivers message"| node_channel_adapters
node_channel_adapters -->|"normalizes input"| node_gateway_core
node_gateway_core -->|"checks access"| node_access_control
node_gateway_core -->|"merges input"| node_message_merge
node_gateway_core -->|"routes message"| node_session_router
node_session_router -->|"follows up"| node_dsh_agent
node_dsh_agent -->|"emits events"| node_gateway_core
node_gateway_core -->|"splits reply"| node_message_split
node_gateway_core -->|"sends reply"| node_channel_adapters
node_channel_adapters -->|"delivers reply"| node_platforms
node_plugin_entry -->|"starts management"| node_channel_manager
node_channel_manager -->|"creates adapters"| node_channel_registry
node_channel_registry -->|"dispatches factory"| node_channel_adapters
node_channel_manager -->|"registers channels"| node_gateway_core
node_channel_manager -->|"persists config"| node_channel_state
node_channel_manager -->|"handles setup"| node_provisioning
node_gateway_core -->|"formats messages"| node_message_format
node_gateway_core -->|"bridges decisions"| node_approval_bridge
node_gateway_core -->|"bridges questions"| node_question_bridge
node_gateway_core -->|"manages reminders"| node_cron_registry
node_cron_registry -->|"calculates schedule"| node_cron_time
node_plugin_entry -->|"persists preferences"| node_workspace_state
node_session_router -.->|"loads preferences"| node_workspace_state

click node_channel_adapters "https://github.com/zhuiyueya/dsh-im-gateway/tree/main/src/channels"
click node_channel_registry "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/channels/index.ts"
click node_plugin_entry "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/index.ts"
click node_channel_manager "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/manager.ts"
click node_gateway_core "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/gateway.ts"
click node_message_merge "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/merge.ts"
click node_message_format "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/format.ts"
click node_message_split "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/split.ts"
click node_access_control "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/approval.ts"
click node_session_router "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/router.ts"
click node_approval_bridge "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/approval.ts"
click node_question_bridge "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/questions.ts"
click node_cron_registry "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/cron.ts"
click node_cron_time "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/cron-time.ts"
click node_provisioning "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/provisioning.ts"
click node_channel_state "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/manager.ts"
click node_workspace_state "https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/index.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_channel_adapters,node_channel_registry,node_user toneBlue
class node_gateway_core,node_message_merge,node_message_format,node_message_split,node_access_control toneAmber
class node_session_router,node_workspace_state toneMint
class node_approval_bridge,node_question_bridge,node_cron_registry,node_cron_time toneRose
class node_plugin_entry,node_channel_manager,node_provisioning,node_channel_state,node_platforms,node_dsh_agent toneIndigo
```

## Components

### Chat channels

- [Channel adapters](https://github.com/zhuiyueya/dsh-im-gateway/tree/main/src/channels): `src/channels`
- [Channel registry](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/channels/index.ts): `src/channels/index.ts`

### Gateway runtime

- [IM gateway](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/gateway.ts): `src/core/gateway.ts`
- [Message merge](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/merge.ts): `src/core/merge.ts`
- [Message formatting](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/format.ts): `src/core/format.ts`
- [Reply splitting](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/split.ts): `src/core/split.ts`
- [Access control](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/approval.ts): `src/core/approval.ts`

### Session handling

- [Session router](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/router.ts): `src/core/router.ts`
- [Workspace preferences](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/index.ts): `src/index.ts`

### Agent interactions

- [Approval bridge](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/approval.ts): `src/core/approval.ts`
- [Question bridge](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/questions.ts): `src/core/questions.ts`
- [Chat reminders](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/cron.ts): `src/core/cron.ts`
- [Schedule calculation](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/cron-time.ts): `src/core/cron-time.ts`

### Channel management

- [Plugin entry](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/index.ts): `src/index.ts`
- [Channel manager](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/manager.ts): `src/manager.ts`
- [Channel provisioning](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/core/provisioning.ts): `src/core/provisioning.ts`
- [Channel state](https://github.com/zhuiyueya/dsh-im-gateway/blob/main/src/manager.ts): `src/manager.ts`

### Other components

- **Chat user**
- **Chat platforms**
- **DSH agent**

## Connections

- Chat user → Chat platforms: sends message
- Chat platforms → Channel adapters: delivers message
- Channel adapters → IM gateway: normalizes input
- IM gateway → Access control: checks access (evidence: `src/core/gateway.ts`)
- IM gateway → Message merge: merges input (evidence: `src/core/gateway.ts`)
- IM gateway → Session router: routes message (evidence: `src/core/gateway.ts`)
- Session router → DSH agent: follows up
- DSH agent → IM gateway: emits events
- IM gateway → Reply splitting: splits reply (evidence: `src/core/gateway.ts`)
- IM gateway → Channel adapters: sends reply
- Channel adapters → Chat platforms: delivers reply
- Plugin entry → Channel manager: starts management (evidence: `src/index.ts`)
- Channel manager → Channel registry: creates adapters (evidence: `src/channels/index.ts`)
- Channel registry → Channel adapters: dispatches factory (evidence: `src/channels/index.ts`)
- Channel manager → IM gateway: registers channels (evidence: `src/manager.ts`)
- Channel manager → Channel state: persists config (evidence: `src/manager.ts`)
- Channel manager → Channel provisioning: handles setup (evidence: `src/core/provisioning.ts`)
- IM gateway → Message formatting: formats messages (evidence: `src/core/gateway.ts`)
- IM gateway → Approval bridge: bridges decisions (evidence: `src/core/gateway.ts`)
- IM gateway → Question bridge: bridges questions (evidence: `src/core/gateway.ts`)
- IM gateway → Chat reminders: manages reminders (evidence: `src/core/gateway.ts`)
- Chat reminders → Schedule calculation: calculates schedule (evidence: `src/core/cron.ts`)
- Plugin entry → Workspace preferences: persists preferences (evidence: `src/index.ts`)
- Session router → Workspace preferences: loads preferences
