# satory074/discord-bot-beauty architecture

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

- Interactive diagram: https://gitdiagram.com/satory074/discord-bot-beauty
- Repository: https://github.com/satory074/discord-bot-beauty

## Overview

##### Project Type and Purpose
- This is a Discord bot project intended for public use (“人様に見せられるようにした discordbot”). The README emphasizes integration with several external services (e.g., Dropbox, Google Apps Script, AWS CI/CD pipelines, and CodeDeploy), making it a full-stack system that leverages both external APIs and cloud deployment pipelines.

##### Analysis of the File Structure
- Top-Level Files:
- .gitignore, README.md: Standard project files for version control and documentation.
- appspec.yml, runtime.txt, requirements.txt: These files indicate deployment configurations (likely for AWS CodeDeploy), runtime environment setup, and Python dependencies.
- Directories:
- scripts: Contains scripts for starting and stopping the application (likely used by CodeDeploy or systemd for automation).
- src: Contains the primary Python source code.
· Files like main.py, config.py, and several command or action-related files (commands.py, commands_tree.py, botutility.py, action.py) suggest that this directory implements the bot’s core functionality, command processing, and integration with external services (e.g., Dropbox with mydropbox.py).

##### Main Components
a. Code Repository & Development:
b. CI/CD Pipeline and Deployment:
- AWS CodeDeploy: Handles automated deployment from GitHub to AWS.
- S3: Used to store deployment artifacts.
- AWS EC2: Where the bot (running as a daemon via systemd) is deployed.
c. External Services and API Integrations:
- Discord: The core service to which the bot responds.
- Dropbox & Other External APIs: Shown as bidirectional interactions with the bot.
- Google Apps Script (GAS): For scheduled tasks (定期実行) and reminders, posting data to webhooks.
d. Additional AWS Components:
- CloudWatch & AWS Lambda: For cost monitoring, scheduled actions, and triggering webhooks.
- AWSBudgets: For cost insights triggered by Lambda functions.

##### Key Relationships and Interactions
- Code Flow: Developer commits lead to GitHub repository updates, which then trigger CI/CD pipelines (via GitHub Actions) that push changes to S3 and trigger CodeDeploy.
- Deployment Flow: AWS CodeDeploy downloads the latest bot version to the EC2 instance where it is managed (started/stopped) via system scripts.
- Runtime Interactions:
- The bot interacts with Discord (sending and receiving messages).
- It interacts with Dropbox and other APIs.
- Scheduled tasks (using Cron or AWS Lambda influenced by CloudWatch events) trigger actions in the bot.
- Google Apps Script periodically posts to webhooks that the bot listens to.
- Architectural Patterns:
- CI/CD Pipeline: Explicit integration via GitHub Actions, S3, and CodeDeploy.
- Microservice/Modular Design: Clear separation of concerns with the “src” modules handling different aspects (configuration, commands, actions, etc.).
- Integration with cloud services: AWS (multiple services) and third-party automations.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Development Layer
    subgraph "Development - Code Repository"
        REPO1["README.md"]:::dev
        REPO2[".gitignore"]:::dev
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        GACTIONS["GitHub Actions"]:::cicd
        S3["S3 (Artifact Store)"]:::aws
        CODEDEPLOY["AWS CodeDeploy"]:::aws
        subgraph "Deployment Config"
            CDS1["appspec.yml"]:::cicd
            CDS2["runtime.txt"]:::cicd
            CDS3["requirements.txt"]:::cicd
        end
    end

    %% Deployed Environment on AWS EC2
    subgraph "AWS EC2 Instance"
        subgraph "Deployment Scripts"
            DS1["applicationstart"]:::aws
            DS2["applicationstop"]:::aws
        end
        subgraph "Bot Core Modules"
            MAIN["Main Application (main.py)"]:::bot
            CONFIG["Configuration (config.py)"]:::bot
            CMD1["Command Processing (commands.py)"]:::bot
            CMD2["Commands Tree (commands_tree.py)"]:::bot
            DISCLIENT["Discord Client (myclient.py)"]:::bot
            DROPBOX["Dropbox Integration (mydropbox.py)"]:::bot
            UTILS["Utility Functions (botutility.py)"]:::bot
            ACTION["Action Handler (action.py)"]:::bot
            CRON["Scheduled Tasks (cronfunction.py)"]:::bot
        end
    end

    %% External Services
    DISCORD_EXT["Discord"]:::external
    DROPBOX_EXT["Dropbox API"]:::external
    GAS["Google Apps Script"]:::external
    AWS_LAMBDA["AWS Lambda/CloudWatch/AWSBudgets"]:::aws

    %% Relationships
    REPO1 -->|"commit"| GACTIONS
    REPO2 -->|"commit"| GACTIONS
    GACTIONS -->|"build_artifact"| S3
    S3 -->|"trigger"| CODEDEPLOY
    CODEDEPLOY -->|"deploys_to"| MAIN

    %% Bot Internal Interactions
    DISCLIENT <-->|"communicates"| DISCORD_EXT
    DROPBOX <-->|"integrates_with"| DROPBOX_EXT

    %% Scheduled Task Triggers
    GAS -->|"triggers"| CRON
    AWS_LAMBDA -->|"triggers"| CRON

    %% Class Definitions for colors
    classDef dev fill:#ffccff,stroke:#990099,stroke-width:2px;
    classDef cicd fill:#cce5ff,stroke:#003399,stroke-width:2px;
    classDef aws fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef bot fill:#ccffff,stroke:#009999,stroke-width:2px;
    classDef external fill:#ffdd99,stroke:#cc6600,stroke-width:2px;

    %% Click Events
    click REPO1 "https://github.com/satory074/discord-bot-beauty/blob/main/README.md"
    click REPO2 "https://github.com/satory074/discord-bot-beauty/blob/main/.gitignore"
    click CDS1 "https://github.com/satory074/discord-bot-beauty/blob/main/appspec.yml"
    click CDS2 "https://github.com/satory074/discord-bot-beauty/blob/main/runtime.txt"
    click CDS3 "https://github.com/satory074/discord-bot-beauty/blob/main/requirements.txt"
    click DS1 "https://github.com/satory074/discord-bot-beauty/tree/main/scripts/applicationstart"
    click DS2 "https://github.com/satory074/discord-bot-beauty/tree/main/scripts/applicationstop"
    click MAIN "https://github.com/satory074/discord-bot-beauty/blob/main/src/main.py"
    click CMD1 "https://github.com/satory074/discord-bot-beauty/blob/main/src/commands.py"
    click CMD2 "https://github.com/satory074/discord-bot-beauty/blob/main/src/commands_tree.py"
    click CONFIG "https://github.com/satory074/discord-bot-beauty/blob/main/src/config.py"
    click DISCLIENT "https://github.com/satory074/discord-bot-beauty/blob/main/src/myclient.py"
    click DROPBOX "https://github.com/satory074/discord-bot-beauty/blob/main/src/mydropbox.py"
    click UTILS "https://github.com/satory074/discord-bot-beauty/blob/main/src/botutility.py"
    click ACTION "https://github.com/satory074/discord-bot-beauty/blob/main/src/action.py"
    click CRON "https://github.com/satory074/discord-bot-beauty/blob/main/src/cronfunction.py"
```
