How smallzombie/bilibili-favorite-sync works
Main components
• CLI Interface: Represented by files such as index.js, CLI.js, and the command subdirectory (with multiple CommandNode files such as HelpCommandNode.js, StartCommandNode.js, StopCommandNode.js, etc.). This is the entry point and command interpreter.
• Main Controller: Main.js acts as the core component that likely manages overall workflow and coordination of sync tasks.
• Push Service: PushService.js is responsible for handling notifications (for example, video expiration notices).
• Command Management: In the “src/command” folder, CommandManager.js coordinates various command nodes, each implementing specific commands like start, pause, reload, and library management (blacklist, whitelist, export, clean, etc).
• Configuration Module: The “src/config/Global.js” manages global settings for the synchronization process.
• Utility Modules: Under “src/util” there are multiple utility classes (BaseUtil, BiliUtil, DownloadUtil, LibraryUtil, Logger, RequestUtil) – these help with logging, communication with Bilibili API, downloading content, handling files, and more.
Relationships and interactions
• The CLI Interface receives user commands and passes them to the Command Manager.
• The Command Manager, by interpreting the command nodes, triggers operations in the Main Controller.
• The Main Controller coordinates workflow and can call into the Push Service to send notifications.
• Utility modules wrap around common tasks (logging, downloading, HTTP requests, etc.) that may be utilized by both the Main Controller and individual command nodes.
• The Global configuration module ensures consistent settings are applied across various operations.
• Additionally, the tool interacts with the local library structure (as described in the README under the library section) to read/write JSON files, manage directories for favorites, videos, recycled files, etc.
Important architectural patterns and principles
• Modular design: The separation of concerns is evident – the CLI, command parsing, synchronization logic, utility functions, and configuration are each contained in dedicated modules.
• Command Pattern: With multiple command nodes and a Command Manager, the project likely employs the Command design pattern to process different user actions.
• Layered Architecture: The tool is organized into layers where the CLI layer handles input, a business logic layer (Main and PushService) processes operations, and a utility layer handles ancillary tasks.
Technologies, frameworks, and libraries
• Node.js is the main runtime environment (as seen with index.js and package.json).
• Various custom utilities (e.g., for networking and downloads) portray the lightweight and specific use of libraries or in-house solutions rather than major frameworks.
• The README suggests timing and retry logic, implying careful handling of external HTTP requests and API rate limiting.
Detail
• Every major file grouping (CLI, Command Management, Utility, Core Sync, Config) is represented.
Happy diagramming!