# sabakihq/sabaki architecture

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

- Interactive diagram: https://gitdiagram.com/sabakihq/sabaki
- Repository: https://github.com/sabakihq/sabaki

## Overview

##### Main Components
- UI Layer: Show the primary “App” component at the entry point (from src/components/App.js) as the container for the SPA.
- UI Subcomponents: List out the individual UI components – for example, MainMenu, MainView, Goban (the main board), MiniGoban, DrawerManager, ToolBar, the various bars (e.g., AutoplayBar, EditBar) and sidebars (e.g., CommentBox, GtpConsole). These represent different regions of the user interface.
- Modules/Logic: Represent the modules housed in src/modules. Key modules include:
- File Formats: Including submodules for SGF, GIB, NGF, and UGf (found under src/modules/fileformats).
- Game Logic & Transformation: Modules such as gamesort, gametree, gobantransformer.
- Engine Support: The enginesyncer and GTP logger to support external GTP engine integration.
- Helpers/Shims: Utility modules like helper.js and shims for compatibility.
- Supporting Layers:
- Internationalization (i18n.js in src),
- Updater (src/updater.js),
- Settings (src/setting.js).
- Configuration and Build: Represent build configuration files (webpack.config.js, package.json) as the foundation that compiles and bundles these components.
- Data Assets: Include the data folder containing audio files and assets for the application (like themes and textures suggested by user-customizable board appearances).

##### Relationships and Interactions
- User Interaction flows: A user starts at the “App” and interacts with the UI components (e.g., through drawer menus, toolbars, or direct board manipulation); actions and events flow from these UI components to the underlying modules.
- Data handling: When a user opens or edits a game file, the UI sends requests to the appropriate file format parser modules (sgf.js, gib.js, etc.). Similarly, integrations with GTP engines pass moves and analysis results between the UI and the engine support modules.
- Module Interconnection:
- The game tree and game sorting utilities work together to update the board state.
- The settings or theme modules update the UI’s styling dynamically (reflected through the style/ directory).

##### Architectural Patterns and Design Principles
- Component-Based Architecture: The project splits its UI into numerous reusable components (React-based, judging by the .js components and modular organization).
- Separation of Concerns: Notice how UI components are separated from the game logic and file handling modules.
- Extensibility: Clearly highlight integration points (e.g., plugin-like modules for GTP engines and various file formats) which allow Sabaki to be extensible and to integrate with external services.

