# xdadda/mini-photo-editor architecture

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

- Interactive diagram: https://gitdiagram.com/xdadda/mini-photo-editor
- Repository: https://github.com/xdadda/mini-photo-editor

## Overview

##### Project type and purpose
- From the file tree and README, this is a single-page, client-side, WebGL2-powered image editor (“mini-img-editor”).
- It uses Vite as the build tool, mini-js for UI utilities, and mini-gl for WebGL abstractions. The entire app lives in the browser—there is no backend service.

##### File structure
- Top-level:
- src/ → source code
- vite.config.js → build configuration
- src/ subdivided into:
- components/ → React-style, self-contained UI components (cropper, colorcurve, histogram, etc.)
- js/ → lower-level utilities (tools.js, zoom_pan.js)
- “_”-prefixed modules → core image-processing routines (filters, curves, composition, adjustments)
- main.js + app.js + CSS files → application entrypoints and global styling

##### Key insights from the README
- It’s deployed as a static site (Netlify link)
- Powered by two core libraries (mini-js, mini-gl) for UI and WebGL respectively
- In-browser photo editing via WebGL2

a. Main components to represent
- Browser UI Layer
– State & routing (mini-js)
- Image Processing Layer
– Core modules: _adjustments.js, _composition.js, _curves.js, _filters.js
– WebGL2 rendering context (mini-gl) + shaders
– LUT assets
– Web Worker (histogram_worker.js)
- Build & Deployment
– Vite bundler (vite.config.js) → produces index.html + bundled JS/CSS in public/
– Netlify (static hosting)
- External Libraries
– mini-js
– mini-gl

b. Relationships & interactions
1. User interacts with UI components → dispatches events to app.js
2. app.js coordinates data:
– Loads image into WebGL texture
– Routes parameter changes to core modules
3. Core modules feed into mini-gl context → shader execution → framebuffers → canvas
4. Histogram module offloaded to Web Worker → posts results back to UI
5. DownloadImage component reads final canvas output → triggers file save
6. Vite handles dev server and bundling; public/ assets injected at build time

c. Architectural patterns & principles
- Component-based UI
- Separation of concerns:
- Presentation (components + state)
- Business logic (JS tools + processing modules)
- Rendering (WebGL)
- Offload compute-heavy tasks (histogram) to Web Worker
- Static, client-only deployment

d. Key technologies/frameworks
- WebGL2 (via mini-gl)
- mini-js (lightweight UI state management)
- Vite (build tool)
- Web Worker API
- ES modules + modern CSS modules

