A small, battery-powered ESP32-C3 electronic keychain that behaves like a reactive digital companion — not just an OLED gadget, but a "buddy" with mood, energy and awareness of its environment. An Android phone connects over Bluetooth LE for a richer UI and internet access; a self-hosted Go backend provides authentication, durable state, event history and OTA firmware distribution.
Core principle: the keychain is useful without the phone or the internet. Every basic buddy behaviour — blinking, mood changes, reactions to movement, button responses — runs entirely on-device. The phone and backend are augmentation layers, not requirements. (
docs/00,docs/16)
Three implementation folders, one documentation folder. Each implementation folder is an independently buildable, independently testable build unit with its own README, build configuration, test suite and scripts.
keychain/
├── docs/ Canonical design specs (source of truth — 29 documents)
├── firmware/ ESP32-C3 firmware · ESP-IDF v6.1 · C · NimBLE · FreeRTOS
├── application/ Android companion app · Kotlin · Jetpack Compose · Hilt
├── backend/ REST API · Go · Gin · PostgreSQL 17 · Tailscale
│
├── README.md ← this file
├── Makefile Convenience targets across all three folders
└── .gitignore Root ignores (secrets, OS/tool noise)
| Folder | Tech | Owns | Canonical docs |
|---|---|---|---|
firmware/ |
ESP-IDF v6.1, C, NimBLE | Buddy behaviour, animation, sensors, power, GATT server, OTA receiver | 07, 08, 09, 10 |
application/ |
Kotlin, Compose, Hilt, Room | BLE client, offline store, sync engine, UI, auth | 11, 14, 16, 19 |
backend/ |
Go, Gin, PostgreSQL 17 | Accounts, device registry, state, events, command queue, firmware | 12, 13, 15, 17 |
┌─────────────┐ BLE ┌─────────────┐ HTTPS/Tailscale ┌─────────────┐
│ firmware/ │ ◄────────────► │application/ │ ◄────────────────────► │ backend/ │
│ ESP32-C3 │ GATT │ Android │ REST API │ Go + PG 17 │
└─────────────┘ └─────────────┘ └─────────────┘
OLED, IMU, Room DB, PostgreSQL,
buttons, haptics, BLE Manager, JWT RS256,
battery, deep sleep Sync Engine MinIO (OTA)
State ownership (docs/28):
| State | Authoritative source | Sync path |
|---|---|---|
| Mood, energy, attention, battery | Device | Device → Phone → Backend |
| Device settings (name, brightness…) | Phone | Phone → Device, Phone → Backend |
| User account | Backend | Backend only |
| Event history | Device → Phone → Backend | Append-only, dedup by ID |
| Firmware version | Backend | Backend → Phone → Device (OTA) |
The three folders never share source code. They share specifications, all of
which live in docs/ and are consumed as read-only contracts:
| Contract | Between | Spec |
|---|---|---|
| BLE GATT protocol — services, characteristics, JSON command/event envelopes, OTA chunking | firmware/ ↔ application/ |
docs/10-ble-protocol.md |
| REST API — endpoints, request/response shapes, error envelope | application/ ↔ backend/ |
docs/17-api-specification.md |
| Sync semantics — revision conflict resolution, event dedup, idempotency | application/ ↔ backend/ |
docs/14-synchronization.md |
| OTA delivery — backend stores binary, phone relays to device | backend/ → firmware/ (via application/) |
docs/25-deployment.md |
| Database schema | backend/ only |
docs/13-database-schema.md |
If a contract changes, it changes in docs/ first, then in each consuming folder.
| Folder | Toolchain |
|---|---|
firmware/ |
ESP-IDF v6.1 ($IDF_PATH/export.sh) |
application/ |
Android Studio (JDK 17–21), Android SDK 34 |
backend/ |
Go 1.22+, Docker + Docker Compose |
make build-all # firmware + application + backend
make test-all # build/run every available suite# Firmware
cd firmware && ./scripts/build.sh # idf.py build
cd firmware && ./scripts/flash.sh # idf.py flash (monitor: scripts/monitor.sh)
# Android
cd application && ./gradlew :app:assembleDebug
cd application && ./gradlew :app:testDebugUnitTest
# Backend (dev stack: postgres + minio + api)
cd backend && make docker-up
cd backend && make migrate-up
cd backend && make run
cd backend && make testFull per-folder instructions — including architecture diagrams, module indexes and
testing strategy — are in each folder's README.md:
All 29 design documents live in docs/. Start here:
| Doc | Title |
|---|---|
00 |
Executive Summary |
01 |
Requirements |
03 |
Architecture |
04 |
Technology Decisions |
10 |
BLE Protocol Specification |
13 |
Database Schema |
17 |
API Specification |
22 |
Development Phases |
28 |
Final Recommended Architecture |
Scaffolded from the design docs. Structure, build configuration, data models, database
migrations and module interfaces are real; feature bodies are marked with
TODO(phase N) and tracked by docs/22-development-phases.md
(Phases 0–14 (19 weeks), Phase 15+ beyond, single developer).