# aries-0331/bookmark-assistant architecture

> Architecture diagram of the GitHub repository aries-0331/bookmark-assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aries-0331/bookmark-assistant
- Repository: https://github.com/aries-0331/bookmark-assistant

## Overview

#### Purpose and topology
Bookmark Assistant is a self-hostable Chrome extension plus Node.js server that captures browser bookmarks, Reading List entries, current pages, and context-menu links, then synchronizes them into a user’s Notion database. It is a pnpm TypeScript monorepo with deployable extension/server applications and reusable core packages.

#### Extension entry points and browser boundary
Chrome loads the extension through `packages/extension/public/manifest.json`. The persistent orchestration point is the background runtime at `packages/extension/src/background/index.ts`; user-facing entry points are the popup at `packages/extension/src/popup/popup.tsx` and options application at `packages/extension/src/options/options.tsx`.

The extension is the boundary to Chrome APIs: it reads bookmarks/Reading List, registers browser actions/context menus, obtains page content, and persists local state in Chrome storage. It communicates with the configured self-hosted server rather than calling Notion directly for sync.

#### Capture and local normalization
Capture paths include background extraction and content-side description extraction:
- `packages/extension/src/background/content-extractor.ts`
- `packages/extension/src/content/description-extractor.ts`
- `packages/extension/src/utils/bookmark.ts`

The extension transforms browser-specific bookmark, Reading List, and page/link data into normalized sync payloads. Shared link/content rules live in `packages/extension-core/src/content.ts`, `packages/extension-core/src/links.ts`, and `packages/extension-core/src/reading-list.ts`, separating reusable capture semantics from Chrome UI/runtime code.

#### Extension sync orchestration
The background sync layer coordinates manual, scheduled, and stateful synchronization:
- `packages/extension/src/background/sync.ts`
- `packages/extension/src/background/auto-sync.ts`
- `packages/extension/src/background/server-api.ts`

It sends normalized records to the server, tracks fingerprints/sync state locally, and updates popup/options state. Authentication is initiated through `packages/extension/src/background/oauth.ts`; server configuration and extension identity constraints are centralized in `packages/extension/src/background/config.ts`.

#### Server API, authentication, and persistence
The Node.js server starts at `packages/server/src/index.ts` and composes HTTP routes from `packages/server/src/routes/index.ts`. Route groups cover bookmark ingestion, Notion operations, OAuth, user state, and administration, including `packages/server/src/routes/bookmarks.ts` and `packages/server/src/routes/oauth.ts`.

Authentication/security middleware sits at the API boundary in `packages/server/src/middleware/auth.ts` and `packages/server/src/middleware/security.ts`. The server uses JWT-based authorization and is configured to accept the designated extension identity. PostgreSQL persistence is modeled through Prisma in `packages/server/prisma/schema.prisma`, with migrations under `packages/server/prisma/migrations`.

#### Notion synchronization pipeline
Server-side bookmark handling converts submitted records into Notion database operations while preserving deduplication and result state:
- `packages/server/src/services/notion.ts`
- `packages/server-core/src/bookmarks.ts`
- `packages/server-core/src/notion-database.ts`

The server owns stored Notion access tokens and connects to the Notion API on behalf of authenticated users. Core logic handles database/property mapping, URL and sync-ID matching, persistence abstractions, and per-item sync results through `packages/server-core/src/notion-properties.ts`, `packages/server-core/src/persistence.ts`, and `packages/server-core/src/sync-results.ts`.

#### Shared contracts and deployment
`packages/contracts/src/types.ts` and `packages/contracts/src/index.ts` define cross-package data shapes; `packages/server-core/src/index.ts` and `packages/extension-core/src/index.ts` expose reusable domain logic. This limits direct coupling between the Chrome runtime and server implementation.

Material runtime dependencies are Chrome extension APIs, Node.js 20.x for the server, PostgreSQL/Prisma, and the external Notion API/OAuth service. The server includes Vercel deployment configuration at `packages/server/vercel.json`; extension builds are produced by Vite configuration in `packages/extension/vite.config.ts`.

