How aidenlx/obsidian-bridge works
Project type and purpose
• This is a TypeScript-based MarginNote 3 “addon” (plugin) whose sole purpose is to bridge content between MarginNote and Obsidian.
• It runs inside MarginNote, listens for user actions or document changes, transforms and packages those into Obsidian-compatible notes, and then hands them off to Obsidian (via the companion app or URI schemes).
File structure
• Top-level config files:
• rollup.config.js – bundler entry points and output settings
• tsconfig.json / tsconfig-lib.json – compiler targets and declarations
• Source root (src/):
• entry points: index.ts, main.ts, toggle-addon.ts, event-handlers.ts
• “modules” folder: parser.ts, recorder.ts, scan.ts, sender.ts, translate.ts, type-tools.ts, tools.ts, url-obj.ts
• const.ts and return.ts hold constants and return-data schemas
• Package manifest (package.json) indicates dependencies, build & publish scripts, and the addon manifest (mnaddon.json).
README for additional insights
• No detailed architecture section, but the purpose is clearly a uni-directional or bi-directional data flow bridge.
• Requires MarginNote v3.7.12+ and relies on its API.
Main components
a. Plugin runtime (inside MarginNote)
– Entry module (main.ts / index.ts)
– Event dispatcher (event-handlers.ts)
– Parser: reads MarginNote document structure, annotations
– Recorder: tracks user interactions or edit sessions
– Scanner: extracts metadata, attachments, links
– Translator: maps MN data structures to Obsidian Markdown/JSON
– Sender: invokes Obsidian Companion (HTTP/URI) or writes to local vault
– Tools & Type-Tools: shared utilities, type definitions, URL assembly
c. External systems:
– MarginNote API (host process exposing scriptable events & data)
– Obsidian Vault (local folder file system or remote via companion)
– Optional: MarginNote Companion service (if using HTTP plugin host)
Relationships and interactions
• Parser/Scanner feed data into Translator, which emits standard note payloads
• Sender takes payloads and pushes to Obsidian (call-out: “HTTP POST to Companion” or “write markdown file”)
Architectural patterns & design principles
• Modular separation: each core function in its own module directory
• Single Responsibility: parser only reads data, translator only transforms, sender only communicates
• Bundling via Rollup to produce one minified JS file (mnaddon.json points to it)
• Config-driven: constants and return schemas externalized in const.ts and return.ts