How sunfish-shogi/shogihome works
Project Type and Purpose
• The README makes it clear that ShogiHome is a GUI application for playing shogi, similar in purpose to “将棋所” or ShogiGUI.
• It leverages Electron for cross-platform desktop support as well as a web app version for browsers.
• It integrates with external shogi engines using the USI protocol (and CSA support), which makes the communications with the engine a key architectural focus.
File Structure for Architectural Clues
• Notice the clear separation between:
• “src/background” – Code running in Electron’s main process. This handles window creation, background processes (e.g., engine integration, logging, file system operations, and settings management).
• “src/renderer” – Code that defines the frontend UI (views, dialogs, layouts, and state management) built with web technologies (Vue components are indicated via .vue files).
• “src/common” contains shared utilities, helpers (for i18n, file conversion, etc.), and core libraries that provide data models and business logic used by both background and renderer.
• There are dedicated “src/command” subdirectories (for example the usi-csa-bridge) to handle CLI or engine integration tasks.
• The “tests” directory shows comprehensive testing of background logic, IPC communication, UI components, etc.
• Build and configuration files (webpack, Vite, tsconfig, etc.) reveal that multiple bundlers and environments (development, production, Electron, and web app) are being supported.
Main Components
• Electron Main Process (Background)
• Components: Window management, process orchestration, file I/O, system settings, USI/CSA engine communication (src/background/usi and src/background/csa), logging, helper modules.
• Modules such as “src/background/book”, “src/background/file”, “src/background/proc” illustrate support for game analysis and record handling.
• Renderer Process (Frontend/UI)
• UI Views: Composed of components (e.g., board displays, dialogs, menus, prompt views) found in “src/renderer/view” and “src/renderer/layout”.
• Store/State Management: Modules under “src/renderer/store” manage the application state for control, settings, and game data.
• Assets and helpers: “src/renderer/assets” and “src/renderer/helpers” support UI rendering and functionality.
• IPC Layers: Directories such as “src/renderer/ipc” provide the means by which UI communicates with the background process.
• Communication/IPC Channel
• “src/common/ipc” and corresponding renderer/background IPC modules indicate that bidirectional messaging (using channels and preloads) is essential for coordinating events and data between UI and backend processes.
• Command-Line and Plugin Tools
• “src/command” and “plugins” show the existence of CLI utilities (like the USI-CSA bridge) and build tools that extend the core functionality.
• External Components
• External shogi engines using the USI protocol.
• Standard libraries and dependencies like Node.js, Electron, and Chromium for deployment.
Architectural Patterns & Design Choices
• Separation of Concerns: Division between background and renderer processes mirrors typical Electron architecture.
• Modular Architecture: Clear separation of shared modules, helper libraries, and independent “command” or plugin components.
• Cross-Platform, Multiple UI Environments: Support for Electron-based desktop app and a browser-based version.
• Clear division of business logic (game rules, I18n, file conversions) and presentation (UI components, layout views).