# piskelapp/piskel architecture

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

- Interactive diagram: https://gitdiagram.com/piskelapp/piskel
- Repository: https://github.com/piskelapp/piskel

## Overview

##### Project Type and Purpose
- Piskel is a rich, single‑page, browser‑based sprite and pixel‑art editor, written entirely in JavaScript, HTML and CSS. It also provides a CLI for headless exporting (PNG, GIF, ZIP) and can be packaged as a desktop app via NW.js.

##### Top‑Level Components (based on file tree)
- Presentation Layer
– src/index.html + src/templates: HTML templates for dialogs, toolbars, previews
– src/js/lib: 3rd‑party libs (jQuery, Spectrum colorpicker, gif.js, jszip, bootstrap's tooltip, canvas‑toBlob shim)
- Application Layer (Controllers & Services)
– src/js/controller: MVC controllers driving UI interactions
– src/js/service: singleton services (History, Clipboard, Storage, Import/Export, Performance)
- Domain Model
– src/js/model: core domain objects (Piskel, Frame, Layer, Palette, Descriptors)
- Rendering Engine
– src/js/rendering: renderer abstractions (CanvasRenderer, OnionSkin, CompositeRenderer) and rendering loop
- Persistence & Storage
– src/js/database: local IndexedDB or LocalStorage abstractions, migration scripts
– src/js/service/storage: StorageService implementations (LocalStorage, IndexedDb, Desktop, Gallery, Download)
- Worker Layer
- Auxiliary
– bin/ & cli/: Node.js scripts to copy assets, headless export routines
– test/: end‑to‑end (CasperJS) and unit tests

##### Relationships & Data Flows
- User events (click, drag) → Controllers → update Model → Services persist changes → Rendering Engine draws on Canvas → UI updates
- Controllers invoke Services for side effects (undo/redo via HistoryService, file import via ImportService)
- Rendering Engine may hire Web Workers for CPU‑intensive tasks and get callbacks
- Templates are bound by Controllers to generate dialog HTML
- CLI scripts load Piskel “core” (model + rendering + services) in Node for headless export

##### Architectural Patterns and Principles
- MVC‑style separation: Controllers (UI logic) ↔ Models (state) ↔ Views/Templates (HTML)
- Service layer for cross‑cutting concerns (storage, history, keyboard shortcuts)
- Rendering pipeline with pluggable Renderer implementations
- Worker‑based concurrency to avoid main‐thread blocking
- Plugin‑style readers/writers in Palette and Serialization modules

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Presentation Layer
  subgraph "Presentation Layer"
    direction TB
    HTML["Index.html"]:::presentation
    Templates["HTML Templates"]:::presentation
    CSS["CSS Styles"]:::presentation
    Images["Images & Icons"]:::presentation
  end

  %% Application Layer
  subgraph "Controllers & Services"
    direction TB
    Controllers["MVC Controllers"]:::application
    Services["Singleton Services"]:::application
  end

  %% Domain Model
  subgraph "Domain Model"
    direction TB
    Model["Core Domain Objects"]:::domain
  end

  %% Rendering & Workers
  subgraph "Rendering & Workers"
    direction TB
    Renderer["Rendering Engine"]:::rendering
    Workers["Web Workers"]:::rendering
  end

  %% Persistence Layer
  subgraph "Persistence & Storage"
    direction TB
    Database[(Database Abstractions)]:::persistence
    Storage["StorageService Implementations"]:::persistence
  end

  %% External & CLI
  subgraph "External Libraries & CLI"
    direction TB
    Libs["3rd‑Party Libraries"]:::external
    CLI["CLI Headless Export"]:::external
    Bin["Auxiliary Scripts"]:::external
    Misc["Packaging Scripts"]:::external
    Tests["E2E & Unit Tests"]:::external
  end

  %% Data Flows
  User([User]):::external -->|"events"| Controllers
  Controllers -->|"updates"| Model
  Controllers -->|"calls"| Services
  Services -->|"persists"| Storage
  Storage -->|"uses"| Database
  Model -->|"renders"| Renderer
  Renderer -->|"offloads"| Workers
  Workers -->|"callbacks"| Renderer
  Renderer -->|"draws on"| HTML
  Controllers -->|"binds"| Templates
  CLI -->|"loads core"| Model
  CLI -->|"exports"| Bin

  %% Click Events
  click HTML "https://github.com/piskelapp/piskel/blob/master/src/index.html"
  click Templates "https://github.com/piskelapp/piskel/tree/master/src/templates/"
  click CSS "https://github.com/piskelapp/piskel/tree/master/src/css/"
  click Images "https://github.com/piskelapp/piskel/tree/master/src/img/"
  click Libs "https://github.com/piskelapp/piskel/tree/master/src/js/lib/"
  click Controllers "https://github.com/piskelapp/piskel/tree/master/src/js/controller/"
  click Services "https://github.com/piskelapp/piskel/tree/master/src/js/service/"
  click Model "https://github.com/piskelapp/piskel/tree/master/src/js/model/"
  click Renderer "https://github.com/piskelapp/piskel/tree/master/src/js/rendering/"
  click Workers "https://github.com/piskelapp/piskel/tree/master/src/js/worker/"
  click Database "https://github.com/piskelapp/piskel/tree/master/src/js/database/"
  click Storage "https://github.com/piskelapp/piskel/tree/master/src/js/service/storage/"
  click CLI "https://github.com/piskelapp/piskel/tree/master/cli/"
  click Bin "https://github.com/piskelapp/piskel/tree/master/bin/"
  click Misc "https://github.com/piskelapp/piskel/tree/master/misc/"
  click Tests "https://github.com/piskelapp/piskel/tree/master/test/"

  %% Styles
  classDef presentation fill:#ADD8E6,stroke:#1E90FF,color:#000
  classDef application fill:#90EE90,stroke:#008000,color:#000
  classDef domain fill:#FFFFE0,stroke:#DAA520,color:#000
  classDef rendering fill:#FFA500,stroke:#FF8C00,color:#000
  classDef persistence fill:#FFB6C1,stroke:#FF1493,color:#000
  classDef external fill:#D3D3D3,stroke:#A9A9A9,color:#000
```
