How 410527416370lh-boop/louiephone works
1. System shape
LouiePhone is split into two runtime domains: an ESP32-S3 firmware that drives the e-ink card device, and a Python backend that turns voice requests into app definitions and coordinates messaging. The core architectural boundary is the device-to-server link, with MQTT used for control/state distribution and Tailscale Funnel used for inbound voice capture.
2. Primary user flow
The main path is: button press on device → audio capture → PCM upload to server → speech-to-text → LLM app generation → JSON app definition → MQTT publish → device updates display/home screen. This is the central data flow the diagram should emphasize.
3. Firmware runtime
The firmware under firmware/ is an ESP-IDF 5.4+ / PlatformIO application. Its responsibilities are hardware-facing: capture input, record audio, manage WiFi/MQTT connectivity, render the UI, update the e-paper display, and handle power/battery behavior. It is the device execution boundary; no heavy AI logic lives here.
4. Firmware subsystems
The firmware is organized by concern:
- audio/ for microphone capture and PCM handling
- display/ for EPD drawing and refresh
- input/ for buttons/gesture input
- net/ for WiFi, MQTT, and a small server/client integration layer
- power/ for charging/battery/sleep behavior
- ui/ for app rendering and screen composition
- core/ for app state and memory management
- main.cpp as the application entry point and orchestration layer
5. Device state model
The device is stateful rather than stateless. core/app_state.* and ui/render.* imply a local app model that drives what appears on the e-paper screen. The MQTT backend likely supplies app definitions and updates, while the firmware keeps the current screen/app state and renders it to the display.
6. Network boundary on the device
Under firmware/src/net/, the device has three distinct network roles:
- WiFi connectivity
- MQTT client for sync/control
- server bridge for the voice/audio upload path
This separation matters for the diagram because one path is long-lived control/state over MQTT, while the other is episodic high-bandwidth audio upload to the backend.
7. Backend runtime
The backend under server/ is a Python 3.11+ service that listens for device voice requests and integrates external AI services. server.py is the main entry point. whatsapp_helper.py indicates a second integration path for forwarding messages from WhatsApp into the system.
8. Backend external dependencies
The backend depends on three outside services that materially shape the architecture:
- Deepgram for speech-to-text
- OpenRouter for LLM-generated app definitions
- MQTT broker for publishing device-facing state/results
Tailscale Funnel provides the public ingress for the device audio stream without exposing the backend directly.
9. Control/data plane split
There are effectively two planes:
- Control plane: MQTT-driven device state, home screen updates, todo sync, and generated app definitions
- Data plane: raw audio sent from device to server, transcribed and transformed into structured output
Keeping these separate helps explain why the device can remain lightweight while the backend performs AI and message handling.
10. Protocol and contracts
docs/DEVICE_PROTOCOL.md suggests an explicit message contract, likely centered on MQTT payload formats and app schema expectations. This is important for the diagram because MQTT is the integration contract between firmware and backend, not just a transport.
11. Persistence and secondary features
The README mentions a persistent todo list synced over MQTT and WhatsApp forwarding. These are not separate deployments; they are additional application flows layered on top of the same backend/device architecture and likely share the MQTT broker and app-state model.
12. Build and configuration boundaries
Secrets are intentionally split by runtime: firmware credentials live in firmware/src/config/device_config.h and backend credentials in server/.env. The repo also includes docs/ for architecture notes, protocol details, build/flash guidance, and battery notes; these are documentation/support artifacts rather than runtime components.
13. What to show in an architecture diagram
The diagram should show:
- the ESP32-S3 device with its internal modules
- the Python backend as the AI orchestration layer
- the MQTT broker as the shared state/control bus
- Tailscale Funnel as the ingress path for voice audio
- Deepgram, OpenRouter, and WhatsApp as external service dependencies
The main visual separation is device hardware vs. cloud/backend services, with MQTT and audio upload as the two cross-boundary flows.
Main entry points: main.cpp Main · server.py Server · render.cpp Render · app_state.cpp App state
Components 18
Firmware
ESP32-S3 device runtime and hardware-facing subsystems
- Main · Firmware entrypoint and device orchestration
firmware/src/main.cpp - App state · Local app and screen state
firmware/src/core/app_state.cpp - Memory · Firmware memory management
firmware/src/core/memory.cpp - Audio · Microphone capture and PCM handling
firmware/src/audio/audio.cpp - Input · Device input handling
firmware/src/input/input.cpp - WiFi · Wireless network connection
firmware/src/net/wifi.cpp - MQTT · Device control and state sync client
firmware/src/net/mqtt.cpp - Upload bridge · Device-side server integration for voice upload
firmware/src/net/server.cpp - Power · Charging, battery, and low-power behavior
firmware/src/power/power.cpp - Render · Screen composition and app rendering
firmware/src/ui/render.cpp - Display draw · Display drawing primitives and refresh orchestration
firmware/src/display/draw.cpp - EPD · E-paper panel driver
firmware/src/display/epd.cpp
Backend
Python service that handles voice, app generation, and messaging
External
Third-party services and shared infrastructure
- Deepgram · Speech transcription service
- OpenRouter · LLM generation for app definitions
- MQTT broker · Shared control/state broker
- Funnel · Inbound access path for voice upload
Connections 18
- Main → Input: reads input · Main loop consumes button events
- Main → Audio: captures audio · Initiates voice recording flow
- Main → WiFi: connects network · Brings up wireless connectivity
- Main → MQTT: syncs state · Publishes and receives device control messages
- Main → Power: manages power · Coordinates charging and sleep behavior
- Main → Render: updates ui · Drives local app rendering
- App state → Render: provides model · UI renders from current app state
- Render → Display draw: draws screen · Composes display output
- Display draw → EPD: refreshes panel · Pushes rendered frames to e-paper
- Audio → Upload bridge: uploads pcm · Sends captured voice data to backend ingress
- MQTT → MQTT broker: publishes/subscribes · Device state and control exchange
- Upload bridge → Funnel: ingress path · Uses public Funnel path for audio upload
- Server → Deepgram: transcribes · Converts raw audio to text
- Server → OpenRouter: generates app · Turns requests into structured app definitions
- Server → MQTT broker: publishes state · Sends device-facing updates and app payloads
- Server → WhatsApp: forwards messages · Secondary messaging integration path
- Server → Funnel: receives audio · Ingress for device voice requests
- Server → App state: app definition · Conceptual contract: backend output drives device state