# posterberg/smshandler architecture

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

- Interactive diagram: https://gitdiagram.com/posterberg/smshandler
- Repository: https://github.com/posterberg/smshandler

## Overview

smshandler is a small MQTT-to-SMS bridge: MQTT messages select a phonebook recipient, a broadcast, or a numeric destination, and the modem sends the SMS. In the reverse direction, the modem callback formats received messages and publishes them to MQTT, optionally replying to the sender. The source shows configuration loading and callback wiring; no separate broker or modem implementation is included. Evidence is limited to the README and the sampled main script.

Main entry points: [`smshandler.py`](https://github.com/posterberg/smshandler/blob/master/smshandler.py) (Runtime setup), [`config.ini`](https://github.com/posterberg/smshandler/blob/master/config.ini) (Runtime config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Runtime setup"]
  node_config["Runtime config<br/>[config.ini]"]
  node_main["Runtime setup<br/>[smshandler.py]"]
  node_mqtt_callbacks["MQTT callbacks<br/>[smshandler.py]"]
end

subgraph group_outbound["Outbound SMS"]
  node_recipient_dispatch["Recipient dispatch<br/>[smshandler.py]"]
  node_send_sms["Send SMS<br/>[smshandler.py]"]
  node_gsm_modem{{"GSM modem"}}
end

subgraph group_inbound["Inbound SMS"]
  node_receive_sms["Receive SMS<br/>[smshandler.py]"]
end

node_user(("Automation user"))
node_mqtt{{"MQTT broker"}}

node_user -->|"sends topic message"| node_mqtt
node_mqtt -.->|"delivers messages"| node_mqtt_callbacks
node_main -->|"reads settings"| node_config
node_main -->|"registers callbacks"| node_mqtt_callbacks
node_main -->|"connects modem"| node_gsm_modem
node_main -->|"registers receive callback"| node_receive_sms
node_mqtt_callbacks -->|"subscribes to topics"| node_mqtt
node_mqtt_callbacks -->|"routes message"| node_recipient_dispatch
node_recipient_dispatch -->|"selects recipient"| node_send_sms
node_send_sms -->|"sends SMS"| node_gsm_modem
node_gsm_modem -->|"delivers received SMS"| node_receive_sms
node_receive_sms -->|"publishes received SMS"| node_mqtt
node_receive_sms -->|"replies if enabled"| node_gsm_modem

click node_config "https://github.com/posterberg/smshandler/blob/master/config.ini"
click node_main "https://github.com/posterberg/smshandler/blob/master/smshandler.py"
click node_mqtt_callbacks "https://github.com/posterberg/smshandler/blob/master/smshandler.py"
click node_recipient_dispatch "https://github.com/posterberg/smshandler/blob/master/smshandler.py"
click node_send_sms "https://github.com/posterberg/smshandler/blob/master/smshandler.py"
click node_receive_sms "https://github.com/posterberg/smshandler/blob/master/smshandler.py"

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_config,node_main,node_mqtt_callbacks,node_user toneBlue
class node_recipient_dispatch,node_send_sms,node_gsm_modem toneAmber
class node_receive_sms toneMint
class node_mqtt toneIndigo
```

## Components

### Runtime setup

- [Runtime config](https://github.com/posterberg/smshandler/blob/master/config.ini): `config.ini`
- [Runtime setup](https://github.com/posterberg/smshandler/blob/master/smshandler.py): `smshandler.py`
- [MQTT callbacks](https://github.com/posterberg/smshandler/blob/master/smshandler.py): `smshandler.py`

### Outbound SMS

- [Recipient dispatch](https://github.com/posterberg/smshandler/blob/master/smshandler.py): `smshandler.py`
- [Send SMS](https://github.com/posterberg/smshandler/blob/master/smshandler.py): `smshandler.py`
- **GSM modem**

### Inbound SMS

- [Receive SMS](https://github.com/posterberg/smshandler/blob/master/smshandler.py): `smshandler.py`

### Other components

- **Automation user**
- **MQTT broker**

## Connections

- Automation user → MQTT broker: sends topic message (evidence: `README.md`)
- MQTT broker → MQTT callbacks: delivers messages
- Runtime setup → Runtime config: reads settings (evidence: `smshandler.py`)
- Runtime setup → MQTT callbacks: registers callbacks (evidence: `smshandler.py`)
- Runtime setup → GSM modem: connects modem (evidence: `smshandler.py`)
- Runtime setup → Receive SMS: registers receive callback (evidence: `smshandler.py`)
- MQTT callbacks → MQTT broker: subscribes to topics (evidence: `smshandler.py`)
- MQTT callbacks → Recipient dispatch: routes message (evidence: `smshandler.py`)
- Recipient dispatch → Send SMS: selects recipient (evidence: `smshandler.py`)
- Send SMS → GSM modem: sends SMS (evidence: `smshandler.py`)
- GSM modem → Receive SMS: delivers received SMS (evidence: `smshandler.py`)
- Receive SMS → MQTT broker: publishes received SMS (evidence: `smshandler.py`)
- Receive SMS → GSM modem: replies if enabled (evidence: `smshandler.py`)
