How eltonchou/twittermediaharvest works
Main Components
• Extension UI:
• Popup, options page, and other UI components (found in src/pages and its subdirectories).
• That these components use React (files like Options.tsx, Popup.tsx) and incorporate common UI components such as side menus and controls.
• Content Script:
• Content_script module which directly interacts with Twitter’s UI.
• Various observer modules (e.g., TweetDeckBetaObserver, TwitterMediaObserver) and core functionality (the Harvester classes) that scan the page, detect media elements, and relay commands to the backend parts.
• Backend/Logic:
• “src/backend” folder components. Break these into sub-components:
▪ Client modules, commands, and repositories (for cookie, credentials, and downloads).
▪ Downloads subsystem: modules and use cases (downloading media files, progress tracking, recording download history).
▪ Settings/Configuration: modules for download settings, filename settings, and Twitter API settings.
▪ Notifications: modules for generating and handling notifications.
▪ API integrations: twitterApi modules for interfacing with Twitter’s endpoints.
• Showing data flows such as:
▪ content_script → backend commands/useCases (for download actions)
▪ backend interactions with local storage and IndexedDB (via repositories).
• Service Workers:
• Their role in communicating between the extension’s UI/content scripts and the backend.
• Libraries and Utilities:
• Core support modules from src/libs (for browser API interactions, IndexedDB management, and proxy support).
• Shared utilities in both backend and content script layers (like data checkers and i18n functions).
• Localization:
• _locales directory as a support layer for internationalization – ensuring the UI and notifications correctly reflect multiple languages (en, ja, zh).
Relationships and Interactions
• Data Flow:
• Interaction between the Extension UI and the backend (via state management and React stores in src/pages/stores) for user-initiated actions such as triggering a download or modifying settings.
• Service workers as intermediaries that listen to events (e.g., browser messages, API callbacks) and trigger subsequent backend operations.
• Dependencies:
• Dependencies where backend functionalities rely on third-party APIs (e.g., Twitter API integration in twitterApi/useCases).
• Build and configuration components (webpack.config.js, babel.config.js, tsconfig.json) as peripheral elements that inform deployment but aren’t part of the runtime architecture.
Architectural Patterns
• Separation of Concerns:
• Clearly separate the presentation layer (UI), content scripts (browser interactions), backend logic, and background/service worker responsibilities.
• Modular Design:
• Use of Repositories and UseCases:
• Backend components follow a pattern where repositories handle low-level data persistence (e.g., IndexedDB for download histories) and use case modules encapsulate business logic. Represent these interactions explicitly between “Repositories” and “Use Cases.”
Final Checklist for the Principal Software Engineer
• Adding notes on key technologies (React for UI, TypeScript for module development, browser-specific APIs in service workers, etc.) to provide additional context.