# 42wim/matterbridge architecture

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

- Interactive diagram: https://gitdiagram.com/42wim/matterbridge
- Repository: https://github.com/42wim/matterbridge

## Overview

Matterbridge is a configurable chat-protocol bridge: operators configure accounts and channels, then messages and supported events pass from one platform adapter through gateway routing to other configured adapters. The repository also documents file handling, edits/deletes, threading, spoofing, private groups, multiple gateways, and an API for third-party integrations. The sampled handlers show adapters submitting normalized messages to the gateway; gateway routing is present in the tree, but its full dispatch logic was not sampled, so adapter-to-gateway routing links are documented at a high level.

Main entry points: [`gateway/gateway.go`](https://github.com/42wim/matterbridge/blob/master/gateway/gateway.go) (Gateway router), [`matterbridge.go`](https://github.com/42wim/matterbridge/blob/master/matterbridge.go) (Application entry), [`gateway/handlers.go`](https://github.com/42wim/matterbridge/blob/master/gateway/handlers.go) (Gateway handlers), [`bridge/discord/handlers.go`](https://github.com/42wim/matterbridge/blob/master/bridge/discord/handlers.go) (Discord adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Application setup"]
  node_entry["Application entry<br/>[matterbridge.go]"]
  node_settings["Configuration<br/>[config.go]"]
end

subgraph group_routing["Message routing"]
  node_gateway["Gateway router<br/>[gateway.go]"]
  node_handlers["Gateway handlers<br/>[handlers.go]"]
  node_samechannel["Channel matching<br/>[samechannel.go]"]
  node_media[("Media storage<br/>[handlers.go]")]
end

subgraph group_adapters["Protocol adapters"]
  node_discord["Discord adapter<br/>[handlers.go]"]
  node_irc["IRC adapter<br/>[handlers.go]"]
  node_matrix["Matrix adapter<br/>[matrix.go]"]
  node_mattermost["Mattermost adapter<br/>[handlers.go]"]
  node_teams["Teams adapter<br/>[handler.go]"]
  node_mumble["Mumble adapter<br/>[handlers.go]"]
  node_slack["Slack adapter<br/>[handlers.go]"]
  node_telegram["Telegram adapter<br/>[handlers.go]"]
  node_whatsapp["WhatsApp adapter<br/>[handlers.go]"]
  node_whatsappmulti["WhatsApp multi<br/>[handlers.go]"]
  node_xmpp["XMPP adapter<br/>[handler.go]"]
end

subgraph group_integration["API integrations"]
  node_api["Bridge API<br/>[api.go]"]
end

node_operator(("Operator"))
node_thirdparty(("Third-party clients"))

node_operator -->|"starts"| node_entry
node_entry -->|"loads"| node_settings
node_entry -->|"creates"| node_gateway
node_gateway -.->|"delegates"| node_handlers
node_gateway -->|"routes via"| node_samechannel
node_handlers -->|"uploads files"| node_media
node_discord -.->|"submits messages"| node_gateway
node_irc -.->|"submits messages"| node_gateway
node_matrix -.->|"submits messages"| node_gateway
node_mattermost -.->|"submits messages"| node_gateway
node_teams -.->|"submits messages"| node_gateway
node_mumble -.->|"submits messages"| node_gateway
node_slack -.->|"submits messages"| node_gateway
node_telegram -.->|"submits messages"| node_gateway
node_whatsapp -.->|"submits messages"| node_gateway
node_whatsappmulti -.->|"submits messages"| node_gateway
node_xmpp -.->|"submits messages"| node_gateway
node_gateway -.->|"dispatches messages"| node_discord
node_gateway -.->|"dispatches messages"| node_irc
node_gateway -.->|"dispatches messages"| node_matrix
node_gateway -.->|"dispatches messages"| node_mattermost
node_gateway -.->|"dispatches messages"| node_teams
node_gateway -.->|"dispatches messages"| node_mumble
node_gateway -.->|"dispatches messages"| node_slack
node_gateway -.->|"dispatches messages"| node_telegram
node_gateway -.->|"dispatches messages"| node_whatsapp
node_gateway -.->|"dispatches messages"| node_whatsappmulti
node_gateway -.->|"dispatches messages"| node_xmpp
node_thirdparty -->|"integrates via"| node_api
node_api -->|"uses bridge"| node_gateway

click node_entry "https://github.com/42wim/matterbridge/blob/master/matterbridge.go"
click node_settings "https://github.com/42wim/matterbridge/blob/master/bridge/config/config.go"
click node_gateway "https://github.com/42wim/matterbridge/blob/master/gateway/gateway.go"
click node_handlers "https://github.com/42wim/matterbridge/blob/master/gateway/handlers.go"
click node_samechannel "https://github.com/42wim/matterbridge/blob/master/gateway/samechannel/samechannel.go"
click node_discord "https://github.com/42wim/matterbridge/blob/master/bridge/discord/handlers.go"
click node_irc "https://github.com/42wim/matterbridge/blob/master/bridge/irc/handlers.go"
click node_matrix "https://github.com/42wim/matterbridge/blob/master/bridge/matrix/matrix.go"
click node_mattermost "https://github.com/42wim/matterbridge/blob/master/bridge/mattermost/handlers.go"
click node_teams "https://github.com/42wim/matterbridge/blob/master/bridge/msteams/handler.go"
click node_mumble "https://github.com/42wim/matterbridge/blob/master/bridge/mumble/handlers.go"
click node_slack "https://github.com/42wim/matterbridge/blob/master/bridge/slack/handlers.go"
click node_telegram "https://github.com/42wim/matterbridge/blob/master/bridge/telegram/handlers.go"
click node_whatsapp "https://github.com/42wim/matterbridge/blob/master/bridge/whatsapp/handlers.go"
click node_whatsappmulti "https://github.com/42wim/matterbridge/blob/master/bridge/whatsappmulti/handlers.go"
click node_xmpp "https://github.com/42wim/matterbridge/blob/master/bridge/xmpp/handler.go"
click node_api "https://github.com/42wim/matterbridge/blob/master/bridge/api/api.go"
click node_media "https://github.com/42wim/matterbridge/blob/master/gateway/handlers.go"

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_entry,node_settings,node_thirdparty toneBlue
class node_gateway,node_handlers,node_samechannel,node_media toneAmber
class node_discord,node_irc,node_matrix,node_mattermost,node_teams,node_mumble,node_slack,node_telegram,node_whatsapp,node_whatsappmulti,node_xmpp toneMint
class node_api toneRose
class node_operator toneIndigo
```

## Components

### Application setup

- [Application entry](https://github.com/42wim/matterbridge/blob/master/matterbridge.go): `matterbridge.go`
- [Configuration](https://github.com/42wim/matterbridge/blob/master/bridge/config/config.go): `bridge/config/config.go`

### Message routing

- [Gateway router](https://github.com/42wim/matterbridge/blob/master/gateway/gateway.go): `gateway/gateway.go`
- [Gateway handlers](https://github.com/42wim/matterbridge/blob/master/gateway/handlers.go): `gateway/handlers.go`
- [Channel matching](https://github.com/42wim/matterbridge/blob/master/gateway/samechannel/samechannel.go): `gateway/samechannel/samechannel.go`
- [Media storage](https://github.com/42wim/matterbridge/blob/master/gateway/handlers.go): `gateway/handlers.go`

### Protocol adapters

- [Discord adapter](https://github.com/42wim/matterbridge/blob/master/bridge/discord/handlers.go): `bridge/discord/handlers.go`
- [IRC adapter](https://github.com/42wim/matterbridge/blob/master/bridge/irc/handlers.go): `bridge/irc/handlers.go`
- [Matrix adapter](https://github.com/42wim/matterbridge/blob/master/bridge/matrix/matrix.go): `bridge/matrix/matrix.go`
- [Mattermost adapter](https://github.com/42wim/matterbridge/blob/master/bridge/mattermost/handlers.go): `bridge/mattermost/handlers.go`
- [Teams adapter](https://github.com/42wim/matterbridge/blob/master/bridge/msteams/handler.go): `bridge/msteams/handler.go`
- [Mumble adapter](https://github.com/42wim/matterbridge/blob/master/bridge/mumble/handlers.go): `bridge/mumble/handlers.go`
- [Slack adapter](https://github.com/42wim/matterbridge/blob/master/bridge/slack/handlers.go): `bridge/slack/handlers.go`
- [Telegram adapter](https://github.com/42wim/matterbridge/blob/master/bridge/telegram/handlers.go): `bridge/telegram/handlers.go`
- [WhatsApp adapter](https://github.com/42wim/matterbridge/blob/master/bridge/whatsapp/handlers.go): `bridge/whatsapp/handlers.go`
- [WhatsApp multi](https://github.com/42wim/matterbridge/blob/master/bridge/whatsappmulti/handlers.go): `bridge/whatsappmulti/handlers.go`
- [XMPP adapter](https://github.com/42wim/matterbridge/blob/master/bridge/xmpp/handler.go): `bridge/xmpp/handler.go`

### API integrations

- [Bridge API](https://github.com/42wim/matterbridge/blob/master/bridge/api/api.go): `bridge/api/api.go`

### Other components

- **Operator**
- **Third-party clients**

## Connections

- Operator → Application entry: starts (evidence: `README.md`)
- Application entry → Configuration: loads (evidence: `matterbridge.go`)
- Application entry → Gateway router: creates (evidence: `matterbridge.go`)
- Gateway router → Gateway handlers: delegates
- Gateway router → Channel matching: routes via
- Gateway handlers → Media storage: uploads files (evidence: `gateway/handlers.go`)
- Discord adapter → Gateway router: submits messages
- IRC adapter → Gateway router: submits messages
- Matrix adapter → Gateway router: submits messages
- Mattermost adapter → Gateway router: submits messages
- Teams adapter → Gateway router: submits messages
- Mumble adapter → Gateway router: submits messages
- Slack adapter → Gateway router: submits messages
- Telegram adapter → Gateway router: submits messages
- WhatsApp adapter → Gateway router: submits messages
- WhatsApp multi → Gateway router: submits messages
- XMPP adapter → Gateway router: submits messages
- Gateway router → Discord adapter: dispatches messages
- Gateway router → IRC adapter: dispatches messages
- Gateway router → Matrix adapter: dispatches messages
- Gateway router → Mattermost adapter: dispatches messages
- Gateway router → Teams adapter: dispatches messages
- Gateway router → Mumble adapter: dispatches messages
- Gateway router → Slack adapter: dispatches messages
- Gateway router → Telegram adapter: dispatches messages
- Gateway router → WhatsApp adapter: dispatches messages
- Gateway router → WhatsApp multi: dispatches messages
- Gateway router → XMPP adapter: dispatches messages
- Third-party clients → Bridge API: integrates via (evidence: `README.md`)
- Bridge API → Gateway router: uses bridge (evidence: `bridge/api/api.go`)
