Skip to content

Commit 3b6ca3a

Browse files
vscarpenterclaude
andcommitted
chore: remove stale Cloudflare/Supabase references after PocketBase migration
Remove dependencies, scripts, documentation, and code references left over from the Cloudflare Workers and Supabase sync systems that were replaced by PocketBase in #148. - Remove wrangler devDependency and hono override from package.json - Delete 8 stale files: Worker/sync/security docs, jwt.ts, scripts - Update MCP server CLI, config, and tool schemas to remove encryption refs - Rewrite architecture-diagrams.ts with PocketBase diagrams - Update 5 documentation files to reflect PocketBase architecture - Remove vectorClock from all test fixtures (schema v13 dropped it) All 1280 tests passing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent da300d2 commit 3b6ca3a

35 files changed

+492
-5335
lines changed

.github/copilot-instructions.md

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ This guide enables AI coding agents to work productively in the GSD Task Manager
77
### Core Stack
88
- **Next.js 16 App Router**: All routes in `app/`. Matrix view: `app/(matrix)/page.tsx`. Dashboard: `app/(dashboard)/dashboard/page.tsx`. PWA install: `app/(pwa)/install/page.tsx`.
99
- **Client-side only**: No server rendering. All components use `"use client"`.
10-
- **Data Layer**: IndexedDB via Dexie v4 (`lib/db.ts`, current schema v12). CRUD in `lib/tasks.ts`. Live queries via `useTasks()` hook (`lib/use-tasks.ts`).
10+
- **Data Layer**: IndexedDB via Dexie v4 (`lib/db.ts`, current schema v13). CRUD in `lib/tasks.ts`. Live queries via `useTasks()` hook (`lib/use-tasks.ts`).
1111
- **Quadrant System**: Tasks classified by `urgent`/`important` booleans → 4 quadrants. Logic in `lib/quadrants.ts`.
1212
- **Schema Validation**: Zod schemas in `lib/schema.ts` for all data types.
1313

14-
### Database Schema (v12)
14+
### Database Schema (v13)
1515
- **Tables**: `tasks`, `archivedTasks`, `smartViews`, `notificationSettings`, `syncQueue`, `syncMetadata`, `deviceInfo`, `archiveSettings`, `syncHistory`, `appPreferences`
16-
- **Task Fields**: Core (id, title, description, urgent, important, quadrant, completed, completedAt, dueDate, createdAt, updatedAt) + Advanced (recurrence, tags, subtasks, dependencies, notifyBefore, snoozedUntil, vectorClock, estimatedMinutes, timeSpent, timeEntries)
16+
- **Task Fields**: Core (id, title, description, urgent, important, quadrant, completed, completedAt, dueDate, createdAt, updatedAt) + Advanced (recurrence, tags, subtasks, dependencies, notifyBefore, snoozedUntil, estimatedMinutes, timeSpent, timeEntries)
1717
- **Indexes**: Performance-critical indexes on `quadrant`, `completed`, `dueDate`, `completedAt`, `createdAt`, `updatedAt`, `*tags`, `*dependencies`, `notificationSent`
1818
- **Migrations**: Schema changes always require migration in `lib/db.ts`. See `DATABASE_ARCHITECTURE.md` for full ERD.
1919

2020
### Key Architectural Decisions
21-
1. **Zero-knowledge sync**: Optional cloud sync encrypts locally with AES-256-GCM before upload. Worker stores only encrypted blobs. Encryption passphrase never leaves client.
22-
2. **Vector clocks**: Conflict detection via per-device version numbers. BFS algorithm prevents circular dependencies in task graph.
21+
1. **PocketBase cloud sync**: Optional cloud sync via self-hosted PocketBase server. Tasks stored as plaintext (user owns the server). OAuth authentication with Google/GitHub.
22+
2. **Last-write-wins conflict resolution**: Conflicts resolved using `client_updated_at` timestamps. BFS algorithm prevents circular dependencies in task graph.
2323
3. **Modular components**: Large files split into <300 line modules. Example: `lib/sync/` has 20+ focused modules vs monolithic sync engine.
2424
4. **Pure analytics functions**: All metric calculations in `lib/analytics/` are side-effect-free for testability and composability.
2525
5. **Transaction-based batch operations**: `lib/bulk-operations.ts` ensures atomicity (all-or-nothing) for multi-task updates.
@@ -38,16 +38,15 @@ This guide enables AI coding agents to work productively in the GSD Task Manager
3838
- **Quick Settings**: Slide-out panel (`quick-settings-panel.tsx`) for frequently-adjusted preferences (theme, notifications, sync interval).
3939

