# faresbakhit/ayin architecture

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

- Interactive diagram: https://gitdiagram.com/faresbakhit/ayin
- Repository: https://github.com/faresbakhit/ayin

## Overview

##### Project's Nature and Purpose
- Ayin is a desktop photo editing application. It’s a GUI-based tool with image manipulation features (filters, multiple tabs, undo/redo) and uses external libraries like ImGui for the user interface, SDL2/OpenGL for rendering, and portable-file-dialogs and stb for file handling and image processing.
- The project is structured as a single application rather than a client-server or multi-service system.

##### File Structure for Architectural Clues
- Top-Level Elements: There are build/configuration files (.clang-format, Makefile, etc.), a README, and a LICENSE. This indicates standard project organization.
- lib Directory: Contains third-party libraries like ImGui, portable-file-dialogs, and stb. The ImGui subfolder also comes with examples and documentation. This tells us that ImGui is the primary UI toolkit with SDL2/OpenGL integration.
- src Directory: Contains the core application source code with files for the Application framework, Commands management (likely supporting undo/redo), Image manipulation (Image, ImageFilter), Photo abstraction, and others. This shows that the business logic and core functionality reside in “src.”

##### Main Components
a. UI/Presentation Layer:
- Uses ImGui (with SDL2 and OpenGL3 backends) to render the interface.
b. Application Core / Business Logic:
- Handled mostly in the src directory.
- Contains the Application class (initialization, main loop, event management).
- Implements Commands (for undo/redo functionality) and image editing tasks (Image, ImageFilter, Photo).
c. External Libraries & Utilities:
- ImGui (with its backends) provides the immediate mode GUI.
- portable-file-dialogs provides file open/save dialogs.
- stb libraries for image reading/writing.
- Utility modules under src/utils (e.g., win32.hpp) to handle platform-specific functionality.

##### Relationships and Interactions
- The UI Layer communicates with the Application Core: User input (via the UI) triggers commands and image processing.
- The Application Core maintains state (e.g., image data, command history) and integrates with various modules, such as the undo/redo system.
- External Libraries act as support modules:
- ImGui drives rendering and handles widget interactions.
- SDL2/OpenGL connectors enable cross-platform graphics.
- File-dialog and stb components handle file management and image I/O.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Differentiate clearly between UI (visual representation), core business logic (command processing, image filters), and file/image utilities.
- Modular Design: Each domain (UI, core logic, utilities) is distinct. This modularity allows easy swapping or updating of components like the UI toolkit or image libraries.
- Immediate Mode GUI Pattern: ImGui’s design is consistent with immediate mode – it redraws UI elements each frame based on the current state held in the core.

##### Final Reminder
- Use clear labels for each component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface"
        ImGui("ImGui (UI Toolkit)"):::frontend
        UIBack("ImGui Backends (SDL2/OpenGL3)"):::frontend
        UIAssetsMisc("UI Assets (misc/fonts)"):::frontend
        UIAssetsSrc("UI Assets (src/fonts)"):::frontend
    end

    subgraph "Application Core"
        Application("Application (Main Loop & Event Management)"):::core
        Commands("Commands (Undo/Redo)"):::core
        ImageProcessing("Image Processing (Image,ImageFilter,Photo)"):::core
    end

    subgraph "External Libraries & Utilities"
        FileDialogs("File Dialogs (portable-file-dialogs)"):::external
        ImageIO("Image I/O (stb)"):::external
        PlatformUtils("Platform Utils (win32.hpp)"):::external
    end

    UIAssetsMisc -->|"supplies_assets"| ImGui
    UIAssetsSrc -->|"supplies_assets"| ImGui
    UIBack -->|"integrates_with"| ImGui

    ImGui -->|"receives_user_events"| Application
    Application -->|"updates_UI"| ImGui

    Application -->|"executes"| Commands
    Application -->|"calls"| ImageProcessing

    Application -->|"uses"| FileDialogs
    Application -->|"uses"| ImageIO
    Application -->|"accesses"| PlatformUtils

    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef core fill:#C1E1C1,stroke:#000,stroke-width:2px;
    classDef external fill:#FFDAB9,stroke:#000,stroke-width:2px;

    click ImGui "https://github.com/faresbakhit/ayin/tree/main/lib/imgui"
    click UIBack "https://github.com/faresbakhit/ayin/tree/main/lib/imgui/backends"
    click UIAssetsMisc "https://github.com/faresbakhit/ayin/tree/main/misc/fonts"
    click UIAssetsSrc "https://github.com/faresbakhit/ayin/tree/main/src/fonts"

    click Application "https://github.com/faresbakhit/ayin/blob/main/src/Application.cpp"
    click Commands "https://github.com/faresbakhit/ayin/blob/main/src/Commands.cpp"
    click ImageProcessing "https://github.com/faresbakhit/ayin/blob/main/src/Image.cpp"

    click FileDialogs "https://github.com/faresbakhit/ayin/tree/main/lib/portable-file-dialogs"
    click ImageIO "https://github.com/faresbakhit/ayin/tree/main/lib/stb"
    click PlatformUtils "https://github.com/faresbakhit/ayin/blob/main/src/utils/win32.hpp"
```
