# sakura-editor/sakura architecture

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

- Interactive diagram: https://gitdiagram.com/sakura-editor/sakura
- Repository: https://github.com/sakura-editor/sakura

## Overview

This project is the open‐source Sakura Editor – a Windows text editor written mainly in C++ with a classic desktop “document–view” architecture enhanced by plugin and macro support. The file tree and README indicate that it is a full-fledged native application with multiple layers (UI, core processing, document/model management, plugin integration, and utility modules) along with a heavy emphasis on development, building, and testing (using CI pipelines, unit tests, installation scripts, etc.).

##### Main system components
a. UI / Presentation Layer:
– This includes the main application launcher (sakura_core/_main) and window/dialog modules (directories such as sakura, sakura_core/dlg, sakura_core/window, sakura_core/view). They are responsible for rendering the user interface, handling user input (keyboard, mouse, etc.), and triggering commands.
b. Core Engine / Business Logic:
– Located in sakura_core, which contains document management (CDocEditor, CDocFile, and layout subdirectories), command processing (sakura_core/cmd), encoding/charset conversion (sakura_core/charset, sakura_core/convert), and other core utilities (memory management, error handling, and the API wrapper).
c. Plugins and Macro Infrastructure:
– Found under sakura_core/plugin and sakura_core/macro, providing extensibility. This layer describes how external modules, macro commands, and additional functionalities are integrated into the editor.
d. Supporting Utilities and Frameworks:
– Libraries such as the “basis” modules, “io” modules (for file and stream I/O), “debug”, “util”, and “types” add to the overall functionality.
e. Build, Test, and Deployment Infrastructure:
– Multiple scripts and CI configurations under .github, ci, tests, installer, and various build files (like sakura.sln, .vsconfig, appveyor.yml, azure-pipelines.yml) reflect a robust build and test pipeline.
f. External Dependencies and Resources:

##### Relationships and interactions
– The UI layer consumes core services from the editor’s engine, requesting document operations, text rendering, and command execution.
– The core engine communicates with supporting components (e.g., encoding conversion, file I/O, plugins) to perform its duties.
– The Plugins and Macro systems serve as extension points, with clearly defined interfaces that the core engine calls.
– Build scripts, unit tests, installer scripts, and continuous integration setups run against these components to ensure quality and deployment readiness.
– The separation of concerns is evident in layered module splitting, such as “doc” for document management, “cmd” for command handling, “util” for utility services, etc.

##### Architectural patterns and design principles
– Emphasize a layered architecture – separating UI, core processing, plugin/macro integration, and utilities.
– Illustrate the usage of design patterns such as MVC or Model–View–Controller (the “doc” and “view” layers in sakura_core) and Observer for event handling across components.
– Identify modularity and extensibility (via plugin and macro managers) with well-defined interfaces.
– Include build automation and continuous integration as separate entities feeding into the development life cycle.