4040
### Sync Architecture
41-
- **Frontend**: `lib/sync/` with 20+ modules: `sync-coordinator.ts` (orchestrator), `engine.ts` (push/pull/resolve), `crypto.ts` (AES-256-GCM), `token-manager.ts` (OAuth + refresh), `queue-optimizer.ts` (batch operations).
42-
- **Backend**: Cloudflare Worker (`worker/src/`) with Hono router, D1 (SQLite), KV (OAuth state), R2 (encrypted blobs). OAuth with Google/Apple (OIDC-compliant).
43-
- **Endpoints**: `/api/auth/oauth/:provider/start`, `/api/auth/oauth/callback`, `/api/sync/push`, `/api/sync/pull`, `/api/sync/status`, `/api/devices`.
44-
- **State Machine**: Sync engine has 6 phases: Validating → Preparing → Pushing → Pulling → Resolving → Finalizing. See `SYNC_ARCHITECTURE.md` for Mermaid diagrams.
41+
- **Frontend**: `lib/sync/` with modular architecture: `pb-sync-engine.ts` (push/pull), `pb-realtime.ts` (SSE subscriptions), `pb-auth.ts` (OAuth), `pocketbase-client.ts` (SDK singleton), `task-mapper.ts` (field mapping), `sync-coordinator.ts` (orchestrator).
42+
- **Backend**: Self-hosted PocketBase server at `https://api.vinny.io` (AWS EC2). OAuth with Google/GitHub. API rules enforce per-user data isolation.
43+
- **Realtime**: PocketBase SSE (Server-Sent Events) for instant cross-device updates with echo filtering via `device_id`.
4544

4645
### MCP Server Integration
4746
- **Purpose**: Enable Claude Desktop to access/analyze tasks via natural language.
4847
- **Location**: `packages/mcp-server/` (standalone npm package, Node.js 18+).
4948
- **20 Tools**: Read (7), Write (5), Analytics (5), System (3). All write operations support `dryRun` mode.
50-
- **Config**: `~/Library/Application Support/Claude/claude_desktop_config.json` with `GSD_API_BASE_URL`, `GSD_AUTH_TOKEN`, `GSD_ENCRYPTION_PASSPHRASE`.
49+
- **Config**: `~/Library/Application Support/Claude/claude_desktop_config.json` with `GSD_POCKETBASE_URL`, `GSD_AUTH_TOKEN`.
5150

5251
## Developer Workflows
5352

@@ -67,11 +66,6 @@ This guide enables AI coding agents to work productively in the GSD Task Manager
6766
- **Deploy**: `./scripts/deploy-cloudfront-function.sh` after adding new App Router routes.
6867
- **Full Deploy**: `bun run deploy` (builds, syncs to S3, invalidates CloudFront)
6968

70-
### Worker Development
71-
- **Deploy**: `npm run deploy:all` in `worker/`
72-
- **Migrations**: `npm run migrations:dev` or `npm run migrations:prod`
73-
- **Setup**: `./worker/scripts/setup-{env}.sh` for environment config
74-
7569
### MCP Server Development
7670
- **Build**: `npm run build` in `packages/mcp-server/`
7771
- **Test**: `npm test` (unit tests with dry-run validation)
@@ -135,17 +129,15 @@ This guide enables AI coding agents to work productively in the GSD Task Manager
135129

136130
- **Client-side only**: No server rendering or network dependencies (except optional sync).
137131
- **Manifest & Icons**: Update `public/manifest.json`, icons, and `public/sw.js` together. Test with `bun run export`.
138-
- **Data**: All user data stays local by default. Export/import via JSON. Sync is opt-in with end-to-end encryption.
132+
- **Data**: All user data stays local by default. Export/import via JSON. Sync is opt-in via self-hosted PocketBase.
139133

140134
## References
141135

