# jdnick27/x-bot architecture

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

- Interactive diagram: https://gitdiagram.com/jdnick27/x-bot
- Repository: https://github.com/jdnick27/x-bot

## Overview

##### Project type and purpose
- This is a small Node.js bot (an automation/tool) that periodically pulls Pokémon TCG card data from the Pokémon TCG API, downloads the card images, and posts them to an X (formerly Twitter) account.

##### File structure
- Top-level scripts:
- index.js – entry point, drives the workflow
- fetchPokemonData.js – handles API calls to the Pokémon TCG service
- twitterClient.js – wraps the X API posting logic
- utilities.js – helper functions (e.g., parsing, file operations)
- fetchPokemonData.js & twitterClient.js both rely on environment variables (.env)
- Configuration/data files:
- pokemon_card_sets.txt – list of set IDs to fetch
- package.json / package-lock.json – dependencies (axios, node-fs, dotenv, twitter-api-v2, etc.)
- Artifacts/storage:
- images/ – local folder where card images are saved
- banner.png, profilepic.jpg – static assets for the X profile

##### README for additional insights
- Workflow:
1. Read set IDs from pokemon_card_sets.txt
2. Call Pokémon TCG API → retrieve card metadata (including image URL)
3. Download the card image to images/
4. Post the image + caption to X via twitterClient.js
- Configuration: environment variables for both APIs stored in .env

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Internal Modules"
        direction TB
        IDX["Scheduler / Entry Point (index.js)"]:::internal
        FETCH["Pokémon TCG Fetcher (fetchPokemonData.js)"]:::internal
        PARSE["Parser & Downloader (utilities.js)"]:::internal
        TWITTER["X/Twitter Client (twitterClient.js)"]:::internal
    end

    subgraph "Local Storage"
        direction TB
        SETS["Set IDs List (pokemon_card_sets.txt)"]:::storage
        IMAGES["Images Folder"]:::storage
    end

    CONFIG["Configuration (.env) & Dependencies (package.json)"]:::config
    DOC["Documentation (README.md)"]:::doc
    PTCG["Pokémon TCG API"]:::external
    XAPI["X API"]:::external

    IDX -->|"Reads set IDs"| SETS
    IDX -->|"Invokes fetcher"| FETCH
    FETCH -->|"Fetch metadata"| PTCG
    PTCG -->|"Card metadata JSON"| FETCH
    FETCH -->|"Pass metadata"| PARSE
    PARSE -->|"Downloads image"| IMAGES
    PARSE -->|"Image path & caption"| TWITTER
    TWITTER -->|"Post Tweet"| XAPI

    CONFIG -->|".env variables"| IDX
    CONFIG -->|".env variables"| FETCH
    CONFIG -->|".env variables"| TWITTER

    DOC -.-> IDX

    click IDX "https://github.com/jdnick27/x-bot/blob/main/index.js"
    click FETCH "https://github.com/jdnick27/x-bot/blob/main/fetchPokemonData.js"
    click PARSE "https://github.com/jdnick27/x-bot/blob/main/utilities.js"
    click TWITTER "https://github.com/jdnick27/x-bot/blob/main/twitterClient.js"
    click SETS "https://github.com/jdnick27/x-bot/blob/main/pokemon_card_sets.txt"
    click CONFIG "https://github.com/jdnick27/x-bot/blob/main/package.json"
    click DOC "https://github.com/jdnick27/x-bot/blob/main/README.md"

    classDef internal fill:#cce5ff,stroke:#0066cc,stroke-width:1px
    classDef storage fill:#d4edda,stroke:#28a745,stroke-width:1px
    classDef config fill:#e2e3e5,stroke:#6c757d,stroke-width:1px
    classDef external fill:#ffe5b4,stroke:#ff8000,stroke-width:1px
    classDef doc fill:#f8d7da,stroke:#721c24,stroke-width:1px
```
