|
| 1 | +# ADR 005: Embedded MQTT Broker Decision |
| 2 | + |
| 3 | +**Status:** Rejected |
| 4 | +**Date:** 2025-11-16 |
| 5 | +**Deciders:** Development Team |
| 6 | +**Related:** [MQTT Commands Research](../research/mqtt-commands-implementation.md) |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## Context |
| 11 | + |
| 12 | +With MQTT commands implementation planned, we evaluated whether to bundle an embedded MQTT broker (Aedes) in the Electron app to simplify user setup. |
| 13 | + |
| 14 | +### Problem |
| 15 | + |
| 16 | +Users need an MQTT broker to: |
| 17 | +1. Receive status updates from Teams |
| 18 | +2. Send action commands to Teams |
| 19 | + |
| 20 | +Without a broker, users must: |
| 21 | +- Install mosquitto: `sudo apt-get install mosquitto` |
| 22 | +- Configure and start the service |
| 23 | +- Understand MQTT concepts |
| 24 | + |
| 25 | +### Proposed Solution |
| 26 | + |
| 27 | +Bundle Aedes (JavaScript MQTT broker) in the Electron app: |
| 28 | +- Auto-starts when app launches |
| 29 | +- Listens on `localhost:1883` |
| 30 | +- Zero configuration needed |
| 31 | +- Bundle size: +230 KB |
| 32 | +- Implementation effort: 6-8 hours |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## Decision |
| 37 | + |
| 38 | +**Do NOT bundle an embedded MQTT broker.** |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## Rationale |
| 43 | + |
| 44 | +### 1. Doesn't Solve the Real Problem |
| 45 | + |
| 46 | +**Users still need MQTT client tools** to send commands: |
| 47 | + |
| 48 | +```bash |
| 49 | +# Even with embedded broker, users must install: |
| 50 | +sudo apt-get install mosquitto-clients |
| 51 | + |
| 52 | +# To run: |
| 53 | +mosquitto_pub -h localhost -t teams/command -m '{"action":"toggle-mute"}' |
| 54 | +``` |
| 55 | + |
| 56 | +**Embedded broker eliminates:** |
| 57 | +- Installing mosquitto broker |
| 58 | + |
| 59 | +**Embedded broker does NOT eliminate:** |
| 60 | +- Installing mosquitto-clients (for `mosquitto_pub`) |
| 61 | +- Creating wrapper scripts |
| 62 | +- Understanding MQTT topics |
| 63 | + |
| 64 | +**Conclusion:** Marginal benefit (removes 1 of 3 installation steps) |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +### 2. Wrong Architectural Pattern |
| 69 | + |
| 70 | +**Teams should be a client, not a broker.** |
| 71 | + |
| 72 | +``` |
| 73 | +❌ Wrong: Each Teams instance runs its own broker |
| 74 | + Teams Instance 1 → Aedes broker :1883 |
| 75 | + Teams Instance 2 → Aedes broker :1884 (port conflict!) |
| 76 | + Home Assistant → Mosquitto :1883 |
| 77 | + → Fragmented ecosystem |
| 78 | +
|
| 79 | +✅ Right: Centralized broker, multiple clients |
| 80 | + Mosquitto :1883 (or Home Assistant MQTT add-on) |
| 81 | + ├─ Teams for Linux (client) |
| 82 | + ├─ Home Assistant (client) |
| 83 | + ├─ Node-RED (client) |
| 84 | + └─ IoT devices (clients) |
| 85 | + → Unified ecosystem |
| 86 | +``` |
| 87 | + |
| 88 | +Users with home automation already have MQTT brokers. Creating another broker fragments their setup. |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +### 3. Better Alternatives Exist |
| 93 | + |
| 94 | +**For users wanting keyboard shortcuts with zero dependencies:** |
| 95 | + |
| 96 | +**Option A: HTTP Server** |
| 97 | +```bash |
| 98 | +# curl is pre-installed on all Linux systems |
| 99 | +curl -X POST http://localhost:48765/action/toggle-mute |
| 100 | +``` |
| 101 | +- ✅ No package installation |
| 102 | +- ✅ Simpler than MQTT |
| 103 | +- ✅ Can serve web UI |
| 104 | + |
| 105 | +**Option B: Named Pipe (FIFO)** |
| 106 | +```bash |
| 107 | +# echo is built-in |
| 108 | +echo '{"action":"toggle-mute"}' > ~/.config/teams-for-linux/commands.fifo |
| 109 | +``` |
| 110 | +- ✅ Zero external dependencies |
| 111 | +- ✅ Standard Unix IPC |
| 112 | + |
| 113 | +**For users with home automation:** |
| 114 | +- They already have MQTT brokers (Home Assistant, etc.) |
| 115 | +- Prefer connecting to existing broker |
| 116 | +- Embedded broker adds unnecessary complexity |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +### 4. Implementation Complexity Without Value |
| 121 | + |
| 122 | +| Component | Embedded Broker | External Broker | HTTP Server | |
| 123 | +|-----------|----------------|-----------------|-------------| |
| 124 | +| Bundle size | +230 KB | 0 KB | 0 KB | |
| 125 | +| Implementation | 6-8 hours | 0 hours | 3-4 hours | |
| 126 | +| User dependencies | mosquitto-clients | mosquitto + mosquitto-clients | None (curl) | |
| 127 | +| Port conflicts | Yes (need handling) | No | Rare | |
| 128 | +| Maintenance | Update Aedes | User manages | None | |
| 129 | + |
| 130 | +**Cost/benefit:** Not favorable |
| 131 | + |
| 132 | +--- |
| 133 | + |
| 134 | +## Consequences |
| 135 | + |
| 136 | +### Positive |
| 137 | +- ✅ Simpler architecture (Teams = client only) |
| 138 | +- ✅ No port conflict handling needed |
| 139 | +- ✅ No Aedes dependency to maintain |
| 140 | +- ✅ Users with existing MQTT get better integration |
| 141 | +- ✅ Saved 6-8 hours implementation effort |
| 142 | + |
| 143 | +### Negative |
| 144 | +- ⚠️ Users without MQTT must install mosquitto |
| 145 | +- ⚠️ Slightly higher barrier to entry for MQTT features |
| 146 | + |
| 147 | +### Mitigations |
| 148 | +- Document easy broker setup (apt-get one-liner for most distros) |
| 149 | +- Recommend Home Assistant MQTT add-on (one-click install) |
| 150 | +- Consider HTTP server for zero-dependency shortcuts (future) |
| 151 | + |
| 152 | +--- |
| 153 | + |
| 154 | +## Alternatives Considered |
| 155 | + |
| 156 | +### Alternative 1: HTTP Command Server (Future) |
| 157 | + |
| 158 | +**For users wanting shortcuts without MQTT:** |
| 159 | + |
| 160 | +```javascript |
| 161 | +// Serve HTTP endpoint |
| 162 | +http://localhost:48765/action/toggle-mute |
| 163 | + |
| 164 | +// User script (no dependencies) |
| 165 | +curl -X POST http://localhost:48765/action/toggle-mute |
| 166 | +``` |
| 167 | + |
| 168 | +**Advantages:** |
| 169 | +- ✅ curl is pre-installed |
| 170 | +- ✅ Simpler than MQTT for basic use |
| 171 | +- ✅ Can add web UI later |
| 172 | + |
| 173 | +**Status:** Consider for future implementation |
| 174 | + |
| 175 | +### Alternative 2: Keep MQTT, Document Broker Setup |
| 176 | + |
| 177 | +**For users with home automation:** |
| 178 | + |
| 179 | +Document connecting to existing brokers: |
| 180 | +- Home Assistant MQTT add-on |
| 181 | +- Existing mosquitto installation |
| 182 | +- Cloud MQTT providers (for advanced users) |
| 183 | + |
| 184 | +**Status:** Accepted (current plan) |
| 185 | + |
| 186 | +--- |
| 187 | + |
| 188 | +## User Segments |
| 189 | + |
| 190 | +### Segment 1: Home Automation Users (30%) |
| 191 | +- Already have MQTT broker |
| 192 | +- Want Teams integration with automations |
| 193 | +- **Solution:** Connect to existing broker (documented) |
| 194 | + |
| 195 | +### Segment 2: Keyboard Shortcut Users (50%) |
| 196 | +- Want simple system-wide shortcuts |
| 197 | +- Don't have MQTT infrastructure |
| 198 | +- **Solution:** Install mosquitto (documented) OR HTTP server (future) |
| 199 | + |
| 200 | +### Segment 3: Advanced Users (20%) |
| 201 | +- Can set up whatever they need |
| 202 | +- **Solution:** Any approach works |
| 203 | + |
| 204 | +--- |
| 205 | + |
| 206 | +## References |
| 207 | + |
| 208 | +- [MQTT Commands Implementation Research](../research/mqtt-commands-implementation.md) |
| 209 | +- [Aedes MQTT Broker](https://github.com/moscajs/aedes) |
| 210 | +- Related: HTTP command server (future consideration) |
| 211 | + |
| 212 | +--- |
| 213 | + |
| 214 | +## Review |
| 215 | + |
| 216 | +This decision should be reviewed if: |
| 217 | +1. A zero-dependency command mechanism becomes critical requirement |
| 218 | +2. MQTT adoption is very low due to broker installation complexity |
| 219 | +3. Implementation effort for embedded broker drops significantly (new library, etc.) |
| 220 | + |
| 221 | +For now: **Proceed with MQTT client only + document broker setup.** |
0 commit comments