Main entry points: [`packages/extension/src/background/index.ts`](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/src/background/index.ts) (Background runtime), [`packages/server/src/services/notion.ts`](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/services/notion.ts) (Notion sync service), [`packages/server/src/routes/index.ts`](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/routes/index.ts) (HTTP routes), [`packages/server/src/routes/oauth.ts`](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/routes/oauth.ts) (OAuth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["Chrome Extension"]
  node_manifest["Extension manifest<br/>extension entry<br/>[manifest.json]"]
  node_extension_ui["Popup &amp; options<br/>extension UI<br/>[popup.tsx]"]
  node_background["Background runtime<br/>extension orchestrator<br/>[index.ts]"]
  node_capture["Capture &amp; normalization<br/>extension capture"]
  node_extension_sync["Sync orchestration<br/>extension sync<br/>[sync.ts]"]
  node_extension_auth["OAuth &amp; server config<br/>extension auth<br/>[oauth.ts]"]
end

subgraph group_shared["Shared Packages"]
  node_extension_core["Extension capture rules<br/>shared domain package<br/>[content.ts]"]
  node_contracts["Cross-package contracts<br/>shared types<br/>[types.ts]"]
  node_server_core["Sync domain core<br/>shared domain package<br/>[bookmarks.ts]"]
end

subgraph group_server["Node.js Server"]
  node_server_entry["Server entry<br/>Node.js runtime<br/>[index.ts]"]
  node_api_routes["HTTP routes<br/>API composition<br/>[index.ts]"]
  node_api_security["Auth &amp; security middleware<br/>API boundary<br/>[auth.ts]"]
  node_bookmark_ingestion["Bookmark ingestion<br/>API route<br/>[bookmarks.ts]"]
  node_server_oauth["OAuth routes<br/>API route<br/>[oauth.ts]"]
  node_notion_service["Notion sync service<br/>server service<br/>[notion.ts]"]
end

subgraph group_external["External Systems"]
  node_chrome{{"Chrome APIs<br/>browser platform"}}
  node_postgres[("PostgreSQL via Prisma<br/>database<br/>[schema.prisma]")]
  node_notion{{"Notion API &amp; OAuth<br/>external API"}}
end

node_manifest -->|"loads"| node_background
node_manifest -->|"loads"| node_extension_ui
node_chrome -->|"browser events"| node_background
node_extension_ui -->|"user actions"| node_background
node_background -->|"collects"| node_capture
node_capture -->|"applies rules"| node_extension_core
node_background -->|"triggers"| node_extension_sync
node_extension_sync -->|"serializes payloads"| node_contracts
node_extension_sync -->|"sync API"| node_api_routes
node_background -->|"auth flow"| node_extension_auth
node_extension_auth -->|"OAuth requests"| node_server_oauth
node_server_entry -->|"composes"| node_api_routes
node_api_routes -->|"protects routes"| node_api_security
node_api_security -->|"authorizes"| node_bookmark_ingestion
node_api_routes -->|"routes OAuth"| node_server_oauth
node_bookmark_ingestion -->|"submits records"| node_notion_service
node_notion_service -->|"uses sync rules"| node_server_core
node_server_core -->|"reads and writes state"| node_postgres
node_notion_service -->|"database operations"| node_notion
node_server_oauth -->|"authorization"| node_notion
node_server_oauth -->|"stores tokens"| node_postgres
node_notion_service -.->|"returns results"| node_contracts

click node_manifest "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/public/manifest.json"
click node_extension_ui "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/src/popup/popup.tsx"
click node_background "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/src/background/index.ts"
click node_capture "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/src/background/content-extractor.ts"
click node_extension_sync "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/src/background/sync.ts"
click node_extension_auth "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/src/background/oauth.ts"
click node_extension_core "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension-core/src/content.ts"
click node_contracts "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/contracts/src/types.ts"
click node_server_entry "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/index.ts"
click node_api_routes "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/routes/index.ts"
click node_api_security "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/middleware/auth.ts"
click node_bookmark_ingestion "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/routes/bookmarks.ts"
click node_server_oauth "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/routes/oauth.ts"
click node_notion_service "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/services/notion.ts"
click node_server_core "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server-core/src/bookmarks.ts"
click node_postgres "https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/prisma/schema.prisma"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_manifest,node_extension_ui,node_background,node_capture,node_extension_sync,node_extension_auth toneBlue
class node_extension_core,node_contracts,node_server_core toneAmber
class node_server_entry,node_api_routes,node_api_security,node_bookmark_ingestion,node_server_oauth,node_notion_service toneMint
class node_chrome,node_postgres,node_notion toneRose
```

## Components

### Chrome Extension

Browser runtime and capture orchestration.

- [Extension manifest](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/public/manifest.json): extension entry · `packages/extension/public/manifest.json`
- [Popup & options](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/src/popup/popup.tsx): extension UI · User controls and sync status. · `packages/extension/src/popup/popup.tsx`
- [Background runtime](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/src/background/index.ts): extension orchestrator · Persistent browser event and capture coordinator. · `packages/extension/src/background/index.ts`
- [Capture & normalization](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/src/background/content-extractor.ts): extension capture · Extracts page data and normalizes browser records. · `packages/extension/src/background/content-extractor.ts`
- [Sync orchestration](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/src/background/sync.ts): extension sync · Runs manual and scheduled sync and tracks local state. · `packages/extension/src/background/sync.ts`
- [OAuth & server config](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension/src/background/oauth.ts): extension auth · Initiates authentication and enforces server identity configuration. · `packages/extension/src/background/oauth.ts`

### Shared Packages

Reusable capture and server domain logic.

- [Extension capture rules](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/extension-core/src/content.ts): shared domain package · Shared link, content, and Reading List semantics. · `packages/extension-core/src/content.ts`
- [Cross-package contracts](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/contracts/src/types.ts): shared types · Sync request and response data shapes. · `packages/contracts/src/types.ts`
- [Sync domain core](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server-core/src/bookmarks.ts): shared domain package · Deduplication, mapping, persistence abstractions, and item results. · `packages/server-core/src/bookmarks.ts`

### Node.js Server

Authenticated sync API and Notion integration.

- [Server entry](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/index.ts): Node.js runtime · `packages/server/src/index.ts`
- [HTTP routes](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/routes/index.ts): API composition · Bookmark, Notion, OAuth, user, and admin endpoints. · `packages/server/src/routes/index.ts`
- [Auth & security middleware](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/middleware/auth.ts): API boundary · JWT authorization and extension identity validation. · `packages/server/src/middleware/auth.ts`
- [Bookmark ingestion](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/routes/bookmarks.ts): API route · Receives normalized extension records. · `packages/server/src/routes/bookmarks.ts`
- [OAuth routes](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/routes/oauth.ts): API route · Connects user accounts to Notion. · `packages/server/src/routes/oauth.ts`
- [Notion sync service](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/src/services/notion.ts): server service · Converts submitted bookmarks into Notion operations. · `packages/server/src/services/notion.ts`

### External Systems

- **Chrome APIs**: browser platform · Bookmarks, Reading List, tabs, context menus, and storage.
- [PostgreSQL via Prisma](https://github.com/aries-0331/bookmark-assistant/blob/main/packages/server/prisma/schema.prisma): database · Stores users, sync state, and Notion access tokens. · `packages/server/prisma/schema.prisma`
- **Notion API & OAuth**: external API

## Connections

- Extension manifest → Background runtime: loads
- Extension manifest → Popup & options: loads
- Chrome APIs → Background runtime: browser events
- Popup & options → Background runtime: user actions
- Background runtime → Capture & normalization: collects
- Capture & normalization → Extension capture rules: applies rules
- Background runtime → Sync orchestration: triggers
- Sync orchestration → Cross-package contracts: serializes payloads
- Sync orchestration → HTTP routes: sync API
- Background runtime → OAuth & server config: auth flow
- OAuth & server config → OAuth routes: OAuth requests
- Server entry → HTTP routes: composes
- HTTP routes → Auth & security middleware: protects routes
- Auth & security middleware → Bookmark ingestion: authorizes
- HTTP routes → OAuth routes: routes OAuth
- Bookmark ingestion → Notion sync service: submits records
- Notion sync service → Sync domain core: uses sync rules
- Sync domain core → PostgreSQL via Prisma: reads and writes state
- Notion sync service → Notion API & OAuth: database operations
- OAuth routes → Notion API & OAuth: authorization
- OAuth routes → PostgreSQL via Prisma: stores tokens
- Notion sync service → Cross-package contracts: returns results
