# nicepkg/ctxport architecture

> Architecture diagram of the GitHub repository nicepkg/ctxport, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nicepkg/ctxport
- Repository: https://github.com/nicepkg/ctxport

## Overview

#### Purpose and Topology
CtxPort is a pnpm/Turborepo monorepo for a Manifest V3 browser extension that locally exports supported AI conversations and GitHub discussions as structured Markdown “Context Bundles.” A separate Next.js documentation/marketing site publishes product and usage content. Workspace boundaries are declared through `pnpm-workspace.yaml` and orchestrated by `turbo.json`.

#### Runtime Entry Points
The extension is the primary product runtime, built with WXT, React, and TypeScript. Its background entry point supports extension lifecycle/runtime integration; the content script mounts UI into supported pages; the popup provides extension UI.
- `apps/browser-extension/src/entrypoints/background.ts`
- `apps/browser-extension/src/entrypoints/content.tsx`
- `apps/browser-extension/src/entrypoints/popup/main.tsx`
- `apps/browser-extension/wxt.config.ts`

The website is a Next.js locale-routed documentation application, with middleware and OpenNext/Cloudflare-oriented deployment configuration.
- `apps/web/src/app/[locale]/page.tsx`
- `apps/web/src/app/[locale]/docs/[[...mdxPath]]/page.tsx`
- `apps/web/middleware.ts`
- `apps/web/open-next.config.ts`

#### Platform Plugin Boundary
`core-plugins` isolates each source platform behind a plugin contract and central registry. The extension selects a plugin based on the active page; plugins parse platform-specific DOM/API representations into shared conversation data rather than leaking source markup into export logic.
- `packages/core-plugins/src/types.ts`
- `packages/core-plugins/src/registry.ts`
- `packages/core-plugins/src/plugins/index.ts`

Platform implementations cover ChatGPT, Claude, Gemini, DeepSeek, Doubao, Grok, and GitHub. ChatGPT has the richest extraction pipeline, including content flatteners and tree linearization; GitHub includes GraphQL integration.
- `packages/core-plugins/src/plugins/chatgpt/plugin.ts`
- `packages/core-plugins/src/plugins/chatgpt/tree-linearizer.ts`
- `packages/core-plugins/src/plugins/github/graphql.ts`

#### Canonical Data and Serialization Pipeline
The cross-package contract is the Context Bundle schema: source metadata, URL/title/date, conversation nodes, and selected output format. Plugins produce this canonical representation; the Markdown package applies format selection and serializes it into clipboard-ready Markdown with frontmatter.
- `packages/core-schema/src/content-bundle.ts`
- `packages/core-schema/src/errors.ts`
- `packages/core-markdown/src/formats.ts`
- `packages/core-markdown/src/serializer.ts`

This creates a deliberate boundary: platform adapters handle acquisition/normalization, while `core-markdown` owns Full, User Only, Code Only, and Compact presentation. Token estimation is colocated with export serialization concerns.
- `packages/core-markdown/src/token-estimator.ts`
- `packages/core-markdown/src/index.ts`

#### Extension Interaction and Copy Flow
On a supported site, the content entrypoint injects the React application and contextual copy controls. User actions from in-chat controls, sidebar/list copy, context menu, or keyboard-oriented extension behavior invoke conversation extraction, serialize the selected bundle, and write it to the local clipboard. No backend, account, or upload pipeline is represented.
- `apps/browser-extension/src/components/app.tsx`
- `apps/browser-extension/src/components/copy-button.tsx`
- `apps/browser-extension/src/components/list-copy-icon.tsx`
- `apps/browser-extension/src/hooks/use-copy-conversation.ts`

#### Shared Presentation Layer
`shared-ui` is a reusable React component, rendering, localization, and styling package consumed by application surfaces. It is separate from extraction and serialization, keeping UI changes from affecting bundle semantics.
- `packages/shared-ui/src/index.ts`
- `packages/shared-ui/src/components/renderer/markdown-renderer.tsx`
- `packages/shared-ui/src/i18n/react.tsx`