142136
- **Product Scope**: `CLAUDE.md` (features, architecture decisions, development notes)
143137
- **Technical Details**: `TECHNICAL.md` (stack, data layer, component structure, key patterns)
144138
- **Contribution Standards**: `coding-standards.md` (agentic behavior, solution quality, reflection)
145139
- **Database**: `DATABASE_ARCHITECTURE.md` (ERD, schema migrations, indexing strategy)
146-
- **Sync**: `SYNC_ARCHITECTURE.md` (state machine, conflict resolution, encryption)
147140
- **Features**: `GSD_FEATURES_GUIDE.md` (user-facing feature guide)
148-
- **OAuth/OIDC**: `OAUTH_OIDC_GUIDE.md` (OAuth flow, token lifecycle, security)
149141

150142
---
151143

DATABASE_ARCHITECTURE.md

Lines changed: 32 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## Overview
44

5-
GSD Task Manager uses **IndexedDB** via **Dexie.js** for client-side data persistence. The database follows a **zero-knowledge architecture** with optional end-to-end encrypted cloud sync. All data is stored locally in the browser, with JSON export/import for backups.
5+
GSD Task Manager uses **IndexedDB** via **Dexie.js** for client-side data persistence. The database follows a **privacy-first architecture** with optional cloud sync via PocketBase. All data is stored locally in the browser, with JSON export/import for backups.
66

7-
**Current Schema Version:** 12
7+
**Current Schema Version:** 13
88

99
---
1010

@@ -41,7 +41,6 @@ erDiagram
4141
boolean notificationSent "indexed"
4242
string lastNotificationAt "ISO timestamp"
4343
string snoozedUntil "ISO timestamp"
44-
object vectorClock "device_id to version_num"
4544
string archivedAt "ISO timestamp (when archived)"
4645
number estimatedMinutes "Planned time to complete"
4746
number timeSpent "Total minutes worked"
@@ -87,7 +86,6 @@ erDiagram
8786
number timestamp "Unix timestamp, indexed"
8887
number retryCount "indexed"
8988
object payload "TaskRecord or null"
90-
object vectorClock "device_id to version_num"
9189
array consolidatedFrom "IDs of merged operations"
9290
number lastAttemptAt "Unix timestamp"
9391
}
@@ -99,13 +97,8 @@ erDiagram
9997
string deviceId "UUID"
10098
string deviceName "User-friendly name"
10199
string email "OAuth email, nullable"
102-
string token "JWT, nullable"
103-
number tokenExpiresAt "Unix timestamp, nullable"
104100
number lastSyncAt "Unix timestamp, nullable"
105-
object vectorClock "device_id to version_num"
106-
string conflictStrategy "last_write_wins|manual"
107-
string serverUrl "API base URL"
108-
string provider "google|apple, nullable"
101+
string provider "google|github, nullable"
109102
number consecutiveFailures "Retry tracking"
110103
number lastFailureAt "Unix timestamp"
111104
string lastFailureReason "Error message"
@@ -159,7 +152,6 @@ erDiagram
159152
- **Subtasks:** Embedded checklist items (not normalized for simplicity)
160153
- **Tags:** Multi-entry index for fast filtering
161154
- **Notifications:** Tracks sent state and snooze timing
162-
- **Sync:** Vector clock for distributed conflict detection
163155
- **Time Tracking:** `estimatedMinutes` for planning, `timeEntries` array for actual work sessions, `timeSpent` for totals
164156

165157
**Indexes:**
@@ -255,7 +247,6 @@ id (primary, fixed to "settings")
255247
- **Operation Types:** create, update, delete
256248
- **Retry Logic:** Exponential backoff with `retryCount`
257249
- **Consolidation:** Multiple updates merged into single operation
258-
- **Vector Clock:** Ensures causal consistency
259250

260251
**Indexes:**
261252
```
@@ -270,7 +261,7 @@ retryCount
270261
1. User modifies task → Add to `syncQueue`
271262
2. Sync engine uploads → Mark as synced, remove from queue
272263
3. Offline → Queue persists until reconnected
273-
4. Conflict → Merge with vector clock, re-queue if needed
264+
4. Conflict → Resolve via last-write-wins, re-queue if needed
274265

275266
---
276267

@@ -279,8 +270,7 @@ retryCount
279270

280271
**Key Features:**
281272
- Singleton table (always `key="sync_config"`)
282-
- JWT token lifecycle management (7-day expiration)
283-
- Vector clock for this device
273+
- PocketBase auth state (token auto-managed by SDK)
284274
- Retry backoff state tracking
285275

286276
**Indexes:**
@@ -289,9 +279,8 @@ key (primary, fixed to "sync_config")
289279
```
290280

