# jumpingchu/pchome-autobuy architecture

> Architecture diagram of the GitHub repository jumpingchu/pchome-autobuy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jumpingchu/pchome-autobuy
- Repository: https://github.com/jumpingchu/pchome-autobuy

## Overview

##### Project type and purpose
- This is an open-source Python automation tool (“PChome-AutoBuy”) that uses Selenium and the requests library to programmatically purchase items on the PChome e-commerce site.
- It’s not a full-stack application but rather a script-driven, single-purpose bot with configuration, a sequential workflow, and external system dependencies.

##### File structure
- Top-level files:
– pchome_autobuy.py – the main orchestration script
– settings.py – configuration constants (credentials, driver paths, retry counts)
– requirements.txt – third-party dependencies (selenium, requests, etc.)
– images/ – screenshots used in documentation
- No separate modules or packages – all logic lives in one script.
- External dependency: ChromeDriver binary launched by Selenium.

##### README for additional insights
- The README describes a linear workflow: check item availability → add to cart → login → select payment → fill in personal/credit-card details → submit order.
- It points out configuration of CHROME_PATH/DRIVER_PATH and optional session persistence in Chrome.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Project Files
    subgraph "Project Files"
        direction TB
        Config["settings.py"]:::internal
        Orchestrator["pchome_autobuy.py"]:::internal
        Requirements["requirements.txt"]:::docs
        Readme["README.md"]:::docs
        Images["images/"]:::docs
    end

    %% Local Environment
    subgraph "Local Environment"
        direction TB
        Python["Python 3.x Runtime"]:::internal
        Network["Network Connectivity"]:::internal
    end

    %% Core Components
    subgraph "Core Workflow"
        direction TB
        HTTPClient["requests Library"]:::internal
        Selenium["Selenium WebDriver"]:::internal
        ChromeDriver["ChromeDriver"]:::externalBinary
        Chrome["Chrome Browser"]:::externalBinary
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        PChomeAPI["PChome API"]:::externalSystem
        PChomeSite["PChome Website"]:::externalSystem
    end

    %% Relationships
    Orchestrator -->|"loads config"| Config
    Orchestrator -->|"dependency list"| Requirements
    Orchestrator -->|"documentation reference"| Readme
    Orchestrator --> Python
    Orchestrator --> Network

    Orchestrator -->|"poll availability"| HTTPClient
    HTTPClient -->|"GET /item/status"| PChomeAPI
    PChomeAPI -->|"status response"| HTTPClient
    HTTPClient -->|"return status"| Orchestrator

    Orchestrator -->|"launch browser"| Selenium
    Selenium -->|"start process"| ChromeDriver
    ChromeDriver -->|"opens"| Chrome
    Chrome -->|"renders pages"| PChomeSite
    PChomeSite -->|"DOM/events"| Chrome

    Chrome -->|"user actions via Selenium"| Selenium
    Selenium -->|"action results"| Orchestrator

    %% Retry Loop Annotation
    Orchestrator -.->|"if out of stock retry up to config.max_retries"| HTTPClient

    %% Click Events
    click Config "https://github.com/jumpingchu/pchome-autobuy/blob/master/settings.py"
    click Orchestrator "https://github.com/jumpingchu/pchome-autobuy/blob/master/pchome_autobuy.py"
    click Requirements "https://github.com/jumpingchu/pchome-autobuy/blob/master/requirements.txt"
    click Readme "https://github.com/jumpingchu/pchome-autobuy/blob/master/README.md"
    click Images "https://github.com/jumpingchu/pchome-autobuy/tree/master/images/"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef externalBinary fill:#90EE90,stroke:#333,stroke-width:1px
    classDef externalSystem fill:#FFA500,stroke:#333,stroke-width:1px
    classDef docs fill:#D3D3D3,stroke:#333,stroke-width:1px
```