#### Website Content and Delivery
The website renders English and Chinese MDX content through locale-aware App Router layouts and documentation routes. It is informational rather than part of the browser extension’s copy path. CI, website deployment, and extension release are automated through GitHub Actions.
- `apps/web/content/en/_meta.ts`
- `apps/web/content/zh/_meta.ts`
- `.github/workflows/deploy-website.yml`
- `.github/workflows/release-extension.yml`

Main entry points: [`packages/core-plugins/src/plugins/index.ts`](https://github.com/nicepkg/ctxport/blob/main/packages/core-plugins/src/plugins/index.ts) (Platform adapters), [`apps/browser-extension/wxt.config.ts`](https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/wxt.config.ts) (WXT build config), [`apps/browser-extension/src/hooks/use-copy-conversation.ts`](https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/src/hooks/use-copy-conversation.ts) (Copy conversation flow), [`apps/browser-extension/src/components/app.tsx`](https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/src/components/app.tsx) (Injected React app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["Browser Extension"]
  node_wxt{{"WXT build config<br/>extension build<br/>[wxt.config.ts]"}}
  node_background["Background runtime<br/>extension entrypoint<br/>[background.ts]"]
  node_content["Content runtime<br/>extension entrypoint<br/>[content.tsx]"]
  node_popup["Popup UI<br/>extension entrypoint<br/>[main.tsx]"]
  node_extension_app["Injected React app<br/>React UI<br/>[app.tsx]"]
  node_copy_flow["Copy conversation flow<br/>interaction hook"]
end

subgraph group_core["Extraction &amp; Export"]
  node_plugin_contract["Plugin contract<br/>shared types<br/>[types.ts]"]
  node_plugin_registry["Plugin registry<br/>platform selection<br/>[registry.ts]"]
  node_platform_plugins["Platform adapters<br/>plugin implementations<br/>[index.ts]"]
  node_chatgpt_pipeline["ChatGPT tree extraction<br/>plugin pipeline<br/>[tree-linearizer.ts]"]
  node_github_graphql["GitHub GraphQL adapter<br/>platform integration<br/>[graphql.ts]"]
  node_bundle_schema["Context Bundle schema<br/>canonical data model<br/>[content-bundle.ts]"]
  node_markdown_formats["Export formats<br/>format selection<br/>[formats.ts]"]
  node_markdown_serializer["Markdown serializer<br/>serialization<br/>[serializer.ts]"]
  node_shared_ui["Shared UI<br/>React component package<br/>[index.ts]"]
end

subgraph group_web["Documentation Site"]
  node_web_routes["Locale docs routes<br/>Next.js App Router<br/>[page.tsx]"]
  node_web_middleware["Locale middleware<br/>Next.js middleware<br/>[middleware.ts]"]
  node_mdx_content["English &amp; Chinese MDX<br/>documentation content<br/>[_meta.ts]"]
end

subgraph group_delivery["Automation"]
  node_web_deploy["Website deployment<br/>GitHub Actions<br/>[deploy-website.yml]"]
  node_extension_release["Extension release<br/>GitHub Actions"]
end

node_wxt -->|"builds"| node_background
node_wxt -->|"builds"| node_content
node_wxt -->|"builds"| node_popup
node_content -->|"mounts"| node_extension_app
node_extension_app -->|"copy actions"| node_copy_flow
node_popup -->|"uses"| node_shared_ui
node_extension_app -->|"uses"| node_shared_ui
node_copy_flow -->|"selects adapter"| node_plugin_registry
node_plugin_registry -->|"uses"| node_plugin_contract
node_plugin_registry -->|"resolves"| node_platform_plugins
node_platform_plugins -->|"includes"| node_chatgpt_pipeline
node_platform_plugins -->|"includes"| node_github_graphql
node_platform_plugins -->|"normalizes to"| node_bundle_schema
node_plugin_contract -->|"defines output"| node_bundle_schema
node_copy_flow -->|"selects format"| node_markdown_formats
node_bundle_schema -->|"serializes"| node_markdown_serializer
node_markdown_formats -->|"configures"| node_markdown_serializer
node_markdown_serializer -->|"Markdown to clipboard"| node_copy_flow
node_web_middleware -->|"routes locale"| node_web_routes
node_mdx_content -->|"renders in"| node_web_routes
node_web_deploy -.->|"deploys"| node_web_routes
node_extension_release -.->|"releases build"| node_wxt

click node_wxt "https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/wxt.config.ts"
click node_background "https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/src/entrypoints/background.ts"
click node_content "https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/src/entrypoints/content.tsx"
click node_popup "https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/src/entrypoints/popup/main.tsx"
click node_extension_app "https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/src/components/app.tsx"
click node_copy_flow "https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/src/hooks/use-copy-conversation.ts"
click node_plugin_contract "https://github.com/nicepkg/ctxport/blob/main/packages/core-plugins/src/types.ts"
click node_plugin_registry "https://github.com/nicepkg/ctxport/blob/main/packages/core-plugins/src/registry.ts"
click node_platform_plugins "https://github.com/nicepkg/ctxport/blob/main/packages/core-plugins/src/plugins/index.ts"
click node_chatgpt_pipeline "https://github.com/nicepkg/ctxport/blob/main/packages/core-plugins/src/plugins/chatgpt/tree-linearizer.ts"
click node_github_graphql "https://github.com/nicepkg/ctxport/blob/main/packages/core-plugins/src/plugins/github/graphql.ts"
click node_bundle_schema "https://github.com/nicepkg/ctxport/blob/main/packages/core-schema/src/content-bundle.ts"
click node_markdown_formats "https://github.com/nicepkg/ctxport/blob/main/packages/core-markdown/src/formats.ts"
click node_markdown_serializer "https://github.com/nicepkg/ctxport/blob/main/packages/core-markdown/src/serializer.ts"
click node_shared_ui "https://github.com/nicepkg/ctxport/blob/main/packages/shared-ui/src/index.ts"
click node_web_routes "https://github.com/nicepkg/ctxport/blob/main/apps/web/src/app/%5Blocale%5D/docs/%5B%5B...mdxPath%5D%5D/page.tsx"
click node_web_middleware "https://github.com/nicepkg/ctxport/blob/main/apps/web/middleware.ts"
click node_mdx_content "https://github.com/nicepkg/ctxport/blob/main/apps/web/content/en/_meta.ts"
click node_web_deploy "https://github.com/nicepkg/ctxport/blob/main/.github/workflows/deploy-website.yml"
click node_extension_release "https://github.com/nicepkg/ctxport/blob/main/.github/workflows/release-extension.yml"

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_wxt,node_background,node_content,node_popup,node_extension_app,node_copy_flow toneBlue
class node_plugin_contract,node_plugin_registry,node_platform_plugins,node_chatgpt_pipeline,node_github_graphql,node_bundle_schema,node_markdown_formats,node_markdown_serializer,node_shared_ui toneAmber
class node_web_routes,node_web_middleware,node_mdx_content toneMint
class node_web_deploy,node_extension_release toneRose
```

## Components

### Browser Extension

- [WXT build config](https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/wxt.config.ts): extension build · `apps/browser-extension/wxt.config.ts`
- [Background runtime](https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/src/entrypoints/background.ts): extension entrypoint · Handles extension lifecycle and runtime integration. · `apps/browser-extension/src/entrypoints/background.ts`
- [Content runtime](https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/src/entrypoints/content.tsx): extension entrypoint · Injects contextual controls into supported pages. · `apps/browser-extension/src/entrypoints/content.tsx`
- [Popup UI](https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/src/entrypoints/popup/main.tsx): extension entrypoint · `apps/browser-extension/src/entrypoints/popup/main.tsx`
- [Injected React app](https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/src/components/app.tsx): React UI · `apps/browser-extension/src/components/app.tsx`
- [Copy conversation flow](https://github.com/nicepkg/ctxport/blob/main/apps/browser-extension/src/hooks/use-copy-conversation.ts): interaction hook · Extracts, serializes, and copies the selected conversation locally. · `apps/browser-extension/src/hooks/use-copy-conversation.ts`

### Extraction & Export

- [Plugin contract](https://github.com/nicepkg/ctxport/blob/main/packages/core-plugins/src/types.ts): shared types · Defines platform adapters and canonical conversation output. · `packages/core-plugins/src/types.ts`
- [Plugin registry](https://github.com/nicepkg/ctxport/blob/main/packages/core-plugins/src/registry.ts): platform selection · Selects the adapter for the active page. · `packages/core-plugins/src/registry.ts`
- [Platform adapters](https://github.com/nicepkg/ctxport/blob/main/packages/core-plugins/src/plugins/index.ts): plugin implementations · ChatGPT, Claude, Gemini, DeepSeek, Doubao, Grok, and GitHub acquisition. · `packages/core-plugins/src/plugins/index.ts`
- [ChatGPT tree extraction](https://github.com/nicepkg/ctxport/blob/main/packages/core-plugins/src/plugins/chatgpt/tree-linearizer.ts): plugin pipeline · Flattens and linearizes ChatGPT conversation trees. · `packages/core-plugins/src/plugins/chatgpt/tree-linearizer.ts`
- [GitHub GraphQL adapter](https://github.com/nicepkg/ctxport/blob/main/packages/core-plugins/src/plugins/github/graphql.ts): platform integration · `packages/core-plugins/src/plugins/github/graphql.ts`
- [Context Bundle schema](https://github.com/nicepkg/ctxport/blob/main/packages/core-schema/src/content-bundle.ts): canonical data model · Carries source metadata, conversation nodes, and output format. · `packages/core-schema/src/content-bundle.ts`
- [Export formats](https://github.com/nicepkg/ctxport/blob/main/packages/core-markdown/src/formats.ts): format selection · Full, User Only, Code Only, and Compact presentations. · `packages/core-markdown/src/formats.ts`
- [Markdown serializer](https://github.com/nicepkg/ctxport/blob/main/packages/core-markdown/src/serializer.ts): serialization · Produces clipboard-ready Markdown with frontmatter and token estimation. · `packages/core-markdown/src/serializer.ts`
- [Shared UI](https://github.com/nicepkg/ctxport/blob/main/packages/shared-ui/src/index.ts): React component package · Reusable rendering, localization, and styling. · `packages/shared-ui/src/index.ts`

### Documentation Site

- [Locale docs routes](https://github.com/nicepkg/ctxport/blob/main/apps/web/src/app/%5Blocale%5D/docs/%5B%5B...mdxPath%5D%5D/page.tsx): Next.js App Router · Renders localized landing and MDX documentation pages. · `apps/web/src/app/[locale]/docs/[[...mdxPath]]/page.tsx`
- [Locale middleware](https://github.com/nicepkg/ctxport/blob/main/apps/web/middleware.ts): Next.js middleware · `apps/web/middleware.ts`
- [English & Chinese MDX](https://github.com/nicepkg/ctxport/blob/main/apps/web/content/en/_meta.ts): documentation content · `apps/web/content/en/_meta.ts`

### Automation

- [Website deployment](https://github.com/nicepkg/ctxport/blob/main/.github/workflows/deploy-website.yml): GitHub Actions · `.github/workflows/deploy-website.yml`
- [Extension release](https://github.com/nicepkg/ctxport/blob/main/.github/workflows/release-extension.yml): GitHub Actions · `.github/workflows/release-extension.yml`

## Connections

- WXT build config → Background runtime: builds
- WXT build config → Content runtime: builds
- WXT build config → Popup UI: builds
- Content runtime → Injected React app: mounts
- Injected React app → Copy conversation flow: copy actions
- Popup UI → Shared UI: uses
- Injected React app → Shared UI: uses
- Copy conversation flow → Plugin registry: selects adapter
- Plugin registry → Plugin contract: uses
- Plugin registry → Platform adapters: resolves
- Platform adapters → ChatGPT tree extraction: includes
- Platform adapters → GitHub GraphQL adapter: includes
- Platform adapters → Context Bundle schema: normalizes to
- Plugin contract → Context Bundle schema: defines output
- Copy conversation flow → Export formats: selects format
- Context Bundle schema → Markdown serializer: serializes
- Export formats → Markdown serializer: configures
- Markdown serializer → Copy conversation flow: Markdown to clipboard
- Locale middleware → Locale docs routes: routes locale
- English & Chinese MDX → Locale docs routes: renders in
- Website deployment → Locale docs routes: deploys
- Extension release → WXT build config: releases build
