# 0x04/emoji-paint architecture

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

- Interactive diagram: https://gitdiagram.com/0x04/emoji-paint
- Repository: https://github.com/0x04/emoji-paint

## Overview

##### Project Type & Purpose
- The project is a front-end, single-page web application (webtoy) that provides a drawing experience with emoji.
- It is built entirely with vanilla JavaScript (ECMAScript 2024) and vanilla CSS, with no heavy external frameworks.
- It’s intended to run as a standalone HTML file, be embeddable/injectable as an <object> or <iframe>, and even be executed on the desktop.

##### Core Components
- Main JavaScript Entry (main.mjs): Orchestrates initialization and module integration.
- Components: Under the src/components folder you have all the visual pieces of the UI:
- Canvas: Handles the drawing area.
- Toolbars (toolbar and toolbar-top): Likely offer various drawing controls.
- Metrics and Paint: Possibly display real-time drawing stats and control painting events.
- Classes: In src/classes, contains core data structures (e.g., Point, Rectangle, Collection) and logic modules (such as mouse-grid and persistent-store) that model the behavior of drawing elements and their interactions.
- Constants: In src/constants, these files define global values:
- Stores: In the src/stores folder, state management modules (for canvas and palette) are maintained for reactive updates across components.

##### Relations and Interactions
- The main entry (main.mjs) ties together the initialization for various components.
- The UI components (canvas, toolbars, palette selectors) interact with the underlying state (stores) to update the display and respond to user input.
- Data models (classes like Point, Rectangle, etc.) support the drawing operations and interactions. For instance, the canvas component will use these models for rendering drawings based on user actions.
- Utility functions and tools are invoked by UI components or stores when certain events are triggered (e.g., copying to clipboard, matching emojis).

##### Architectural and Design Principles
- Separation of Concerns: The project logically separates view elements (in components), business/data logic (in classes and stores), and constants/configuration.
- Modularity: Independent modules in directories (classes, components, stores, functions, tools) interact to keep the architecture clean.
- Single Source of Truth: The use of stores (canvas-store and palette-store) suggests a central state management approach even within a vanilla JS context.
- Embeddability: The simplified project structure (with a single HTML file and minimal dependency on external libraries) enhances ease of embedding.

