# cyy25121/auto-buy architecture

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

- Interactive diagram: https://gitdiagram.com/cyy25121/auto-buy
- Repository: https://github.com/cyy25121/auto-buy

## Overview

##### Project type and purpose
- This is a command-line automation tool (“AUTO BUY”) written in Python that uses Playwright to drive headless (or headed) browsers and automatically purchase items on multiple e-commerce platforms (MOMO, PC Home).
- It’s not a web front-end or a microservice: it’s a local CLI application with platform-specific modules and a core orchestration layer.

##### File structure
- Top-level files
- main.py – the CLI entrypoint (parses arguments, loads config, kicks off a purchase job)
- .env.example – template for environment variables (credentials, headless flag defaults)
- requirements.txt – Python dependencies (playwright, python-dotenv, pytest, etc.)
- README.md – project overview and usage
- buyer/ package
- base.py – defines the BaseBuyer abstract class and factory logic (Strategy/Factory pattern)
- momo.py – MomoBuyer implementation (login flow, add-to-cart, checkout selectors)
- pchome.py – PChomeBuyer implementation
- utils.py – helper routines (e.g. load .env, timestamp parsing, common error handling)
- tests/ – pytest fixtures and unit tests for BaseBuyer and other logic

##### README for additional insights
- Confirms use cases (CLI invocation, scheduling purchase, headless/headed browser)
- Emphasizes external dependencies (Playwright, network stability, anti-bot considerations)

##### Diagramming recommendations
- External entities “MOMO Website”, “PC Home Website” (grey clouds)
CLI → Config Loader → Factory → Buyer → Playwright → External Website
- Denote the Factory/Strategy boundary clearly so it’s obvious where new platforms plug in

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLI Layer
    CLI["CLI Layer<br/>main.py"]:::cli

    %% Core Layer
    CONFIG["Configuration Loader<br/>utils.py"]:::core
    FACTORY["Buyer Factory/Orchestrator<br/>buyer/base.py"]:::core

    %% Buyer Modules
    subgraph "Platform Adapters"
        MOMO["MomoBuyer<br/>buyer/momo.py"]:::buyer
        PCHOME["PChomeBuyer<br/>buyer/pchome.py"]:::buyer
    end

    %% Automation Engine
    ENGINE["Playwright Engine"]:::engine

    %% External Systems
    EXT1["MOMO Website"]:::external
    EXT2["PC Home Website"]:::external

    %% Documentation & Config
    README["README.md"]:::docs
    ENV[".env.example"]:::docs
    REQ["requirements.txt"]:::docs
    TESTS["Testing Harness<br/>tests/"]:::docs

    %% Flow
    CLI -->|"parse args & invoke"| CONFIG
    CONFIG -->|"load .env & creds"| FACTORY
    FACTORY -->|"select platform"| MOMO
    FACTORY -->|"select platform"| PCHOME
    MOMO -->|"launch browser"| ENGINE
    PCHOME -->|"launch browser"| ENGINE
    ENGINE -->|"automate flows"| EXT1
    ENGINE -->|"automate flows"| EXT2
    TESTS -->|"validate BaseBuyer & modules"| FACTORY
    TESTS --> FACTORY
    TESTS --> MOMO
    TESTS --> PCHOME

    %% Click Events
    click CLI "https://github.com/cyy25121/auto-buy/blob/main/main.py"
    click CONFIG "https://github.com/cyy25121/auto-buy/blob/main/utils.py"
    click FACTORY "https://github.com/cyy25121/auto-buy/blob/main/buyer/base.py"
    click MOMO "https://github.com/cyy25121/auto-buy/blob/main/buyer/momo.py"
    click PCHOME "https://github.com/cyy25121/auto-buy/blob/main/buyer/pchome.py"
    click TESTS "https://github.com/cyy25121/auto-buy/tree/main/tests/"
    click REQ "https://github.com/cyy25121/auto-buy/blob/main/requirements.txt"
    click ENV "https://github.com/cyy25121/auto-buy/blob/main/.env.example"
    click README "https://github.com/cyy25121/auto-buy/blob/main/README.md"

    %% Styles
    classDef cli fill:#a6e22e,stroke:#333,stroke-width:1px
    classDef core fill:#66d9ef,stroke:#333,stroke-width:1px
    classDef buyer fill:#9cdcfe,stroke:#333,stroke-width:1px
    classDef engine fill:#fd971f,stroke:#333,stroke-width:1px
    classDef external fill:#75715e,stroke:#333,stroke-width:1px
    classDef docs fill:#f92672,stroke:#333,stroke-width:1px
```