##### Summary checklist
- [ ] UI layer with individual components
- [ ] Core image-processing modules
- [ ] WebGL2 context (mini-gl) and LUT assets
- [ ] Web Worker for histogram
- [ ] Build & Deployment (Vite + Netlify)
- [ ] External libraries (mini-js, mini-gl)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Browser UI Layer
    subgraph "Browser UI Layer"
        direction TB
        ClickDrop["Click/Drop File Component"]:::ui
        Cropper["Cropper Component"]:::ui
        ColorCurve["Color Curve Component"]:::ui
        FiltersPanel["Filters Panel Component"]:::ui
        SplitView["Split-View Component"]:::ui
        DownloadImage["Download Image Component"]:::ui
        GPSMap["GPS Map Component"]:::ui
        ThemeToggle["Theme Toggle Component"]:::ui
        HistogramUI["Histogram UI Component"]:::ui
        PerspectiveTool["Perspective Tool Component"]:::ui
        AppState["State & Routing (app.js)"]:::ui
    end

    %% Image Processing Layer
    subgraph "Image Processing Layer"
        direction TB
        Adjustments["_adjustments.js"]:::processing
        Composition["_composition.js"]:::processing
        Curves["_curves.js"]:::processing
        Filters["_filters.js"]:::processing
        Tools["tools.js"]:::processing
        ZoomPan["zoom_pan.js"]:::processing
        HistogramWorker["Web Worker (histogram_worker.js)"]:::processing
    end

    %% Rendering Layer
    subgraph "Rendering Layer"
        direction TB
        WebGL["WebGL2 Context (mini-gl)"]:::rendering
        LUT["LUT Assets (src/assets/LUT/)"]:::rendering
        Canvas["Canvas Output"]:::rendering
    end

    %% Build & Deployment
    subgraph "Build & Deployment"
        direction TB
        ViteConfig["vite.config.js"]:::build
        HTML["index.html"]:::build
        Public["public/"]:::build
        Netlify["Netlify (Static Hosting)"]:::build
    end

    %% External Libraries
    subgraph "External Libraries"
        direction TB
        MiniJS["mini-js"]:::external
        MiniGL["mini-gl"]:::external
        Vite["Vite"]:::external
    end

    %% Application Entry
    Main["main.js"]:::ui

    %% Connections
    ClickDrop -->|"user event"| AppState
    Cropper -->|"user event"| AppState
    ColorCurve -->|"user event"| AppState
    FiltersPanel -->|"user event"| AppState
    SplitView -->|"user event"| AppState
    DownloadImage -->|"user action"| Canvas
    GPSMap -->|"user event"| AppState
    ThemeToggle -->|"user event"| AppState
    HistogramUI -->|"requests histogram"| HistogramWorker
    PerspectiveTool -->|"user event"| AppState

    AppState -->|"loads image & routes params"| Adjustments
    AppState --> Composition
    AppState --> Curves
    AppState --> Filters
    AppState --> Tools
    AppState --> ZoomPan

    Adjustments --> WebGL
    Composition --> WebGL
    Curves --> WebGL
    Filters --> WebGL
    Tools --> WebGL
    ZoomPan --> WebGL

    HistogramWorker -->|"posts data"| HistogramUI

    WebGL --> Canvas
    LUT --> WebGL

    Main --> AppState
    Main --> WebGL
    Main --> LUT

    ViteConfig --> HTML
    ViteConfig --> Public
    HTML --> Public
    Public --> Netlify

    MiniJS --> AppState
    MiniGL --> WebGL
    Vite --> ViteConfig

    %% Click Events
    click ClickDrop "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/clickdropFile.js"
    click Cropper "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/cropper.js"
    click Cropper "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/cropper.css"
    click ColorCurve "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/colorcurve.js"
    click ColorCurve "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/colorcurve.css"
    click FiltersPanel "https://github.com/xdadda/mini-photo-editor/blob/main/src/_filters.js"
    click SplitView "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/splitview.js"
    click SplitView "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/splitview.css"
    click DownloadImage "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/downloadImage.js"
    click GPSMap "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/gpsmap.js"
    click ThemeToggle "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/themetoggle.js"
    click HistogramUI "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/histogram.js"
    click HistogramWorker "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/histogram_worker.js"
    click PerspectiveTool "https://github.com/xdadda/mini-photo-editor/blob/main/src/components/perspective.js"
    click AppState "https://github.com/xdadda/mini-photo-editor/blob/main/src/app.js"
    click Main "https://github.com/xdadda/mini-photo-editor/blob/main/src/main.js"
    click Adjustments "https://github.com/xdadda/mini-photo-editor/blob/main/src/_adjustments.js"
    click Composition "https://github.com/xdadda/mini-photo-editor/blob/main/src/_composition.js"
    click Curves "https://github.com/xdadda/mini-photo-editor/blob/main/src/_curves.js"
    click Filters "https://github.com/xdadda/mini-photo-editor/blob/main/src/_filters.js"
    click Tools "https://github.com/xdadda/mini-photo-editor/blob/main/src/js/tools.js"
    click ZoomPan "https://github.com/xdadda/mini-photo-editor/blob/main/src/js/zoom_pan.js"
    click LUT "https://github.com/xdadda/mini-photo-editor/tree/main/src/assets/LUT/"
    click ViteConfig "https://github.com/xdadda/mini-photo-editor/blob/main/vite.config.js"
    click HTML "https://github.com/xdadda/mini-photo-editor/blob/main/index.html"
    click Public "https://github.com/xdadda/mini-photo-editor/tree/main/public/"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085
    classDef processing fill:#d4edda,stroke:#155724
    classDef rendering fill:#ffe5b4,stroke:#856404
    classDef build fill:#e2e3e5,stroke:#6c757d
    classDef external fill:#f8d7da,stroke:#721c24
```
