# y-exe/sugiyama-bot architecture

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

- Interactive diagram: https://gitdiagram.com/y-exe/sugiyama-bot
- Repository: https://github.com/y-exe/sugiyama-bot

## Overview

##### Project Type and Purpose
- This is a Python-based Discord Bot (“杉山啓太Bot”) that runs as a single deployable application.
- Purpose: provide miscellaneous utility and entertainment commands (chat summarization, voice conversion via RVC/VoiceVox, image generation, watermarking, games, weather, currency conversion, URL shortening, etc.) within Discord servers.

##### File Structure Analysis
- Top level:
- main.py – entry point and command dispatcher
- requirements.txt – Python dependencies (discord.py, python-dotenv, pillow, aiohttp, numpy, pydub, google-generativeai, etc.)
- assets/
– fonts/ (MochiyPopOne-Regular.ttf, NotoSerifJP-Bold.otf)
– watermark_templates/ (PNG templates)
- Runtime-generated files (described in README, not in repo):
- .env – environment variables (API keys)
- bot_settings.json, game_points.json, weather_city_codes.json
- audio/ (input/output temp folders)
- RVC_Project/ (external voice-conversion submodule via git clone)

##### Key Insights from README
- Bot uses discord.py v2.x and Python 3.10
- Interacts with multiple external services/APIs:
- Discord Gateway (command and event stream)
- Google Gemini API (AI summarization, weather city ID inference)
- VoiceVox API (text-to-speech)
- RVC CLI (local inference for voice conversion)
- Pillow (image/font rendering)
- Various third-party web APIs (weather.tsukumijima, x.gd, currency exchange, 5000兆円 image generator)

a. Main Components
- Discord Gateway (WebSocket + REST)
- Bot Application (main.py)
– Command Processor (dispatches slash and prefix-free commands)
– Feature Modules:
· AI Summarizer
· Voice Conversion (VoiceVox + RVC CLI)
· Image/Text Generation (Pillow, watermark fusion)
· Games Engine (othello, janken, dice)
· Utility Clients (weather, rate, shorturl)
– File Manager (reads/writes JSON state files, loads assets/fonts, temp audio files)
- External Services:
– Google Gemini API
– VoiceVox API
– RVC CLI (local subprocess)
– Third-party Web APIs
- File System / Data Store:
– assets/, fonts/, watermark_templates/, audio/
– JSON files for settings, points, cache

b. Relationships and Data Flow
- Discord Gateway → Bot Application: receives events (messages, slash commands)
- Bot Application → Discord REST API: sends responses (text, embeds, files)
- Bot Application → External API clients: HTTP requests to Gemini, VoiceVox, weather, rate, shorturl, 5000choyen
- Bot Application → RVC CLI: subprocess call for voice conversion
- Bot Application → File System: load fonts/assets, read/write JSON, write temp audio
- Bot Application ↔ Users: command issuance and bot responses via Discord

c. Architectural Patterns & Principles
- Single-process monolith structured in modules
- Separation of concerns: one handler per feature
- Externalize configuration via .env and JSON files
- Use of asynchronous I/O (aiohttp, discord.py async)
- Pluggable asset pipeline (fonts, templates loaded at runtime)

d. Key Technologies/Frameworks
- Python 3.10, discord.py v2.x
- python-dotenv
- Pillow for image generation
- aiohttp for HTTP clients
- numpy, pydub for audio processing
- subprocess + local RVC CLI for voice conversion
- Google-generativeai client

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Entrypoint
    DiscordGateway["Discord Gateway\n(WebSocket)"]:::external
    DiscordREST["Discord REST API"]:::external

    %% Bot Application Core
    BotApp["Bot Application"]:::core
    click BotApp "https://github.com/y-exe/sugiyama-bot/blob/main/main.py"

    %% Bot Modules
    subgraph "Bot Application Modules"
        direction TB
        CommandProc["Command Processor"]:::core
        AISummarizer["AI Summarizer Module"]:::core
        VoiceConvModule["Voice Conversion Module\n(VoiceVox + RVC)"]:::core
        ImageModule["Image/Text Generation Module"]:::core
        GamesEngine["Games Engine Module"]:::core
        UtilityClients["Utility Clients Module"]:::core
        FileManager["File Manager"]:::core
    end

    %% File System & Data Store
    subgraph "File System & Data" 
        direction TB
        Fonts["Fonts Directory"]:::fs
        click Fonts "https://github.com/y-exe/sugiyama-bot/tree/main/assets/fonts"
        Watermarks["Watermark Templates"]:::fs
        click Watermarks "https://github.com/y-exe/sugiyama-bot/tree/main/assets/watermark_templates"
        JSONStore[(JSON State Files)]:::fs
        AudioTemp[(Audio Temp Folders)]:::fs
    end

    %% External Services & APIs
    subgraph "External Services & APIs"
        direction TB
        GoogleGemini["Google Gemini API\n(async HTTP)"]:::external
        VoiceVoxAPI["VoiceVox API\n(async HTTP)"]:::external
        RVC["RVC CLI\n(subprocess)"]:::external
        ThirdParty["Third-Party Web APIs\n(weather, rate, shorturl)"]:::external
    end

    %% Documentation & Config
    Requirements["requirements.txt"]:::fs
    click Requirements "https://github.com/y-exe/sugiyama-bot/blob/main/requirements.txt"
    Readme["README.md"]:::fs
    click Readme "https://github.com/y-exe/sugiyama-bot/blob/main/README.md"

    %% Core Connections
    DiscordGateway -->|"events"| CommandProc
    CommandProc -->|"dispatch"| AISummarizer
    CommandProc -->|"dispatch"| VoiceConvModule
    CommandProc -->|"dispatch"| ImageModule
    CommandProc -->|"dispatch"| GamesEngine
    CommandProc -->|"dispatch"| UtilityClients
    CommandProc -->|"dispatch"| FileManager

    BotApp --> DiscordREST
    BotApp --> AISummarizer
    BotApp --> VoiceConvModule
    BotApp --> ImageModule
    BotApp --> GamesEngine
    BotApp --> UtilityClients
    BotApp --> FileManager

    %% Bot to File System
    FileManager --> Fonts
    FileManager --> Watermarks
    FileManager --> JSONStore
    FileManager --> AudioTemp

    %% Bot to External Services
    AISummarizer -->|async HTTP| GoogleGemini
    VoiceConvModule -->|async HTTP| VoiceVoxAPI
    VoiceConvModule -->|subprocess call| RVC
    ImageModule -->|uses Pillow| Fonts
    UtilityClients -->|async HTTP| ThirdParty

    %% Documentation & Config relation
    BotApp --> Requirements
    BotApp --> Readme

    classDef external fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef fs fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef core fill:#FFA500,stroke:#000,stroke-width:1px;
```
