How denk0403/algedraw-calculator works
Project Type and Purpose
• This is a Fitbit OS application (“AlgeDraw Calculator”) that runs on the watch (app/) and leverages a companion phone app (companion/) for advanced AI-based digit recognition. There’s also a settings page (settings/) and UI definitions (resources/) for the watch.
Main Components
a. Watch App (app/)
• index.js: orchestrates UI, user input, calculation engine, local session stack.
• resources/: GUI definitions (.gui), styling (.css), widget layouts.
b. Companion App (companion/)
• index.js: receives raw drawing data via Fitbit messaging, runs the custom AI model to recognize handwritten digits, sends results back to the watch.
c. Settings Page (settings/)
• index.jsx: React-based settings interface on the companion side or Fitbit settings screen, used to configure constants, units (radians/degrees), etc.
d. External Dependencies & Services
• Fitbit OS Messaging API (watch ↔ phone over Bluetooth)
• Custom AI inference library (e.g., TensorFlow.js or a lightweight JS model on the companion)
• Fitbit SDK for UI, storage, device APIs
Component Interactions & Data Flow
1. User draws a digit on the watch UI canvas (resources/widgets.gui → app/index.js listens).
2. The watch app packages the stroke data and sends it to the companion via the Messaging API.
3. The companion receives strokes, runs the AI model on the phone, obtains a digit prediction.
4. The companion sends the recognized digit back to the watch.
5. The watch app’s calculation engine (app/index.js) integrates the new digit into the current expression or stack.
6. The UI updates to reflect the new input or computed result.
7. All inputs/results are stored in the app’s session stack (in-memory or simple key-value storage) until the session ends.
Architectural Patterns & Design Principles
• Separation of Concerns: UI (resources + app/index.js), logic & storage (app), AI inference (companion).
• Message-Driven RPC: the watch and companion communicate via asynchronous messages.
• MVC-like layering on the watch:
• View: GUI definitions in resources/
• Controller: app/index.js handles events & updates
• Model: in-memory stack + constants
• Settings as a distinct module: React/JSX-based page (settings/index.jsx) isolates configuration from runtime logic.