How koishijs/koishi works
Main Components
• Core Engine (packages/core): This is the backbone. It includes the bot implementation, command handling (see files like bot.ts, command/*, parser.ts, validate.ts), context management, database interactions, middleware, i18n support (locales and i18n.ts), permissions, and schema definitions.
• CLI/Main Application (packages/koishi): This package contains the command-line interface (under src/cli), the main entry point (packages/koishi/src/index.ts), and worker-related modules (under packages/koishi/src/worker such as daemon.ts and logger.ts). It likely acts as the runtime that bootstraps the bot by integrating the core.
• Plugin System (plugins/*): There’s an extensive directory of plugins (e.g., common plugins like bind, broadcast, callme, echo, help, inspect and others such as hmr, http, mock, proxy-agent, server). These modules are designed to extend or complement the core functionality. They each maintain their own locales, tests, and configuration.
• Loader and Utilities (packages/loader and packages/utils): The loader package (e.g., packages/loader/src/index.ts) is likely responsible for dynamically loading and managing plugins/extensions. The utils package provides helper functions which support common operations across the system.
• Internationalization (packages/i18n-utils): Although seemingly a small package, it provides utilities to support the multiple locale files distributed across the core and plugin modules.
Out the Relationships and Data Flow
• A central “Core Engine” block that exposes fundamental services (bot logic, command parsing, context, database, etc.).
• “Loader” as an intermediary that dynamically imports or activates plugins. It should be shown between the core and the plugins.
• “Utilities” and “i18n” as supporting modules that are linked to both core and plugins. They provide cross-cutting functions and localization support.
Architectural Patterns and Design Principles
• Modular Architecture: Each package (core, CLI, plugins, loader, utilities) is self-contained, making the system highly extensible.
• Plugin-Based Extension: The clear separation into a core engine and separate plugins (each with its own locale support and tests) emphasizes an architecture where additional functionality can be “plugged in” without altering the core.
• Separation of Concerns: Core handles business logic, CLI/worker handles runtime interactions, and plugins encapsulate additional features.
• Use of standardized configuration/testing tools (see the various tsconfig.json files, ESLint configurations, GitHub workflows) which reinforces a robust, multi-package development practice.
Be Detailed
• You might also want to add a section for “Testing & Configuration” to show the presence of test suites within each package and the various config files (GitHub workflows, ESLint, etc.), indicating robust development practices.
Happy diagramming!