##### Final Touches
- That all components (UI, business logic, state, utility tools) are represented and visibly connected with clear labels.
- Detailing internal relationships (for instance, how the canvas component uses the persistent store for saving drawing data) so that every essential module is accounted for.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        A["HTML Container (index.html)"]:::ui
        B["Main Entry (main.mjs)"]:::ui
        A --> B
        subgraph "UI Components"
            C["Canvas Component"]:::ui
            D["Palette Component"]:::ui
            E["Palette Editor"]:::ui
            F["Palette Selection"]:::ui
            G["Palette Dropdown"]:::ui
            H["Toolbar"]:::ui
            I["Toolbar Top"]:::ui
            J["Metrics"]:::ui
            K["Paint"]:::ui
        end
        B --> C
        B --> D
        B --> E
        B --> F
        B --> G
        B --> H
        B --> I
        B --> J
        B --> K
    end

    %% Business Logic
    subgraph "Business Logic"
        subgraph "Data Models"
            L["Point"]:::business
            M["Rectangle"]:::business
            N["Collection"]:::business
            O["Mouse Grid"]:::business
            P["Persistent Store"]:::business
            Q["Store"]:::business
        end
        subgraph "Constants"
            R["Draw Functions"]:::business
            S["Globals"]:::business
            T["Palettes"]:::business
            U["Version String"]:::business
        end
    end

    %% Utility Functions
    subgraph "Utility Functions"
        V["Copy To Clipboard"]:::utility
        W["Is Emoji"]:::utility
        X["Match Emojis"]:::utility
    end

    %% Tools
    subgraph "Tools"
        Y["Draw Tool"]:::tools
        Z["Tool"]:::tools
    end

    %% State Management
    subgraph "State Management"
        AA["Canvas Store"]:::state
        AB["Palette Store"]:::state
        AC["Stores"]:::state
    end

    %% Connections from Main Entry to Business Logic, Utilities, and Tools
    B --> R
    B --> S
    B --> T
    B --> U
    B --> V
    B --> Y
    B --> Z

    %% UI Components interactions with Business Logic and State Management
    C -->|"uses"| L
    C --> M
    C --> N
    C --> O
    C --> P
    C --> Q
    C --> AA

    D --> AB
    E --> AB
    F --> AB
    G --> AB

    H --> AA
    I --> AA

    J --> AC
    K --> AA

    %% Utility interaction example
    F --> X

    %% Aggregating State Management
    AA --> AC
    AB --> AC

    %% Styling
    classDef ui fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef business fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef state fill:#ffcccb,stroke:#000,stroke-width:2px;
    classDef utility fill:#ffeb99,stroke:#000,stroke-width:2px;
    classDef tools fill:#b3d9ff,stroke:#000,stroke-width:2px;

    %% Click Events
    click A "https://github.com/0x04/emoji-paint/blob/main/index.html"
    click B "https://github.com/0x04/emoji-paint/blob/main/main.mjs"
    click C "https://github.com/0x04/emoji-paint/blob/main/src/components/canvas.mjs"
    click D "https://github.com/0x04/emoji-paint/blob/main/src/components/palette.mjs"
    click E "https://github.com/0x04/emoji-paint/blob/main/src/components/palette-editor.mjs"
    click F "https://github.com/0x04/emoji-paint/blob/main/src/components/palette-selection.mjs"
    click G "https://github.com/0x04/emoji-paint/blob/main/src/components/palette-dropdown.mjs"
    click H "https://github.com/0x04/emoji-paint/blob/main/src/components/toolbar.mjs"
    click I "https://github.com/0x04/emoji-paint/blob/main/src/components/toolbar-top.mjs"
    click J "https://github.com/0x04/emoji-paint/blob/main/src/components/metrics.mjs"
    click K "https://github.com/0x04/emoji-paint/blob/main/src/components/paint.mjs"
    click L "https://github.com/0x04/emoji-paint/blob/main/src/classes/point.mjs"
    click M "https://github.com/0x04/emoji-paint/blob/main/src/classes/rectangle.mjs"
    click N "https://github.com/0x04/emoji-paint/blob/main/src/classes/collection.js"
    click O "https://github.com/0x04/emoji-paint/blob/main/src/classes/mouse-grid.mjs"
    click P "https://github.com/0x04/emoji-paint/blob/main/src/classes/persistent-store.mjs"
    click Q "https://github.com/0x04/emoji-paint/blob/main/src/classes/store.mjs"
    click R "https://github.com/0x04/emoji-paint/blob/main/src/constants/draw-functions.mjs"
    click S "https://github.com/0x04/emoji-paint/blob/main/src/constants/globals.mjs"
    click T "https://github.com/0x04/emoji-paint/blob/main/src/constants/palettes.mjs"
    click U "https://github.com/0x04/emoji-paint/blob/main/src/constants/versionString.mjs"
    click AA "https://github.com/0x04/emoji-paint/blob/main/src/stores/canvas-store.mjs"
    click AB "https://github.com/0x04/emoji-paint/blob/main/src/stores/palette-store.mjs"
    click AC "https://github.com/0x04/emoji-paint/blob/main/src/stores/stores.mjs"
    click V "https://github.com/0x04/emoji-paint/blob/main/src/functions/copy-to-clipboard.mjs"
    click W "https://github.com/0x04/emoji-paint/blob/main/src/functions/is-emoji.mjs"
    click X "https://github.com/0x04/emoji-paint/blob/main/src/functions/match-emojis.mjs"
    click Y "https://github.com/0x04/emoji-paint/blob/main/src/tools/draw-tool.mjs"
    click Z "https://github.com/0x04/emoji-paint/blob/main/src/tools/tool.mjs"
```