##### Highlighting Relevant Technologies and Frameworks
- JavaScript Framework: The use of components in the src directory suggests a modern JavaScript framework (possibly React or Preact – especially given related projects like Shudan mentioned in the README).
- Bundling Tools: Webpack is used as evident from webpack.config.js.
- CI/CD: GitHub workflows and CI scripts, indicating automated testing and deployment.
- Testing: A separate test directory emphasizes the importance of automated tests for game logic and file format handling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        A["App (Main Container)"]:::ui
        MM["Main Menu"]:::ui
        MV["Main View"]:::ui
        GB["Board (Goban)"]:::ui
        MG["Mini Board (MiniGoban)"]:::ui
        DM["Drawer Manager"]:::ui
        TB["Tool Bar"]:::ui
        AB["Autoplay Bar"]:::ui
        EB["Edit Bar"]:::ui
        CB["Comment Box Sidebar"]:::ui
        GC["GTP Console Sidebar"]:::ui
    end

    %% Modules / Business Logic
    subgraph "Modules/Logic"
        %% File Formats Parsers
        subgraph "File Formats Parsers"
            SGF["SGF Parser"]:::module
            GIB["GIB Parser"]:::module
            NGF["NGF Parser"]:::module
            UGf["UGf Parser"]:::module
        end
        %% Game Logic & Transformation
        subgraph "Game Logic & Transformation"
            GS["Game Sort Utility"]:::module
            GTM["Game Tree Management"]:::module
            BT["Board Transformation"]:::module
        end
        %% Engine Support
        subgraph "Engine Support"
            ES["Engine Synchronization"]:::module
            GL["GTP Logger"]:::module
        end
        %% Helpers & Shims
        subgraph "Helpers/Shims"
            GH["General Helpers"]:::module
            CS["Compatibility Shims"]:::module
        end
    end

    %% Supporting Layers
    subgraph "Supporting Layer"
        I18n["Internationalization"]:::module
        UP["Updater"]:::module
        SET["Settings"]:::module
    end

    %% Configuration & Build
    subgraph "Configuration & Build"
        WP["Webpack Configuration"]:::config
        PK["Package Configuration"]:::config
    end

    %% Data Assets
    DA["Data Assets"]:::asset

    %% Connections from UI Layer to Modules/Logic
    A -->|"initializes"| MM
    A -->|"initializes"| MV
    A -->|"initializes"| DM
    A -->|"initializes"| TB

    MV -->|"renders"| GB
    MV -->|"renders"| MG
    MV -->|"invokes"| SGF
    MV -->|"invokes"| GIB
    MV -->|"invokes"| NGF
    MV -->|"invokes"| UGf

    GB -->|"updates via"| GTM
    GB -->|"updates via"| GS
    GB -->|"updates via"| BT

    TB -->|"controls"| AB
    TB -->|"controls"| EB

    CB -->|"displays comments for"| GTM
    GC -->|"interfaces with"| ES
    GC -->|"interfaces with"| GL

    %% Connections from Modules to Supporting Layers
    SET -->|"modifies UI"| A
    I18n -->|"localizes"| A
    UP -->|"notifies changes to"| A

    %% Connections among Modules
    GH -->|"assists"| SGF
    GH -->|"assists"| GIB
    GH -->|"assists"| NGF
    GH -->|"assists"| UGf
    CS -->|"ensures compatibility for"| GTM

    %% Build and Data Assets Support
    WP -->|"bundles"| A
    PK -->|"manages dependencies for"| A
    DA -->|"provides assets to"| A

    %% Click Events for UI Layer
    click A "https://github.com/sabakihq/sabaki/blob/master/src/components/App.js"
    click MM "https://github.com/sabakihq/sabaki/blob/master/src/components/MainMenu.js"
    click MV "https://github.com/sabakihq/sabaki/blob/master/src/components/MainView.js"
    click GB "https://github.com/sabakihq/sabaki/blob/master/src/components/Goban.js"
    click MG "https://github.com/sabakihq/sabaki/blob/master/src/components/MiniGoban.js"
    click DM "https://github.com/sabakihq/sabaki/blob/master/src/components/DrawerManager.js"
    click TB "https://github.com/sabakihq/sabaki/blob/master/src/components/ToolBar.js"
    click AB "https://github.com/sabakihq/sabaki/blob/master/src/components/bars/AutoplayBar.js"
    click EB "https://github.com/sabakihq/sabaki/blob/master/src/components/bars/EditBar.js"
    click CB "https://github.com/sabakihq/sabaki/blob/master/src/components/sidebars/CommentBox.js"
    click GC "https://github.com/sabakihq/sabaki/blob/master/src/components/sidebars/GtpConsole.js"

    %% Click Events for File Formats Parsers
    click SGF "https://github.com/sabakihq/sabaki/blob/master/src/modules/fileformats/sgf.js"
    click GIB "https://github.com/sabakihq/sabaki/blob/master/src/modules/fileformats/gib.js"
    click NGF "https://github.com/sabakihq/sabaki/blob/master/src/modules/fileformats/ngf.js"
    click UGf "https://github.com/sabakihq/sabaki/blob/master/src/modules/fileformats/ugf.js"

    %% Click Events for Game Logic & Transformation
    click GS "https://github.com/sabakihq/sabaki/blob/master/src/modules/gamesort.js"
    click GTM "https://github.com/sabakihq/sabaki/blob/master/src/modules/gametree.js"
    click BT "https://github.com/sabakihq/sabaki/blob/master/src/modules/gobantransformer.js"

    %% Click Events for Engine Support
    click ES "https://github.com/sabakihq/sabaki/blob/master/src/modules/enginesyncer.js"
    click GL "https://github.com/sabakihq/sabaki/blob/master/src/modules/gtplogger.js"

    %% Click Events for Helpers & Shims
    click GH "https://github.com/sabakihq/sabaki/blob/master/src/modules/helper.js"
    click CS "https://github.com/sabakihq/sabaki/blob/master/src/modules/shims/prop-types.js"

    %% Click Events for Supporting Layers
    click I18n "https://github.com/sabakihq/sabaki/blob/master/src/i18n.js"
    click UP "https://github.com/sabakihq/sabaki/blob/master/src/updater.js"
    click SET "https://github.com/sabakihq/sabaki/blob/master/src/setting.js"

    %% Click Events for Configuration & Build
    click WP "https://github.com/sabakihq/sabaki/blob/master/webpack.config.js"
    click PK "https://github.com/sabakihq/sabaki/blob/master/package.json"

    %% Click Event for Data Assets
    click DA "https://github.com/sabakihq/sabaki/tree/master/data/"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef module fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef config fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef asset fill:#F5CBA7,stroke:#D35400,stroke-width:2px;
```