291281
**Security Notes:**
292-
- **Token Storage:** JWT stored in IndexedDB (encrypted DB on disk)
293-
- **Salt Storage:** Encryption salt stored encrypted in Cloudflare D1 (useless without passphrase)
294-
- **Zero-Knowledge:** Worker cannot decrypt task content
282+
- **Token Storage:** PocketBase auth token stored in localStorage (auto-managed by SDK)
283+
- **Access Control:** PocketBase API rules enforce per-user data isolation
295284

296285
---
297286

@@ -301,7 +290,7 @@ key (primary, fixed to "sync_config")
301290
**Key Features:**
302291
- Singleton table (always `key="device_info"`)
303292
- Generated on first install
304-
- Used in vector clock and sync history
293+
- Used in sync history and device attribution
305294

306295
**Indexes:**
307296
```
@@ -565,7 +554,7 @@ syncHistory: id, timestamp, status, deviceId
565554

566555
### Version 6 → 7 (Cloud Sync)
567556
- Created `syncQueue`, `syncMetadata`, `deviceInfo` tables
568-
- Added `vectorClock` to tasks
557+
- Added `vectorClock` to tasks (later removed in v13)
569558
- Initialized sync config with device UUID
570559

571560
### Version 7 → 8 (Completion Tracking)
@@ -592,6 +581,11 @@ syncHistory: id, timestamp, status, deviceId
592581
- Migration validates and repairs corrupt data
593582
- Backfilled defaults: `timeEntries=[]`, `timeSpent=0`
594583

584+
### Version 12 → 13 (PocketBase Sync Migration)
585+
- Removed `vectorClock` from tasks, syncQueue, and syncMetadata
586+
- Removed `conflictStrategy`, `serverUrl`, `token`, `tokenExpiresAt` from syncMetadata
587+
- Migrated cloud sync from Cloudflare Workers to PocketBase
588+
595589
---
596590

597591
## Data Integrity Rules
@@ -623,10 +617,6 @@ syncHistory: id, timestamp, status, deviceId
623617
- Multiple updates to same task merged into single operation
624618
- Tracked via `consolidatedFrom` array
625619

626-
7. **Vector Clock Monotonicity**
627-
- Each device increments own counter on every update
628-
- Never decremented (ensures causality)
629-
630620
---
631621

632622
## Security Considerations
@@ -637,11 +627,10 @@ syncHistory: id, timestamp, status, deviceId
637627
- **XSS Protection:** Strict CSP prevents script injection
638628

639629
### Cloud Sync (Optional)
640-
- **End-to-End Encryption:** AES-256-GCM with PBKDF2 key derivation (600k iterations)
641-
- **Zero-Knowledge:** Worker stores only encrypted blobs, cannot decrypt
642-
- **Transport Security:** HTTPS only, CORS restricted to production domain
643-
- **Token Security:** JWT tokens (HS256) with 7-day expiration, stored in IndexedDB
644-
- **Salt Storage:** Encryption salt stored encrypted in Cloudflare D1 (useless without passphrase)
630+
- **PocketBase Backend:** Self-hosted PocketBase server (tasks stored as plaintext, user owns the server)
631+
- **Access Control:** API rules enforce `owner = @request.auth.id` on all operations
632+
- **Transport Security:** HTTPS required for production deployments
633+
- **Token Security:** PocketBase auth tokens auto-managed by SDK in localStorage
645634

646635
### Data Sanitization
647636
- **Input Validation:** All fields validated with Zod schemas
@@ -700,15 +689,15 @@ syncHistory: id, timestamp, status, deviceId
700689
2. **Replace:** Delete all existing, import only
701690

702691
### Sync Backup
703-
- Cloud sync maintains encrypted copy in Cloudflare R2
704-
- Versioned by vector clock (conflict resolution)
705-
- Retention: Indefinite (user deletes account to purge)
692+
- Cloud sync maintains a copy in PocketBase SQLite database
693+
- Conflict resolution via last-write-wins using `client_updated_at` timestamps
694+
- Retention: Indefinite (user controls server lifecycle)
706695

707696
---
708697

709698
## Future Schema Changes (Planned)
710699

711-
### Version 13+ (Potential)
700+
### Version 14+ (Potential)
712701
- **Attachments:** Add `attachments[]` field (file references, not blobs)
713702
- **Subtask Dependencies:** Nested dependencies within subtasks
714703
- **Custom Fields:** User-defined metadata (JSON object)
@@ -717,6 +706,7 @@ syncHistory: id, timestamp, status, deviceId
717706
### Recently Implemented
718707
- **v11:** App preferences (pinned smart views)
719708
- **v12:** Time tracking (`estimatedMinutes`, `timeSpent`, `timeEntries`)
709+
- **v13:** Removed `vectorClock` from tasks/syncQueue/syncMetadata (migrated from Cloudflare Workers to PocketBase sync)
720710

721711
### Backward Compatibility
722712
- All migrations include `.upgrade()` hooks
@@ -745,63 +735,26 @@ flowchart TD
745735
HOOK --> UI
746736
747737
SYNC[Sync Engine] -->|Push/Pull| DB
748-
SYNC <-->|Encrypt/Decrypt| CRYPTO[AES-256-GCM]
749738
end
750739
751740
subgraph "Cloud (Optional)"
752-
WORKER[Cloudflare Worker]
753-
D1[(D1 Database<br/>SQLite)]
754-
R2[R2 Blob Storage<br/>Encrypted Tasks]
741+
PB[PocketBase Server]
742+
SQLITE[(SQLite Database)]
755743
756-
WORKER --> D1
757-
WORKER --> R2
744+
PB --> SQLITE
758745
end
759746
760-
SYNC <-->|HTTPS + JWT| WORKER
747+
SYNC <-->|HTTPS + OAuth| PB
748+
PB -->|SSE Realtime| SYNC
761749
762750
subgraph "MCP Server (Claude Desktop)"
763751
MCP[MCP Tools]
764-
MCP_CRYPTO[Crypto Manager]
765-
766-
MCP <-->|Decrypt| MCP_CRYPTO
767-
MCP <-->|API Calls| WORKER
752+
MCP <-->|PocketBase SDK| PB
768753
end
769754
770755
style DB fill:#4CAF50
771-
style D1 fill:#2196F3
772-
style R2 fill:#FF9800
773-
style CRYPTO fill:#F44336
774-
style MCP_CRYPTO fill:#F44336
775-
```
776-
777-
---
778-
779-
## Diagram: Sync Vector Clock Flow
780-
781-
```mermaid
782-
sequenceDiagram
783-
participant D1 as Device 1
784-
participant W as Worker
785-
participant D2 as Device 2
786-
787-
Note over D1: Edit task A<br/>VC: {d1:1}
788-
D1->>W: Push (encrypted blob + VC)
789-
W->>W: Store in R2
790-
791-
Note over D2: Edit task A<br/>VC: {d2:1}
792-
D2->>W: Push (encrypted blob + VC)
793-
W->>W: Detect conflict<br/>(VC: {d1:1} vs {d2:1})
794-
795-
W->>D1: Pull (both versions)
796-
W->>D2: Pull (both versions)
797-
798-
Note over D1: Auto-resolve<br/>(last-write-wins)<br/>VC: {d1:2, d2:1}
799-
D1->>W: Push resolved (encrypted)
800-
801-
Note over D2: Auto-resolve<br/>(last-write-wins)<br/>VC: {d1:2, d2:1}
802-
D2->>W: Push resolved (encrypted)
803-
804-
W->>W: Identical VCs → Sync complete
756+
style SQLITE fill:#2196F3
757+
style PB fill:#FF9800
805758
```
806759

807760
---
@@ -814,13 +767,12 @@ sequenceDiagram
814767
- CRUD: `lib/tasks.ts`
815768
- Filters: `lib/filters.ts`
816769
- Dependencies: `lib/dependencies.ts`
817-
- Sync: `lib/sync/engine/coordinator.ts`
770+
- Sync: `lib/sync/sync-coordinator.ts`
818771

819772
- **Testing:**
820773
- Data layer tests: `tests/data/`
821774
- Coverage: ≥80% statements (Vitest)
822775

823776
- **Documentation:**
824777
- Project README: `README.md`
825-
- Feature guide: `GSD_FEATURES_GUIDE.md`
826778
- Claude instructions: `CLAUDE.md`

0 commit comments

Comments
 (0)