Repository Public
1<!--2SP Notes iOS3File: docs/AUDIT.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->7# Audit of the existing project (2026-11-18)89Read on the backend node (`M4M64c:~/apps/note-spboucher-ai`, commit `2c18f85`, never modified from here) and on this Mac.1011## Backend — note.spboucher.ai1213| Subject | Finding |14|---|---|15| Stack | Next.js 16 route handlers, PostgreSQL 17 + pgvector, pg-boss worker, PM2, public route through the MacLustr tunnel (BHS64). |16| Data model | A note is a row of `pages` (tree by `parent_id`, `section` notes/documents/databases/projects/research, `type` page/database/research, `pinned`, `archived`, `deleted_at`, `inbox_at`, `properties` JSONB, `version`). Tags (`tags`, `page_tags`), attachments (`attachments`, files on disk by SHA-256), tasks, page history (`page_versions`, 200 per page), links/backlinks, Notion-like databases, research references, AI tables. |17| Note format | **ProseMirror JSON** (Tiptap 3): paragraph, heading 1–3, bullet/ordered/task lists (nested), blockquote, callout, details (toggle), code block (language), table, image, file block, block/inline math (LaTeX), mention (link to a page), footnote, YouTube embed, horizontal rule, AI block; marks bold, italic, underline, strike, code, highlight, subscript, superscript, link. Stable block ids on 14 node types. Schema recorded in `SPNotesCore/docs/reference/web-editor-schema.txt`. |18| Saving | `PATCH /api/pages/<id>` with `baseVersion`; a stale base is refused with 409 and the server copy; `/resolve` settles a conflict keeping both copies in the history. Idempotency keys on mutations. |19| Folders | There is **no folder entity**: the tree of pages and the sections play that role. |20| Favourites | Not in the model (`pinned` only). |21| Search | Server side, hybrid (tsvector + pgvector + trigram), online only. |22| AI | `POST /api/ai/action` (20 inline actions + free instruction, SSE, text only — the client applies the result) and `POST /api/ai/chat` (grounded assistant with sources). Providers OpenAI and Anthropic are routed by the server; keys never leave it. |23| Authentication | Passkeys only (WebAuthn, SimpleWebAuthn 14), relying party `note.spboucher.ai`, revocable server-side sessions in an HttpOnly cookie, step-up (5 min) for permanent deletion and security changes, same-origin check on mutations. Enrollment windows are opened from the node CLI only. |24| Synchronisation | None for native clients before this project: the web client keeps one draft per open page in IndexedDB. No change feed, no tombstones, server-generated ids. |25| Administration | Settings (AI routing, budget, jobs, audit log, security), import/export (Markdown, HTML, JSON, ZIP), backups. Web only. |26| Production data | 4 pages, 1 attachment, 3 tasks at the time of the audit (structure inspected, no content copied). |2728## What had to be added to the backend (branch `native-sync`, written by the macOS session, additive)2930Change feed `GET /api/sync?since=<rev>` (revision sequence maintained by database triggers, tombstones for purges), client-chosen ids31for `POST /api/pages` and `POST /api/attachments` (offline creation, stable internal links), `/.well-known/apple-app-site-association`32(webcredentials for the two apps), a readable session label for the native apps. Contract: `SPNotesCore/docs/reference/BACKEND_CONTRACT.md`.33Nothing existing was changed or removed.3435## SP Notes macOS3637Did **not exist** when this work started (nothing on this Mac, no repository on spbgit). It is being built at the same time by another38session (`~/Desktop/Cluster/apple/SPNotes`). The two sessions agreed on a split: the macOS session owns the backend additions; this39session owns the shared Swift core, **`~/Desktop/Cluster/apple/SPNotesCore`** (`SPNotesDocument`, `SPNotesStore`, `SPNotesAPI`,40`SPNotesSync`), consumed by both apps. The interfaces (SwiftUI/UIKit here, AppKit there) are distinct.4142## Decisions that follow from the audit4344- The editor is native (UITextView on TextKit 2) and works on the ProseMirror document **without loss**: node types and attributes this45 app does not edit (details, YouTube, footnotes, AI blocks, unknown future nodes) are kept untouched and shown as neutral blocks.46- Folders = pages flagged `properties.folder = true` (a plain page with sub-pages on the web). Favourite = `properties.favorite = true`.47 Reminder = a task `{pageId, dueAt}`. PencilKit drawing = an image (visible everywhere) + a companion `.pkdrawing` attachment48 (editable source). Same conventions in the macOS app.49- Search is local (SQLite FTS5) so it works offline; the server search is not required.50- Web-only features not rebuilt natively are listed in `PARITY_MATRIX.md`.51