##### Mention relevant technologies and frameworks
– C++ (native Windows development with Visual Studio; note the .vcxproj files and solution files)
– Build automation tools (batch files, CMake files in tests, CI configurations for AppVeyor and Azure Pipelines)
– Static analysis tools such as cppcheck, doxygen for documentation, and integration with SonarQube.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface (UI & Windows)"
        UI_main["Main Launcher (_main)"]:::ui
        UI_dlg["Dialog Modules (dlg)"]:::ui
        UI_window["Window Components (window)"]:::ui
        UI_view["View Components (view)"]:::ui
    end

    %% Core Engine Layer
    subgraph "Core Engine (Document & Command Processing)"
        core_main["Core Code (sakura_core)"]:::core
        core_doc["Document Management (doc)"]:::core
        core_cmd["Command Processing (cmd)"]:::core
        core_charset["Charset Conversion (charset)"]:::core
        core_convert["Encoding Conversion (convert)"]:::core
        core_util["Core Utilities (util)"]:::core
        core_io["File/Stream I/O (io)"]:::core
    end

    %% Plugins & Macro Module
    subgraph "Plugins and Macro Module"
        plugin["Plugins (plugin)"]:::plugins
        macro["Macro Support (macro)"]:::plugins
    end

    %% Supporting Utilities & Frameworks
    subgraph "Supporting Utilities and Frameworks"
        basis["Basis Modules (basis)"]:::utilities
        debug["Debug Utilities (debug)"]:::utilities
        extmodule["External Modules (extmodule)"]:::utilities
        func["Function Modules (func)"]:::utilities
        types["Types (types)"]:::utilities
    end

    %% Build, Test, and Deployment Infrastructure
    subgraph "Build, Test, and Deployment Infrastructure"
        github["GitHub Workflows (.github)"]:::build
        ci["CI Scripts (ci)"]:::build
        installer["Installer Scripts (installer)"]:::build
        tests["Unit & Compile Tests (tests)"]:::build
        buildFiles["Build Files (sakura.sln, .vsconfig, appveyor.yml, azure-pipelines.yml)"]:::build
    end

    %% External Dependencies and Resources
    subgraph "External Dependencies and Resources"
        externals["Externals (externals)"]:::external
        resource["Resources (resource)"]:::external
        help["Documentation & Help (help)"]:::external
    end

    %% Relationships between layers
    UI_main  -->|"UserInput"| core_main
    UI_dlg   -->|"UserInteraction"| core_main
    UI_window-->|"WindowMgmt"| core_main
    UI_view  -->|"ViewUpdates"| core_main

    core_main -->|"Manages"| core_doc
    core_main -->|"Executes"| core_cmd
    core_main -->|"Converts"| core_charset
    core_main -->|"Encodes"| core_convert
    core_main -->|"Utilizes"| core_util
    core_main -->|"I/OOps"| core_io

    core_main -->|"ExtendsVia"| plugin
    core_main -->|"HooksMacro"| macro

    core_main -->|"Uses"| basis
    core_main -->|"DebugsVia"| debug
    core_main -->|"Integrates"| extmodule
    core_main -->|"Functions"| func
    core_main -->|"HandlesTypes"| types

    %% Build/CI integration
    github -->|"TriggersBuild"| buildFiles
    ci     -->|"CI_Pipeline"| buildFiles
    tests  -->|"Tests"| core_main
    installer -->|"Packages"| core_main
    buildFiles -->|"Builds"| core_main

    %% External Dependencies integration
    externals -->|"ToolsFor"| buildFiles
    resource  -->|"ProvidesAssets"| UI_window
    help      -->|"Guides"| UI_dlg

    %% CSS Classes
    classDef ui fill:#cce5ff,stroke:#0056b3,stroke-width:2px;
    classDef core fill:#dff0d8,stroke:#3c763d,stroke-width:2px;
    classDef plugins fill:#f2dede,stroke:#a94442,stroke-width:2px;
    classDef utilities fill:#f9f2d4,stroke:#8a6d3b,stroke-width:2px;
    classDef build fill:#fcf8e3,stroke:#8a6d3b,stroke-width:2px,stroke-dasharray: 5 5;
    classDef external fill:#d9edf7,stroke:#31708f,stroke-width:2px;

    %% Click Events for UI / Presentation Layer
    click UI_main "https://github.com/sakura-editor/sakura/tree/master/sakura_core/_main"
    click UI_dlg "https://github.com/sakura-editor/sakura/tree/master/sakura_core/dlg"
    click UI_window "https://github.com/sakura-editor/sakura/tree/master/sakura_core/window"
    click UI_view "https://github.com/sakura-editor/sakura/tree/master/sakura_core/view"

    %% Click Events for Core Engine / Business Logic
    click core_main "https://github.com/sakura-editor/sakura/tree/master/sakura_core"
    click core_cmd "https://github.com/sakura-editor/sakura/tree/master/sakura_core/cmd"
    click core_charset "https://github.com/sakura-editor/sakura/tree/master/sakura_core/charset"
    click core_convert "https://github.com/sakura-editor/sakura/tree/master/sakura_core/convert"
    click core_util "https://github.com/sakura-editor/sakura/tree/master/sakura_core/util"
    click core_io "https://github.com/sakura-editor/sakura/tree/master/sakura_core/io"

    %% Click Events for Plugins and Macro Infrastructure
    click plugin "https://github.com/sakura-editor/sakura/tree/master/sakura_core/plugin"
    click macro "https://github.com/sakura-editor/sakura/tree/master/sakura_core/macro"

    %% Click Events for Supporting Utilities and Frameworks
    click basis "https://github.com/sakura-editor/sakura/tree/master/sakura_core/basis"
    click debug "https://github.com/sakura-editor/sakura/tree/master/sakura_core/debug"
    click extmodule "https://github.com/sakura-editor/sakura/tree/master/sakura_core/extmodule"
    click func "https://github.com/sakura-editor/sakura/tree/master/sakura_core/func"
    click types "https://github.com/sakura-editor/sakura/tree/master/sakura_core/types"

    %% Click Events for Build, Test, and Deployment Infrastructure
    click github "https://github.com/sakura-editor/sakura/blob/master/.github"
    click ci "https://github.com/sakura-editor/sakura/tree/master/ci"
    click installer "https://github.com/sakura-editor/sakura/tree/master/installer"
    click tests "https://github.com/sakura-editor/sakura/tree/master/tests"
    click buildFiles "https://github.com/sakura-editor/sakura/blob/master/sakura.sln"

    %% Click Events for External Dependencies and Resources
    click externals "https://github.com/sakura-editor/sakura/tree/master/externals"
    click resource "https://github.com/sakura-editor/sakura/tree/master/resource"
    click help "https://github.com/sakura-editor/sakura/tree/master/help"
```
