# douweb010/multipost-extension architecture

> Architecture diagram of the GitHub repository douweb010/multipost-extension, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/douweb010/multipost-extension
- Repository: https://github.com/douweb010/multipost-extension

## Overview

##### Project type and purpose
- This is a browser extension (Chrome/Edge) built in TypeScript + React.
- Purpose: allow users to publish or synchronize content (text, images, videos) from any web page to multiple social media platforms with one click.

##### File structure
- Top-level configuration and CI/CD
- package.json, pnpm-lock.yaml, tsconfig.json, build scripts (makefile)
- .github/workflows for automated releases and issue management
- Husky, ESLint, Prettier, Stylelint for code quality
- src folder organized by “execution context”:
- background/ – MV3 service worker entry point and platform-agnostic services (tabs.ts, trust-domain.ts)
- contents/ – injected content script (extension.ts) plus helpers and scrapers for each target site
- popup/, options/, sidepanel/ – React UIs served in different extension panels
- components/ – shared React components (Header, Sidepanel Tabs, Sync tabs)
- sync/ – core business logic for “account,” “article,” “dynamic,” “video” synchronization; each platform has its own implementation under corresponding subfolder
- tabs/, utils/, types/ – utility modules, type definitions, keep-alive functions
- Localization: locales/{en,zh_CN}/messages.json
- Styling: tailwind.config.js, postcss.config.js, src/style.css

##### README for additional insights
- Confirms it’s a content-publishing extension with no backend/API keys.
- Mentions modular registration of platforms in sync/common.ts.
- Uses Plasmo or standard Chrome MV3 APIs.

a. Main components
- UI Layer
- Popup UI
- Options page
- Sidepanel UI (Sync tabs: About, Settings, Article, Video, Dynamic)
- Content Script Layer
- Scraper modules for each site (csdn, zhihu, jianshu, etc.)
- Helper modules (bilibili, weibo, common)
- Background Service Worker
- Chrome API services (tabs management, trust-domain checks)
- Message broker for UI ↔ content ↔ sync
- Sync Engine
- Registry (sync/common.ts)
- Account sync (bilibili, tiktok, etc.)
- Article sync (weixin, zhihu, jiangjin, etc.)
- Dynamic sync (social feeds)
- Video sync (youtube, douyin, etc.)
- External Systems
- Social platform HTTP APIs
- OAuth or no-auth endpoints (depending on platform)

b. Relationships and data flows
2. User selects action (publish now, schedule) → Popup sends message to background via chrome.runtime.sendMessage
3. Background checks trust-domain, obtains current tab info → dispatches “scrape request” to content script on that tab
4. Content script executes scraper pipeline → returns structured content to background
5. Background invokes Sync Engine modules (account/auth, article/video/dynamic)
6. Each sync module formats payload and performs HTTP calls to platform endpoints
7. Success/failure responses bubble back through background → UI displays status

c. Architectural patterns and design principles
- MV3 Event-Driven: background service worker reacts to messages and Chrome events
- Modular Plugin Architecture: each platform is a pluggable module under sync/ or contents/helper/
- Single Responsibility: clear separation between UI (React), orchestration (background), scraping (content), and publishing (sync modules)
- Registry Pattern: sync/common.ts auto-registers all platform modules

d. Key technologies
- TypeScript for type safety
- React + TSX for UI panels
- Tailwind CSS / PostCSS for styling
- Chrome Extension MV3 APIs
- pnpm, Husky, ESLint, Prettier, GitHub Actions for development workflow

