# dorayaki-chan/clanmanagementdiscordbot architecture

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

- Interactive diagram: https://gitdiagram.com/dorayaki-chan/clanmanagementdiscordbot
- Repository: https://github.com/dorayaki-chan/clanmanagementdiscordbot

## Overview

##### Main Components to Identify
- Discord Bot Interface: As the project is a “Discord鯖管理Bot”, the bot must interact with Discord’s API. Represent this as the primary external component.
- Command Processing Module: Within src-js-2, the “commands” directory shows a modularized command handling system (including HTML project assets, info, kick, and special measures commands).
- API Request & Scraping Modules: The “api-requests” directories in src-js-2 (and also some similar modules in src-js-1) indicate that the bot makes external API calls and performs web scraping. Include nodes for these and show interaction with external services.
- Database Integration: The README includes MySQL commands (e.g., creating “clandb”) and there are several modules for database creation and operations (such as createDB.js and operateDatabase). Mark the MySQL database as a central component.
- Utility/Support Modules:
– Tools for date/time conversion (change-datetime-type, makeDateTime.js).
– Structure modules for entities like “activity”, “profile”, and “role” (src-js-2/src/structures).
– Template resources (discordServerInfo.json, notice.json, roles.json) for message or configuration formats.
- Patch/Update Modules: The patch directory (src-js-2/patch) suggests scripts that modify the DB schema or other features.
- Python Component: In the src-py folder, main.py and config.py likely represent an auxiliary or complementary service that may handle specific tasks not covered in the JavaScript code.

##### Relationships and Data Flow
- The Discord Bot Component sends/receives messages from Discord servers.
- Incoming commands are routed to the Command Processing Module in src-js-2.
- Many commands trigger API requests (handled by the dedicated module) or web scraping routines to fetch data from external sources.
- The Database Component is accessed by various modules (both creation and operation) to store or retrieve data, for instance when processing user commands or updating server info.
- Utility modules (like those for date-time conversion) support other processes by formatting or transforming data.
- If the Python component integrates with the JavaScript code base, it may communicate via a defined API or be scheduled as a background worker, so mark its interaction with the database or other services as needed.

##### Architectural Patterns / Design Principles
- Modularity: The project is clearly divided into many small modules (commands, API requests, scraping, database operations) making it easier to maintain and extend.
- Separation of Concerns: There is a clear boundary between the bot communication layer, command-processing logic, data acquisition (web scraping/API calls), and database interaction.
- Configuration-Driven: With several example config files (e.g., in src-js-2/config), the system likely uses external configuration files for environment-dependent settings.
- Evolutionary Development: Presence of both “src-js-1” and “src-js-2” suggests iterations in architecture, with src-js-2 representing an improved, more maintainable version.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Discord Communication"
        DAPI("Discord API"):::external
        DBI("Discord Bot Interface"):::bot
        DAPI -->|"messages"| DBI
    end

    subgraph "Core Processing"
        CPM("Command Processing Module"):::processing
        DBI -->|"forwards commands"| CPM
    end

    subgraph "External Integration"
        APIJS("API Request Module (JS)"):::integration
        SCRJS("Scraping Module (JS)"):::integration
        SCRJS1("Scraping Module (JS-1)"):::integration
        EXT("External API"):::external
        CPM -->|"triggers_API"| APIJS
        CPM -->|"triggers_scraping"| SCRJS
        CPM -->|"triggers_scraping"| SCRJS1
        APIJS -->|"calls"| EXT
        SCRJS -->|"scrapes"| EXT
        SCRJS1 -->|"scrapes"| EXT
    end

    subgraph "Database Integration"
        DBC1("Database Creation (JS-1)"):::database
        DBC2("Database Creation (JS-2)"):::database
        DBO("Database Operations"):::database
        DBC1 -->|"init_DB"| DBO
        DBC2 -->|"init_DB"| DBO
        CPM -->|"db_queries"| DBO
    end

    subgraph "Utilities & Support"
        DTJS1("Date/Time Conversion (JS-1)"):::utility
        DTJS2("Date/Time Conversion (JS-2)"):::utility
        STR("Structure Modules"):::utility
        TPL("Template Resources"):::utility
        CPM -->|"formats"| DTJS1
        CPM -->|"formats"| DTJS2
        CPM -->|"uses"| STR
        CPM -->|"uses"| TPL
    end

    subgraph "Patch & Update"
        PATCH("Patch/Update Module"):::patch
        CPM -->|"apply_patches"| PATCH
        PATCH -->|"updates_schema"| DBO
    end

    subgraph "Auxiliary Services"
        PY("Python Component"):::python
        PY -->|"db_support"| DBO
    end

    %% Click Events
    click DBI "https://github.com/dorayaki-chan/clanmanagementdiscordbot/blob/master/src-js-2/src/runbot/main.js"
    click CPM "https://github.com/dorayaki-chan/clanmanagementdiscordbot/tree/master/src-js-2/src/commands"
    click APIJS "https://github.com/dorayaki-chan/clanmanagementdiscordbot/blob/master/src-js-2/src/api-requests/api-requests.js"
    click SCRJS "https://github.com/dorayaki-chan/clanmanagementdiscordbot/blob/master/src-js-2/src/api-requests/scraping.js"
    click SCRJS1 "https://github.com/dorayaki-chan/clanmanagementdiscordbot/blob/master/src-js-1/src/process/apiRequest.js"
    click DBC1 "https://github.com/dorayaki-chan/clanmanagementdiscordbot/blob/master/src-js-1/src/process/createDB.js"
    click DBC2 "https://github.com/dorayaki-chan/clanmanagementdiscordbot/blob/master/src-js-2/src/first-todo/createDatabase.js"
    click DBO "https://github.com/dorayaki-chan/clanmanagementdiscordbot/blob/master/src-js-2/src/operateDatabase/opratedatabase.js"
    click DTJS1 "https://github.com/dorayaki-chan/clanmanagementdiscordbot/blob/master/src-js-1/src/process/makeDateTime.js"
    click DTJS2 "https://github.com/dorayaki-chan/clanmanagementdiscordbot/blob/master/src-js-2/src/change-datetime-type/toDatetime.js"
    click STR "https://github.com/dorayaki-chan/clanmanagementdiscordbot/tree/master/src-js-2/src/structures"
    click TPL "https://github.com/dorayaki-chan/clanmanagementdiscordbot/tree/master/src-js-2/template"
    click PATCH "https://github.com/dorayaki-chan/clanmanagementdiscordbot/tree/master/src-js-2/patch"
    click PY "https://github.com/dorayaki-chan/clanmanagementdiscordbot/tree/master/src-py"

    %% Styles
    classDef external fill:#ccf,stroke:#333,stroke-width:2px;
    classDef bot fill:#fcf,stroke:#333,stroke-width:2px;
    classDef processing fill:#cff,stroke:#333,stroke-width:2px;
    classDef integration fill:#cfc,stroke:#333,stroke-width:2px;
    classDef database fill:#ffc,stroke:#333,stroke-width:2px;
    classDef utility fill:#f9c,stroke:#333,stroke-width:2px;
    classDef patch fill:#fcc,stroke:#333,stroke-width:2px;
    classDef python fill:#e0e0ff,stroke:#333,stroke-width:2px;
```
