|
| 1 | +# How it works (Developer view) |
| 2 | + |
| 3 | +This document explains the architecture, data model, and runtime behavior of the v2 widget stack from a developer POV. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 1) Architecture overview |
| 8 | + |
| 9 | +**Pipeline**: Notion → Google Sheets → Apps Script → Google Calendar → Scriptable |
| 10 | + |
| 11 | +**Why this stack** |
| 12 | + |
| 13 | +- **Notion**: user-friendly source of truth (editable by non-devs). |
| 14 | +- **Sheets**: stable integration layer and audit-friendly table. |
| 15 | +- **Apps Script**: serverless automation + calendar integration. |
| 16 | +- **Google Calendar**: native reminders and timezone handling. |
| 17 | +- **Scriptable**: fast, local UI for iOS widgets. |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## 2) Data model (Sheet schema) |
| 22 | + |
| 23 | +Core columns (used by sync and widget): |
| 24 | + |
| 25 | +- Event Name |
| 26 | +- Event Date |
| 27 | +- Event Type |
| 28 | +- Owner Timezone |
| 29 | +- All Day? |
| 30 | +- Exact Local Time |
| 31 | +- Relative Reminders |
| 32 | +- Notes |
| 33 | +- Active? |
| 34 | +- Widget Emoji |
| 35 | +- Widget Clr |
| 36 | + |
| 37 | +**Notes** |
| 38 | + |
| 39 | +- `Event Date` can be a Date cell or a text date (e.g., `Jul 2, 1986`). |
| 40 | +- `Relative Reminders` uses days (e.g., `7,1,0.125`). |
| 41 | +- `Exact Local Time` is optional and can be derived. |
| 42 | +- `Widget Emoji` auto-fills from Event Type if empty. |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +## 3) Sync engine (Apps Script) |
| 47 | + |
| 48 | +**Main scripts** |
| 49 | + |
| 50 | +- `event_sync.gs`: end-to-end sync (events + reminders + deletions) |
| 51 | +- `build_events_only.gs`: only main calendar events |
| 52 | +- `build_reminders_only.gs`: only reminder series |
| 53 | +- `cleanup_events.gs`: wipe all events in the calendar (use carefully) |
| 54 | + |
| 55 | +**Key behaviors** |
| 56 | + |
| 57 | +- **Create/update**: uses ID if present, else searches by title/day. |
| 58 | +- **Deletion**: compares current sheet IDs against previously known IDs to remove deleted events. |
| 59 | +- **Debounce + lock**: avoids duplicate syncs from multiple triggers. |
| 60 | +- **Auto emoji**: fills `Widget Emoji` based on `Event Type`. |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## 4) Timezone & reminders logic |
| 65 | + |
| 66 | +**Offset check** |
| 67 | + |
| 68 | +- If owner timezone has the **same UTC offset** as the user on that date: |
| 69 | + - No separate reminder series is created. |
| 70 | + - Relative reminders are applied directly to the main event. |
| 71 | + |
| 72 | +**Different offset** |
| 73 | + |
| 74 | +- A dedicated reminder series is created at the owner’s midnight mapped to local time. |
| 75 | +- Relative reminders are attached to the reminder series, not the main event. |
| 76 | + |
| 77 | +**Exact Local Time derivation** |
| 78 | + |
| 79 | +- If `Exact Local Time` is blank and relative reminders exist: |
| 80 | + - It derives a local time from the smallest reminder offset. |
| 81 | + - Writes the derived time back to the sheet. |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## 5) Widget data feed |
| 86 | + |
| 87 | +The web app (Code.gs) returns a minimal JSON payload: |
| 88 | + |
| 89 | +```json |
| 90 | +[ |
| 91 | + {"name":"Asha","date":"1986-07-02","icon":"🎂","color":"#7b9a50"} |
| 92 | +] |
| 93 | +``` |
| 94 | + |
| 95 | +The widget expects: |
| 96 | + |
| 97 | +- `name` |
| 98 | +- `date` (YYYY-MM-DD or a parseable date string) |
| 99 | +- `icon` |
| 100 | +- `color` (optional) |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +## 6) Widget rendering |
| 105 | + |
| 106 | +- Sorts events by next upcoming date in the current year. |
| 107 | +- Shows 1 / 3 / 6 items based on size. |
| 108 | +- Small widget supports optional “age mode.” |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 112 | +## 7) Notifications |
| 113 | + |
| 114 | +- Google Calendar handles precise alerts. |
| 115 | +- Notion Calendar can also alert if you want a second channel. |
| 116 | + |
| 117 | +To avoid duplicates, disable alerts in one of the calendars. |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## 8) Extensibility |
| 122 | + |
| 123 | +- Add new event types: update emoji mapping in Apps Script. |
| 124 | +- Change colors: update `Widget Clr` in Sheets. |
| 125 | +- Swap UI layout: modify Scriptable stacks. |
| 126 | +- Add fields: update Code.gs + widget parser. |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## 9) Known tradeoffs |
| 131 | + |
| 132 | +- Apps Script has rate limits; batch updates accordingly. |
| 133 | +- Date-only events can shift if you don’t parse them as local dates. |
| 134 | +- Duplicates can happen if triggers overlap (mitigated by lock/debounce). |
0 commit comments