# hundredrabbits/dotgrid architecture

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

- Interactive diagram: https://gitdiagram.com/hundredrabbits/dotgrid
- Repository: https://github.com/hundredrabbits/dotgrid

## Overview

##### Project type and purpose
- Dotgrid is a single-page, front-end web application (no separate backend).
- Its purpose is to provide a grid-based vector drawing environment in the browser, supporting SVG, PNG export, multiple layers, mirroring, radial drawing, and a variety of drawing tools.

##### File structure
- Top-level:
- index.html – the single entry point
- links/*.css – styling (main.css, theme.css)
- scripts/ – all application logic
- scripts/ is divided into:
- core modules (manager.js, renderer.js, tool.js, picker.js, interface.js, generator.js, cursor.js, client.js)
- lib/ – shared utilities (acels.js, build.js, history.js, source.js, theme.js)
- push.sh, LICENSEs, README.txt: deployment and documentation—but no server-side code.

##### README for additional insights
- Confirms front-end only, open-source under MIT.
- Describes features (layers, SVG spec, effects) but no mention of a backend or external APIs other than file download.

##### Main components
a. Browser / Frontend Container
b. User Interface Layer
- HTML (index.html)
- CSS themes (links/main.css, links/theme.css)
c. Input & Event Handling
- scripts/client.js (keyboard/mouse event capture)
- scripts/lib/acels.js (keyboard accelerators)
d. Tool Management
- scripts/tool.js (tool selection, stroke modes)
- scripts/cursor.js (cursor updates)
e. Application State & History
- scripts/manager.js (document state, layers, grid)
- scripts/lib/history.js (undo/redo stack)
f. Rendering Engine
- scripts/generator.js (generate radial/mirror effects)
g. Export Module
- scripts/lib/source.js (assemble SVG source)
- scripts/client.js or build.js (trigger PNG export, download)
h. Theming & Configuration
- scripts/lib/theme.js (load/reset theme)
i. Build & Deployment (optional)
- scripts/lib/build.js
- push.sh (deployment script)

##### Relationships & data flows
- User → UI Layer → Input Handler → Tool Manager → App State
- App State → Rendering Engine → Canvas Display
- App State → History Module (undo/redo)
- App State → Export Module → File Download (SVG/PNG)
- Theme Module ↔ UI Layer

##### Architectural patterns & design principles
- Modular, client-side MVC style:
- “Controller” → client.js + tool.js
- “Model” → manager.js + history.js
- “View” → renderer.js + generator.js
- Event-driven: input events drive state changes and re-render.
- Separation of concerns:
- lib/ for reusable utilities
- core scripts for domain logic

##### Essential elements to capture
- All scripts in their logical groups (interface, tool, manager, renderer, lib)
- The CSS/theme subsystem and index.html as entry point
- Data flow from user events through state to rendering and export
- Undo/redo and theming as cross-cutting concerns

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser Boundary"
        direction TB

        subgraph "UI Layer"
            direction TB
            UI["index.html"]:::ui
            mainCss["main.css"]:::ui
            themeCss["theme.css"]:::ui
            interfaceLogic["interface.js"]:::core
        end

        subgraph "Input & Event Handling"
            direction TB
            client["client.js"]:::core
            acels["acels.js"]:::util
        end

        subgraph "Tool Management"
            direction TB
            tool["tool.js"]:::core
            picker["picker.js"]:::core
            cursor["cursor.js"]:::core
        end

        subgraph "Application State & History"
            direction TB
            manager["manager.js"]:::core
            history["history.js"]:::util
        end

        subgraph "Rendering Engine & Effects"
            direction TB
            renderer["renderer.js"]:::core
            generator["generator.js"]:::core
            Canvas["Canvas/SVG Display"]:::core
        end

        subgraph "Export Module"
            direction TB
            source["source.js"]:::util
        end

        subgraph "Theming & Configuration"
            direction TB
            themeLib["theme.js"]:::util
        end

        subgraph "Build & Deployment"
            direction TB
            build["build.js"]:::util
            push["push.sh"]:::util
        end
    end

    %% Relationships
    User["User"]:::external --> UI
    UI --> interfaceLogic
    interfaceLogic --> client
    client --> acels
    client --> tool
    tool --> picker
    tool --> cursor
    tool --> manager
    manager -.-> history
    manager --> renderer
    manager --> generator
    renderer --> Canvas
    generator --> Canvas
    manager --> source
    source --> client
    themeLib --> UI
    build --> push

    %% Click Events
    click UI "https://github.com/hundredrabbits/dotgrid/blob/master/index.html"
    click mainCss "https://github.com/hundredrabbits/dotgrid/blob/master/links/main.css"
    click themeCss "https://github.com/hundredrabbits/dotgrid/blob/master/links/theme.css"
    click interfaceLogic "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/interface.js"
    click client "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/client.js"
    click acels "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/lib/acels.js"
    click tool "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/tool.js"
    click picker "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/picker.js"
    click cursor "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/cursor.js"
    click manager "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/manager.js"
    click history "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/lib/history.js"
    click renderer "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/renderer.js"
    click generator "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/generator.js"
    click source "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/lib/source.js"
    click themeLib "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/lib/theme.js"
    click build "https://github.com/hundredrabbits/dotgrid/blob/master/scripts/lib/build.js"
    click push "https://github.com/hundredrabbits/dotgrid/blob/master/push.sh"

    %% Styles
    classDef ui fill:#cfe2f3,stroke:#036; 
    classDef core fill:#d9ead3,stroke:#093;
    classDef util fill:#eeeeee,stroke:#666;
    classDef external fill:#fff2cc,stroke:#e69138;
```