##### Final reminders
- Essential pieces: UI panels, Chrome APIs, message bus, scrapers, sync modules, external platforms
- You don’t need to show every single platform file; group them logically (e.g., “Article Sync Modules: {zhihu, jianshu, …}”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Context
    subgraph "UI Context"
        POPUP["Popup UI"]:::ui
        OPTIONS["Options Page"]:::ui
        SIDEPANEL["Sidepanel UI"]:::ui
        Header["Header"]:::ui
        TabsManager["Sidepanel Tabs Manager"]:::ui
        SyncTabs["Sync Tabs"]:::ui
        POPUP -->|renders using| Header
        POPUP -->|renders using| TabsManager
        POPUP -->|renders using| SyncTabs
        OPTIONS -->|renders using| Header
        OPTIONS -->|renders using| TabsManager
        OPTIONS -->|renders using| SyncTabs
        SIDEPANEL -->|renders using| Header
        SIDEPANEL -->|renders using| TabsManager
        SIDEPANEL -->|renders using| SyncTabs
    end

    %% Content Script Context
    subgraph "Content Script Context"
        EXTENSION["Content Entry"]:::content
        GeneralHelper["General Helpers"]:::content
        PlatformHelpers["Platform Helpers"]:::content
        MainScraper["Main Scraper"]:::content
        SiteScrapers["Site-Specific Scrapers"]:::content
        EXTENSION -->|uses| GeneralHelper
        EXTENSION -->|uses| PlatformHelpers
        EXTENSION -->|orchestrates| MainScraper
        MainScraper -->|calls| SiteScrapers
    end

    %% Background Service Worker
    subgraph "Background Service Worker"
        BG["Background Entry"]:::background
        SERVICES_TABS["Tabs Service"]:::service
        SERVICES_TRUST["Trust-Domain Service"]:::service
        BG -->|manages| SERVICES_TABS
        BG -->|checks| SERVICES_TRUST
    end

    %% Sync Engine
    subgraph "Sync Engine"
        REG["Registry"]:::sync

        subgraph "Account Sync"
            ACCOUNT_CORE["Account Core"]:::sync
            ACCOUNT_IMPL["Account Modules"]:::sync
            ACCOUNT_CORE --> ACCOUNT_IMPL
        end

        subgraph "Article Sync"
            ARTICLE_CORE["Article Core"]:::sync
            ARTICLE_IMPL["Article Modules"]:::sync
            ARTICLE_CORE --> ARTICLE_IMPL
        end

        subgraph "Dynamic Sync"
            DYN_CORE["Dynamic Core"]:::sync
            DYN_IMPL["Dynamic Modules"]:::sync
            DYN_CORE --> DYN_IMPL
        end

        subgraph "Video Sync"
            VIDEO_CORE["Video Core"]:::sync
            VIDEO_IMPL["Video Modules"]:::sync
            VIDEO_CORE --> VIDEO_IMPL
        end

        REG -->|registers| ACCOUNT_CORE
        REG -->|registers| ARTICLE_CORE
        REG -->|registers| DYN_CORE
        REG -->|registers| VIDEO_CORE
    end

    %% External Platforms
    subgraph "External Platforms"
        EXT_API["Social Platform APIs"]:::external
    end

    %% Message and Data Flows
    POPUP -->|"sendMessage('ACTION')"| BG
    OPTIONS -->|"sendMessage('OPTIONS')"| BG
    SIDEPANEL -->|"sendMessage('SYNC')"| BG
    BG -->|"chrome.tabs.sendMessage('SCRAPE')"| EXTENSION
    EXTENSION -->|"scraped data"| BG
    BG -->|"invoke sync"| REG
    ACCOUNT_IMPL -->|"HTTP POST /publish"| EXT_API
    ARTICLE_IMPL -->|"HTTP POST /publish"| EXT_API
    DYN_IMPL -->|"HTTP POST /publish"| EXT_API
    VIDEO_IMPL -->|"HTTP POST /publish"| EXT_API
    EXT_API -->|"response"| BG
    BG -->|"sendMessage('STATUS')"| POPUP
    BG -->|"sendMessage('STATUS')"| SIDEPANEL

    %% Click Events
    click POPUP "https://github.com/douweb010/multipost-extension/blob/main/src/popup/index.tsx"
    click OPTIONS "https://github.com/douweb010/multipost-extension/blob/main/src/options/index.tsx"
    click SIDEPANEL "https://github.com/douweb010/multipost-extension/blob/main/src/sidepanel/index.tsx"
    click Header "https://github.com/douweb010/multipost-extension/blob/main/src/components/Header.tsx"
    click TabsManager "https://github.com/douweb010/multipost-extension/blob/main/src/components/Sidepanel/Tabs/TabsManager.tsx"
    click SyncTabs "https://github.com/douweb010/multipost-extension/tree/main/src/components/Sync"
    click EXTENSION "https://github.com/douweb010/multipost-extension/blob/main/src/contents/extension.ts"
    click GeneralHelper "https://github.com/douweb010/multipost-extension/blob/main/src/contents/helper.ts"
    click PlatformHelpers "https://github.com/douweb010/multipost-extension/tree/main/src/contents/helper"
    click MainScraper "https://github.com/douweb010/multipost-extension/blob/main/src/contents/scraper.ts"
    click SiteScrapers "https://github.com/douweb010/multipost-extension/tree/main/src/contents/scraper"
    click BG "https://github.com/douweb010/multipost-extension/blob/main/src/background/index.ts"
    click SERVICES_TABS "https://github.com/douweb010/multipost-extension/blob/main/src/background/services/tabs.ts"
    click SERVICES_TRUST "https://github.com/douweb010/multipost-extension/blob/main/src/background/services/trust-domain.ts"
    click REG "https://github.com/douweb010/multipost-extension/blob/main/src/sync/common.ts"
    click ACCOUNT_CORE "https://github.com/douweb010/multipost-extension/blob/main/src/sync/account.ts"
    click ACCOUNT_IMPL "https://github.com/douweb010/multipost-extension/tree/main/src/sync/account"
    click ARTICLE_CORE "https://github.com/douweb010/multipost-extension/blob/main/src/sync/article.ts"
    click ARTICLE_IMPL "https://github.com/douweb010/multipost-extension/tree/main/src/sync/article"
    click DYN_CORE "https://github.com/douweb010/multipost-extension/blob/main/src/sync/dynamic.ts"
    click DYN_IMPL "https://github.com/douweb010/multipost-extension/tree/main/src/sync/dynamic"
    click VIDEO_CORE "https://github.com/douweb010/multipost-extension/blob/main/src/sync/video.ts"
    click VIDEO_IMPL "https://github.com/douweb010/multipost-extension/tree/main/src/sync/video"

    %% Styles
    classDef ui fill:#f9f,stroke:#333,stroke-width:1px
    classDef content fill:#afa,stroke:#333,stroke-width:1px
    classDef background fill:#aaf,stroke:#333,stroke-width:1px
    classDef service fill:#ccf,stroke:#333,stroke-width:1px
    classDef sync fill:#ffc,stroke:#333,stroke-width:1px
    classDef external fill:#fcf,stroke:#333,stroke-width:1px
```
