# vmoranv/astrbot_plugin_pixiv_search architecture

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

- Interactive diagram: https://gitdiagram.com/vmoranv/astrbot_plugin_pixiv_search
- Repository: https://github.com/vmoranv/astrbot_plugin_pixiv_search

## Overview

##### Project type and purpose
- This is an **AstrBot plugin** ("AstrBot Pixiv 搜索插件"). It is an _extension_ to the AstrBot chatbot framework. Its sole purpose is to parse Pixiv‑related commands from users, call the Pixiv API (via `pixivpy3` and `aiohttp`), and return image results or metadata back through AstrBot into a chat platform.

##### File structure
- Top‑level files only:
- `main.py` – the plugin’s entry point (command definitions, API calls, response formatting)
- `metadata.yaml` – plugin metadata (name, version, hooks) used by AstrBot’s plugin manager
- `_conf_schema.json` – configuration schema for AstrBot’s WebUI (defines refresh_token, R18 mode, quantity, etc.)
- `requirements.txt` – external Python dependencies (`pixivpy3`, `aiohttp`)
- `README.md`, `LICENSE` – documentation
- No frontend, no database, no persistent storage.
- This is a **single-process**, **plugin-based** architecture where AstrBot loads and isolates each plugin.

##### README for additional insights
- The README outlines user‑facing commands (e.g. `/pixiv`, `/pixiv_ranking`, `/pixiv_related`), configuration options, setup steps.
- It notes that AstrBot handles plugin discovery, dependency installation, configuration UI, and command routing.

##### Main components & interactions
a. Components
- User (chat client: QQ/Telegram/WeChat)
- Chat Platform API (e.g., Telegram API)
- AstrBot Core
- Plugin Manager
- Configuration Store (WebUI + `_conf_schema.json`)
- Command Router
- Pixiv Plugin
- `main.py` (command handlers + business logic)
- `metadata.yaml` (registration)
- `_conf_schema.json` (configuration schema)
- Python runtime with dependencies (`pixivpy3`, `aiohttp`)
- External Pixiv API
- (Optional) HTTP Proxy (if configured)
b. Relationships & data flow
1. User sends `/pixiv tag1,tag2` in chat
2. Chat Platform forwards message to AstrBot Core
3. AstrBot Core’s Command Router inspects `metadata.yaml`, dispatches to Pixiv Plugin
4. Plugin’s `main.py` reads user arguments + loads plugin-specific configuration (refresh_token, R18 mode) from AstrBot Configuration Store
5. Plugin makes HTTP calls to the Pixiv API (via `pixivpy3` + `aiohttp`), optionally through a proxy
6. Pixiv API returns JSON data (illustration URLs, titles, tags)
7. Plugin formats results (images + caption) and returns to AstrBot Core
8. AstrBot sends formatted message/images back through Chat Platform API to the user
c. Architectural patterns & principles
- **Plugin architecture**: loosely‑coupled components loaded at runtime
- **Configuration‑driven behavior**: via `_conf_schema.json` and AstrBot’s WebUI
- **Single responsibility**: plugin only handles Pixiv commands; AstrBot handles messaging, plugin isolation, dependency management
d. Key technologies & libraries
- Python 3.10+
- AstrBot plugin framework (core)
- pixivpy3 (Pixiv API wrapper)
- aiohttp (async HTTP client)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Chat Layer
    subgraph "Chat Layer"
        User["User"]:::external
        ChatAPI["Chat Platform API"]:::external
    end

    %% Bot Layer
    subgraph "Bot Layer"
        subgraph "AstrBot Core"
            PM["Plugin Manager"]:::core
            CR["Command Router"]:::core
            CS[(Configuration Store)]:::config
        end
        subgraph "Pixiv Plugin"
            MP["main.py"]:::plugin
            MD["metadata.yaml"]:::plugin
            SC["_conf_schema.json"]:::plugin
            RE["requirements.txt"]:::plugin
            RD["README.md"]:::plugin
            LI["LICENSE"]:::plugin
        end
    end

    %% External Service Layer
    subgraph "External Service Layer"
        Proxy["HTTP Proxy"]:::external
        PixivAPI["Pixiv API"]:::external
    end

    %% Data Flows
    User -->|"/pixiv command"| ChatAPI
    ChatAPI -->|"forward message"| CR
    CR -->|"dispatch to plugin"| PM
    PM -->|"loads metadata"| MD
    PM -->|"invokes handler"| MP
    MP -->|"reads config"| CS
    MP -->|"loads schema"| SC
    MP -->|"uses dependencies"| RE
    MP -->|"HTTP Request"| Proxy
    Proxy -->|"forward to Pixiv"| PixivAPI
    PixivAPI -->|"JSON data"| Proxy
    Proxy -->|"returns data"| MP
    MP -->|"formats response"| CR
    CR -->|"send message"| ChatAPI
    ChatAPI -->|"deliver to user"| User

    %% Click Events
    click MP "https://github.com/vmoranv/astrbot_plugin_pixiv_search/blob/master/main.py"
    click MD "https://github.com/vmoranv/astrbot_plugin_pixiv_search/blob/master/metadata.yaml"
    click SC "https://github.com/vmoranv/astrbot_plugin_pixiv_search/blob/master/_conf_schema.json"
    click RE "https://github.com/vmoranv/astrbot_plugin_pixiv_search/blob/master/requirements.txt"
    click RD "https://github.com/vmoranv/astrbot_plugin_pixiv_search/blob/master/README.md"
    click LI "https://github.com/vmoranv/astrbot_plugin_pixiv_search/tree/master/LICENSE"

    %% Styles
    classDef external fill:#D0E8FF,stroke:#004EC6,color:#004EC6
    classDef core fill:#DFFFE0,stroke:#008000,color:#006400
    classDef plugin fill:#FFFACD,stroke:#FFD700,color:#B8860B
    classDef config fill:#E0FFF0,stroke:#00A050,color:#007F3D
```
