# sunfish-shogi/shogihome architecture

> Architecture diagram of the GitHub repository sunfish-shogi/shogihome, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sunfish-shogi/shogihome
- Repository: https://github.com/sunfish-shogi/shogihome

## Overview

##### 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).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User"]:::user

    %% Electron Main Process (Background)
    subgraph "Electron Main Process (Background)"
        WM["Window Manager"]:::bg
        USI["USI Engine Communication"]:::bg
        CSA["CSA Engine Communication"]:::bg
        FRM["File & Record Manager"]:::bg
        PM["Process Management & Logging"]:::bg
        SM["Settings Manager"]:::bg
    end

    %% Renderer Process (Frontend/UI)
    subgraph "Renderer Process (Frontend/UI)"
        UIV["UI Views & Dialogs"]:::renderer
        LM["Layout Management"]:::renderer
        SMStore["Store/State Management"]:::renderer
        IPC["Renderer IPC Bridge"]:::renderer
        Assets["Assets"]:::renderer
        Helpers["Helpers"]:::renderer
    end

    %% Shared/Common Libraries
    subgraph "Shared/Common Libraries"
        Shared["Shared/Common Libraries"]:::common
    end

    %% Command-Line and Plugin Tools
    subgraph "Command-Line & Plugins"
        CLI["USI-CSA Bridge CLI"]:::cli
    end

    %% External Systems
    External["External Shogi Engine (USI/CSA)"]:::external

    %% Connections
    User --> UIV
    UIV --> IPC
    UIV --> LM
    IPC <--> WM
    IPC --> PM
    IPC --> SM
    WM --> Shared
    SMStore --> Shared
    LM --> Shared
    Assets --> Shared
    Helpers --> Shared
    USI --> External
    CSA --> External
    CLI --> USI
    CLI --> External

    %% Click Events for Electron Main Process
    click WM "https://github.com/sunfish-shogi/shogihome/tree/main/src/background/window"
    click USI "https://github.com/sunfish-shogi/shogihome/tree/main/src/background/usi"
    click CSA "https://github.com/sunfish-shogi/shogihome/tree/main/src/background/csa"
    click FRM "https://github.com/sunfish-shogi/shogihome/tree/main/src/background/file"
    click PM "https://github.com/sunfish-shogi/shogihome/tree/main/src/background/proc"
    click SM "https://github.com/sunfish-shogi/shogihome/blob/main/src/background/settings.ts"

    %% Click Events for Renderer Process
    click UIV "https://github.com/sunfish-shogi/shogihome/tree/main/src/renderer/view"
    click LM "https://github.com/sunfish-shogi/shogihome/tree/main/src/renderer/layout"
    click SMStore "https://github.com/sunfish-shogi/shogihome/tree/main/src/renderer/store"
    click IPC "https://github.com/sunfish-shogi/shogihome/tree/main/src/renderer/ipc"
    click Assets "https://github.com/sunfish-shogi/shogihome/tree/main/src/renderer/assets"
    click Helpers "https://github.com/sunfish-shogi/shogihome/tree/main/src/renderer/helpers"

    %% Click Events for Shared/Common Libraries and CLI Tools
    click Shared "https://github.com/sunfish-shogi/shogihome/tree/main/src/common"
    click CLI "https://github.com/sunfish-shogi/shogihome/tree/main/src/command/usi-csa-bridge"

    %% Class Definitions for Colors
    classDef bg fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef renderer fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef common fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef cli fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef user fill:#FFFACD,stroke:#000,stroke-width:2px;
```
