# sudo-nick/hatori architecture

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

- Interactive diagram: https://gitdiagram.com/sudo-nick/hatori
- Repository: https://github.com/sudo-nick/hatori

## Overview

##### Project Overview
- Hatori is an image editor with an infinite canvas, and its primary purpose is to handle drawing, image editing, and interaction with the canvas.
- It is written in C (with some C++ files as seen in hatori.cpp and hatori2.cpp) and integrates Raylib for managing the graphics and possibly input events.
- The build and deployment process has both native and web targets. This is controlled via a custom “make” script that orchestrates building Raylib (included as an external dependency) and then compiling the application.

##### Main Components
a. User Interface / Presentation Layer:
– The canvas and image editing interface that the user directly interacts with.
– This will be depicted as a top-level UI module/component.
b. Application Core / Business Logic:
– The logic for starting up, managing the canvas (handling drawing, zoom/pan events, etc.), and interfacing with user commands.
– This core likely resides in files like hatori.cpp, hatori.h, hatori2.cpp, and hatori3.c.
c. Graphics Abstraction / Raylib Integration:
– Raylib (sourced under src/external/raylib) is responsible for rendering and handling low-level graphics operations.
d. Build & Platform Layer:
– The “make” script and associated build configurations (targeting native and web builds) form the build system layer.
– Separate nodes can represent the build orchestration (compilation of external libraries and application code) and the platform-specific integration (e.g., raylib-web for the browser target via WebAssembly or native desktop builds).

##### Relationships and Data Flow
- If needed, you might also represent configuration files (.clang-format, .gitignore) as supporting components for code quality and source control, but these are less critical for the high-level system design.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly distinguish the application’s core logic from the graphics subsystem (Raylib). This isolation allows easier maintenance, testing, and potential swapping of the rendering engine.
- Layered Architecture: One layer deals with user interface interactions, the next manages business logic (canvas operations), and the lowest lever handles graphics and platform-specific code.
- Modular Inclusion: The external Raylib source is kept as a submodule or embedded dependency. Emphasize how the project encapsulates its use of Raylib without altering its core.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI["User Interface / Canvas Module"]:::frontend
    end

    %% Application Core / Business Logic
    subgraph "Application Core / Business Logic"
        APP1["hatori.cpp"]:::business
        APP2["hatori.h"]:::business
        APP3["hatori2.cpp"]:::business
        APP4["hatori3.c"]:::business
    end

    %% Graphics Abstraction / Raylib Integration
    subgraph "Graphics Layer"
        RAYLIB["Raylib – Graphics Engine"]:::external
    end

    %% Build System / Platform Integration
    subgraph "Build System / Platform Integration"
        BUILD["Build System (Make)"]:::buildsys
        NAT["Native Build"]:::platform
        WEB["Web Build"]:::platform
    end

    %% Connections between layers
    UI -->|"sends_input"| APP1
    APP1 --> APP2
    APP2 --> APP3
    APP3 --> APP4
    APP4 -->|"issues_graphics_calls"| RAYLIB

    %% Build system connections
    BUILD -->|"compiles"| APP1
    BUILD -->|"compiles"| RAYLIB
    BUILD --> NAT
    BUILD --> WEB

    %% Click events
    click UI "https://github.com/sudo-nick/hatori/blob/master/hatori.html"
    click APP1 "https://github.com/sudo-nick/hatori/blob/master/src/hatori.cpp"
    click APP2 "https://github.com/sudo-nick/hatori/blob/master/src/hatori.h"
    click APP3 "https://github.com/sudo-nick/hatori/blob/master/src/hatori2.cpp"
    click APP4 "https://github.com/sudo-nick/hatori/blob/master/src/hatori3.c"
    click RAYLIB "https://github.com/sudo-nick/hatori/tree/master/src/external/raylib"
    click BUILD "https://github.com/sudo-nick/hatori/tree/master/make"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#1f77b4,stroke-width:2px;
    classDef business fill:#fdd49e,stroke:#ff7f0e,stroke-width:2px;
    classDef external fill:#d5f5e3,stroke:#2ca02c,stroke-width:2px;
    classDef buildsys fill:#e1d5e7,stroke:#9467bd,stroke-width:2px;
    classDef platform fill:#e1d5e7,stroke:#9467bd,stroke-width:2px;
```
