How magicdawn/bilibili-gate works
• User Interface (UI) Layer – This includes the React components located under src/components (AppRoot, Modal components, VideoCard, Header, etc.) and styling (CSS/SCSS files). These components form the visible interface that users interact with.
– Access Key Management (including TV QR code auth)
– Bilibili-related utilities (bilibili data, player configuration, risk control)
– Recommendation and service modules (for “App 推荐”, dynamic feeds, favorites, live, watchlater, etc.)
– Settings and compatibility modules (adjustments for dark mode, integration with Bilibili-Evolved, etc.)
• Utility Layer – All the common helper functions (src/utility) for operations like async handling, cookies, DOM manipulations, API calls, and state management (using valtio—a state management library).
• Configuration and Build Tools – Files like vite.config.ts, tsconfig.json, knip.config.ts, and others. These reflect the build and code quality configuration, although they are not runtime components, they are key for development and toolchain integration.
Relationships and flows
• That configuration files and build scripts (Vite, turbo.json, etc.) support the entire development and build lifecycle, even if not executed at runtime.
Important architectural patterns or design principles
• Separation of concerns: The project clearly divides UI (src/components) from business logic (src/modules) and shared utilities (src/utility).
• Modular design: With specialized directories for each major feature (for different recommendation types, dynamic feeds, favorites, etc.), the architecture follows a modular design where each module is responsible for a specific set of functionalities.
• State management: The use of valtio for handling client state and hooks for lifecycle management in React (as seen in src/common/hooks) are important design choices.
• Compatibility and extensibility: Adapters for Bilibili-Evolved and dark mode compatibility are carefully integrated, indicating the design’s attention to interoperability.
Relevant technologies and frameworks
• React & TypeScript for the UI.
• Vite for bundling and building the project.
• pnpm as the package manager.
• CSS/SCSS for styling.
• State management using valtio.
• Third-party integrations like ant-design components, Dark Reader for dark mode, and compatibility layers for other userscripts.
• Clear labels for each component:
– UI Components (e.g., AppRoot, VideoCard, Header, various modals)
– Modules (e.g., rec-services, access-key, dark-mode, settings)
– Utility services (e.g., async operations, cookie management, API helpers)
– Communication between modules and shared utility functions.
– For utility services,
Overall advice
• Don’t over-complicate by including every minor file; instead, focus on the high-level architectural components that delineate the core functionalities.