# ithcc/beijing-hpv-node architecture

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

- Interactive diagram: https://gitdiagram.com/ithcc/beijing-hpv-node
- Repository: https://github.com/ithcc/beijing-hpv-node

## Overview

##### Project Type and Purpose
- This is a script-based application (written in Node.js) that automates components of vaccine booking. It isn’t a full-blown web application but a backend service that interacts with different booking channels.
- The README emphasizes its research/learning nature and describes multiple “渠道” (channels) for vaccine procurement, alongside configuration instructions for a specific platform (“大医苗小程序”). It also provides guidelines for starting the script using PM2.
- Overall, the purpose is straightforward: to automate or assist in vaccine booking, handling multiple platforms/sources.

##### File Structure
- At the top-level, you have standard Node.js files such as index.js (your main entry file), package.json, and configuration files (.npmrc, ecosystem.config.js).
- The config directory (with default.js) houses your global configuration settings.
- The data directory holds JSON data (dayimiao.json) which could be used for dynamic data, possibly for scheduling or settings.
- The lib directory contains reusable modules:
⁃ “device” subfolder with index.js and JSON files (mobile.json, pc.json) that likely store device-specific settings or emulation data.
⁃ logger.js for logging, and request.js for handling HTTP requests.
- The platforms folder defines platform-specific logic for interfacing with the booking systems (base.js for common functions; dayimiao.js for a specific channel).
- The utils folder holds utility functions (utils.js) that assist with miscellaneous tasks.

##### Additional Insights from the README
- The README describes various vaccine booking channels and distinct scenarios (dayimiao, etc.), reflecting that the script supports multiple platforms.
- It highlights instructions to set up and run the service using PM2, implying that the script is designed for continuous operation rather than one-off execution.
- There is an emphasis on parameter configuration (with note of using packet capture tools) indicating a degree of integration with external systems.

a. Main Application:
- Index.js: Acts as the entry point.
- Configuration from config/default.js, loaded during initialization.
b. Core Functional Modules (inside lib):
- Logger (lib/logger.js): Used for logging events or errors.
- Request (lib/request.js): Handles HTTP interactions with external vaccine booking services.
- Device Module (lib/device folder): Manages device profiles (mobile and PC emulation) to mimic human behavior.
c. Platform Abstraction Layer:
- Platforms Directory: Contains base implementations (platforms/base.js) and specific platform logic (platforms/dayimiao.js) to communicate with various booking channels.
d. Data and Utility Support:
- Data Files (data/dayimiao.json): Contains dynamic or configuration data used by the platforms.
- Utility Functions (utils/utils.js): Supports various non-domain-specific tasks.
e. Process Management:
- PM2 integration (ecosystem.config.js): Used to deploy and manage the script as a service.

##### Relationships and Interactions
- When the script starts (via index.js), it reads configurations from the config files and initializes the logger and request modules.
- It uses utility functions to format or prepare data before sending requests.
- Depending on the booking channel invoked, the application selects the appropriate platform from the platforms directory to handle the request logic.
- The device module provides the necessary emulated profiles (from mobile.json/pc.json) to mimic user attributes during HTTP requests.
- Results, logs, and errors are recorded using the logger and possibly forwarded to monitoring solutions managed by PM2.

##### Detailed Steps for the Principal Software Engineer
- Blocks for core libraries (logger, request, device) from the lib directory, showing them as helper modules utilized throughout the system.
- A data block that connects to the platform layer for dynamic configuration.
- An external block for PM2, indicating that it controls process management and monitoring.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Application Core
    subgraph "Application Core"
        A1["index.js"]:::core
        A2["Configuration (config/default.js)"]:::core
    end

    %% Core Modules
    subgraph "Core Modules"
        B1["Logger (lib/logger.js)"]:::lib
        B2["Request (lib/request.js)"]:::lib
        B3["Device Emulation (lib/device)"]:::lib
    end

    %% Platform Abstraction Layer
    subgraph "Platform Abstraction Layer"
        C1["Base Platform (platforms/base.js)"]:::platform
        C2["Dayimiao Platform (platforms/dayimiao.js)"]:::platform
    end

    %% Data and Utilities
    subgraph "Data & Utilities"
        D1["Data (data/dayimiao.json)"]:::data
        D2["Utilities (utils/utils.js)"]:::data
    end

    %% Process Management
    subgraph "Process Management"
        E1["PM2 Manager (ecosystem.config.js)"]:::pm2
    end

    %% Connections: Application Core Initialization
    A1 -->|"loads"| A2
    A1 -->|"initializes"| B1
    A1 -->|"initializes"| B2
    A1 -->|"sets-up"| B3
    A1 -->|"calls"| D2
    
    %% Connections: Platform Selection and Data Flow
    A1 -->|"selects"| C1
    A1 -->|"selects"| C2
    C2 -->|"uses"| D1

    %% Core Modules inter-dependencies (optional utility usage)
    B1 -->|"formats"| D2
    B2 -->|"formats"| D2

    %% PM2 Process Management
    E1 -->|"monitors"| A1

    %% Click Events
    click A1 "https://github.com/ithcc/beijing-hpv-node/blob/master/index.js"
    click A2 "https://github.com/ithcc/beijing-hpv-node/blob/master/config/default.js"
    click B1 "https://github.com/ithcc/beijing-hpv-node/blob/master/lib/logger.js"
    click B2 "https://github.com/ithcc/beijing-hpv-node/blob/master/lib/request.js"
    click B3 "https://github.com/ithcc/beijing-hpv-node/tree/master/lib/device"
    click C1 "https://github.com/ithcc/beijing-hpv-node/blob/master/platforms/base.js"
    click C2 "https://github.com/ithcc/beijing-hpv-node/blob/master/platforms/dayimiao.js"
    click D1 "https://github.com/ithcc/beijing-hpv-node/blob/master/data/dayimiao.json"
    click D2 "https://github.com/ithcc/beijing-hpv-node/blob/master/utils/utils.js"
    click E1 "https://github.com/ithcc/beijing-hpv-node/blob/master/ecosystem.config.js"

    %% Styles
    classDef core fill:#f9c,stroke:#333,stroke-width:2px;
    classDef lib fill:#9cf,stroke:#333,stroke-width:2px;
    classDef platform fill:#9f9,stroke:#333,stroke-width:2px;
    classDef data fill:#fc9,stroke:#333,stroke-width:2px;
    classDef pm2 fill:#f99,stroke:#333,stroke-width:2px;
```
