How mistval/kotoba works
Main Components
• Discord Bot – Housed under the “bot” directory. This component interacts with Discord (via Discord.js or similar) and includes its own set of commands, message processors, and helper utilities.
• API Server – Located in “api”. It is an Express-based backend providing endpoints for game operations, user data, and other functionalities. It also exposes routes (see “api/routes”) and utilities for game logic.
• Web Frontend – Found in the “kotobaweb” folder. This is a React application that displays the user interface, handles user interactions, and connects to the API.
• Worker Process – In the “worker” directory. Its role is to handle heavy-lifting tasks (like computing quiz statistics or rendering furigana) so that neither the API nor the bot’s event loop is blocked.
• Cloud Functions – Under “cloud_functions”. These comprise HTTP endpoints (for furigana and hispadic commands) that offload certain processing from the main bot/API.
• Nginx Proxy – The “nginx” directory holds configuration files for an Nginx server used to proxy web requests to both the frontend and API.
• Backup Tools – The “backup” directory provides scripts to backup user data, indicating an external process or scheduled task that interacts with the other systems.
• Resources – The “resources” directory contains non-code assets (dictionaries, fonts, images, quiz data) that are potentially used by multiple components (API, bot, web).
Relationships and Data Flows
• The Web Frontend (React) communicates with the API server via HTTP (or possibly WebSocket for real-time features).
• The API server might further interact with shared code (from “node-common” and “common”) and databases (MongoDB, as indicated in the README by configuration instructions).
• The Discord Bot interacts with both Discord (external integration) and internal services such as the Worker (sending HTTP requests to offload heavy tasks) and the Cloud Functions endpoints.
• The Nginx proxy sits in front of the web components and the API server, directing incoming HTTP requests appropriately.
• The Worker process receives HTTP requests from both the Bot and (potentially) the API for computational tasks, such as calculating quiz statistics.
• The Cloud Functions – deployed on platforms like Google Cloud – are triggered by the Bot (or possibly user actions) and provide results for specialized queries (like furigana and hispadic lookup).
Architectural Patterns and Design Principles
• Separation of Concerns – Components (bot, API, and frontend) are cleanly separated so that they can evolve independently.
• Microservices-like Communication – Even if not microservices in a strict sense, the use of HTTP for inter-process communication suggests loosely coupled pieces.
• Shared libraries – Common and node-common indicate adherence to the DRY principle by reusing code across components.
• Offloading intensive operations – The use of a Worker process and Cloud Functions shows that computation-heavy tasks are isolated, ensuring responsiveness in user-facing services.