# datavorous/grudgepixel architecture

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

- Interactive diagram: https://gitdiagram.com/datavorous/grudgepixel
- Repository: https://github.com/datavorous/grudgepixel

## Overview

##### Project Type and Purpose
- GrudgePixel is a full-fledged pixel art editor written in C++, explicitly using raylib for graphics. It targets fast, low-memory usage, and simplicity for both beginners and expert users.
- The README shows it’s built using premake5, with a clear delineation of source files (in “src/” and “include/”) and assets (in “res/”). There’s also an auxiliary Python tool (“Enhancer_GUI.py”) for additional image enhancements.

##### Key Components
a. Front-End / User Interface:
- The UI module is represented by the files in “include/ui.h” and “src/ui.cpp”. This module handles drawing the interface and likely interactions.
- It is integrated with the main application loop (src/main.cpp) using raylib.
b. Drawing Module:
- The drawing functionality is encapsulated in “include/drawing.h” and “src/drawing.cpp”. It’s responsible for rendering pixel art elements.
c. Input Handling:
- Files “include/input.h” and “src/input.cpp” manage user input, capturing keystrokes and mouse interactions.
d. File Operations:
- “include/file.h” and “src/file.cpp” likely handle file I/O—loading and saving pixel art.
e. Main Application Flow:
- The “src/main.cpp” ties everything together, starting the application, initializing raylib, and managing the overall event loop.
f. External Enhancer Module:
- “Enhancer_GUI.py” is a separate utility that provides additional image processing functionality (enhancements, resizing, dithering, etc.). Include this as an optional external tool that interacts with the core application.
g. Build and Configuration:
- The premake5.lua and raylib_premake5.lua scripts indicate the use of premake5 for cross-platform project file generation, which is a part of the build system.
h. Assets and Resources:
- The “res/” directory holds assets (images, potentially fonts, etc.) needed by the application.
- “demo/” shows sample outputs/screenshots illustrating the application’s capabilities.
i. Repository Management:
- The .github folder and associated issue templates for bug reports and feature requests indicate how contributions and issue tracking are managed, though these are more project maintenance aspects.

##### Relationships and Data Flow
- The main component (main.cpp) initializes the program and coordinates component interactions:
- It sets up the raylib context and calls UI routines.
- The UI module, via the drawing and input components, handles user interactions and renders the art content.
- When saving or loading, the file module is called to handle I/O operations.
- The drawing and input components interact closely: input data (from key presses/mouse events) is used to update the drawing canvas.
- The external Enhancer tool can be seen as an adjunct service that is called when users select image enhancement options.

##### Architectural Patterns and Principles
- Modular separation: Each functionality (UI, drawing, input, file handling) is isolated in its own module. This separation aids maintainability and testing.
- A simple main event loop in main.cpp coordinates between modules.
- The build is handled externally via premake5 scripts, suggesting clear segregation between code and configuration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core Application"
        MA["Main Application (main.cpp)"]:::core
        UI["User Interface (ui.cpp/ ui.h)"]:::core
        DR["Drawing Module (drawing.cpp/ drawing.h)"]:::core
        IN["Input Handling (input.cpp/ input.h)"]:::core
        FO["File Operations (file.cpp/ file.h)"]:::core
    end

    subgraph "Supporting Tools"
        EX["External Enhancer (Enhancer_GUI.py)"]:::utility
        BC["Build & Configuration (premake5 & raylib_premake5)"]:::utility
        AS["Assets & Demo (res/ & demo/)"]:::utility
        RM["Repository Management (.github/)"]:::utility
    end

    MA -->|"initializes"| UI
    MA -->|"handlesInput"| IN
    MA -->|"managesFiles"| FO
    UI -->|"rendersWith"| DR
    IN -->|"updatesCanvas"| DR
    UI -->|"fileOps"| FO
    UI -->|"integrates"| EX
    AS -->|"providesResources"| UI
    BC -->|"builds"| MA
    RM -->|"managesRepo"| BC

    click MA "https://github.com/datavorous/grudgepixel/blob/main/src/main.cpp"
    click UI "https://github.com/datavorous/grudgepixel/blob/main/include/ui.h"
    click UI "https://github.com/datavorous/grudgepixel/blob/main/src/ui.cpp"
    click DR "https://github.com/datavorous/grudgepixel/blob/main/include/drawing.h"
    click DR "https://github.com/datavorous/grudgepixel/blob/main/src/drawing.cpp"
    click IN "https://github.com/datavorous/grudgepixel/blob/main/include/input.h"
    click IN "https://github.com/datavorous/grudgepixel/blob/main/src/input.cpp"
    click FO "https://github.com/datavorous/grudgepixel/blob/main/include/file.h"
    click FO "https://github.com/datavorous/grudgepixel/blob/main/src/file.cpp"
    click EX "https://github.com/datavorous/grudgepixel/blob/main/Enhancer_GUI.py"
    click BC "https://github.com/datavorous/grudgepixel/blob/main/premake5.lua"
    click BC "https://github.com/datavorous/grudgepixel/blob/main/raylib_premake5.lua"
    click AS "https://github.com/datavorous/grudgepixel/tree/main/res/"
    click AS "https://github.com/datavorous/grudgepixel/tree/main/demo/"
    click RM "https://github.com/datavorous/grudgepixel/tree/main/.github/"

    classDef core fill:#FFDDC1,stroke:#FF7F50,stroke-width:2px;
    classDef utility fill:#C1FFD7,stroke:#32CD32,stroke-width:2px;
```
