# jamestomasino/stitchy architecture

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

- Interactive diagram: https://gitdiagram.com/jamestomasino/stitchy
- Repository: https://github.com/jamestomasino/stitchy

## Overview

#### Purpose
Stitchy is a browser-based crochet-pattern generator. It lets a user place an uploaded image over a rectangular grid, transform it, reduce each grid cell to a color treatment, manually adjust cells, and print/save the resulting pattern.

#### Entry Point and Runtime
`index.html` is the application entry point and hosts the UI plus the drawing surface. The app runs entirely in the browser with client-side JavaScript and CSS:
- `index.html`
- `scripts.js`
- `styles.css`

There is no server-side code, database, build system, or deployment infrastructure represented in the repository.

#### UI and Pattern Workspace
The page provides controls for defining grid dimensions, loading an image, selecting processing behavior, and output actions. `styles.css` owns presentation while `scripts.js` coordinates UI events with canvas/grid updates.
- `index.html`
- `styles.css`
- `scripts.js`

#### Grid and Image-Transformation Stage
The central workspace is a grid overlaid on an image. User-controlled rotate, scale, and transform operations determine how source pixels align with grid cells before pattern generation. This stage is the key boundary between source-image manipulation and discrete stitch-cell output.
- `scripts.js`
- `index.html`

#### Color Sampling and Cell Rendering
Pattern processing converts image areas corresponding to grid blocks into rendered cell colors. Supported modes include black-and-white conversion and dominant-color extraction per block. The resulting grid is the editable, printable artifact.
- `scripts.js`
- `color-thief.umd.js`
- `nearestColor.js`

#### Palette Quantization and Manual Editing
Dominant/sample colors are mapped to usable palette colors through the bundled nearest-color implementation. Rendered cells can then be clicked to cycle through palette options, allowing manual correction after automated processing.
- `nearestColor.js`
- `scripts.js`

#### External Client-Side Libraries
The repository includes local browser-ready color-processing libraries:
- `color-thief.umd.js` supplies dominant-color extraction.
- `nearestColor.js` supplies nearest-palette matching.

The README also identifies Konva as the canvas/interaction library used by the application; its integration is expected through the page/scripts rather than a tracked package manifest.
- `color-thief.umd.js`
- `nearestColor.js`
- `index.html`

#### Output Boundary
The final rendered grid is exported through browser print/save behavior. Output is generated from the client-side workspace rather than persisted to a backend.
- `scripts.js`
- `index.html`

Main entry points: [`scripts.js`](https://github.com/jamestomasino/stitchy/blob/master/scripts.js) (Block color sampling), [`index.html`](https://github.com/jamestomasino/stitchy/blob/master/index.html) (Application page), [`styles.css`](https://github.com/jamestomasino/stitchy/blob/master/styles.css) (Presentation), [`color-thief.umd.js`](https://github.com/jamestomasino/stitchy/blob/master/color-thief.umd.js) (Dominant color extractor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser application"]
  node_page["Application page<br/>HTML entry point<br/>[index.html]"]
  node_ui["Pattern controls<br/>UI workspace<br/>[index.html]"]
  node_styles["Presentation<br/>CSS<br/>[styles.css]"]
  node_app{{"App coordinator<br/>browser JavaScript<br/>[scripts.js]"}}
  node_output["Print / save<br/>browser output<br/>[scripts.js]"]
end

subgraph group_processing["Pattern processing"]
  node_source["Uploaded image<br/>browser file input<br/>[index.html]"]
  node_transform["Image transform<br/>grid alignment<br/>[scripts.js]"]
  node_sampling["Block color sampling<br/>pattern generator<br/>[scripts.js]"]
  node_color_thief{{"Dominant color extractor<br/>client-side library<br/>[color-thief.umd.js]"}}
  node_quantizer{{"Palette matcher<br/>client-side library<br/>[nearestColor.js]"}}
  node_grid["Editable stitch grid<br/>rendered pattern<br/>[scripts.js]"]
  node_editing["Cell correction<br/>click editing<br/>[scripts.js]"]
end

node_page -->|"hosts"| node_ui
node_page -->|"loads"| node_app
node_page -->|"applies"| node_styles
node_ui -->|"selects"| node_source
node_ui -->|"events"| node_app
node_source -->|"image"| node_transform
node_app -->|"controls"| node_transform
node_transform -->|"aligned pixels"| node_sampling
node_sampling -->|"extracts dominant colors"| node_color_thief
node_sampling -->|"matches palette"| node_quantizer
node_sampling -->|"renders cells"| node_grid
node_grid -->|"clickable cells"| node_editing
node_editing -->|"updates color"| node_grid
node_grid -->|"print / save"| node_output

click node_page "https://github.com/jamestomasino/stitchy/blob/master/index.html"
click node_ui "https://github.com/jamestomasino/stitchy/blob/master/index.html"
click node_styles "https://github.com/jamestomasino/stitchy/blob/master/styles.css"
click node_app "https://github.com/jamestomasino/stitchy/blob/master/scripts.js"
click node_source "https://github.com/jamestomasino/stitchy/blob/master/index.html"
click node_transform "https://github.com/jamestomasino/stitchy/blob/master/scripts.js"
click node_sampling "https://github.com/jamestomasino/stitchy/blob/master/scripts.js"
click node_color_thief "https://github.com/jamestomasino/stitchy/blob/master/color-thief.umd.js"
click node_quantizer "https://github.com/jamestomasino/stitchy/blob/master/nearestColor.js"
click node_grid "https://github.com/jamestomasino/stitchy/blob/master/scripts.js"
click node_editing "https://github.com/jamestomasino/stitchy/blob/master/scripts.js"
click node_output "https://github.com/jamestomasino/stitchy/blob/master/scripts.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_page,node_ui,node_styles,node_app,node_output toneBlue
class node_source,node_transform,node_sampling,node_color_thief,node_quantizer,node_grid,node_editing toneAmber
```

## Components

### Browser application

Entire application runs client-side.

- [Application page](https://github.com/jamestomasino/stitchy/blob/master/index.html): HTML entry point · Hosts controls and drawing surface. · `index.html`
- [Pattern controls](https://github.com/jamestomasino/stitchy/blob/master/index.html): UI workspace · Grid, image, processing, and output controls. · `index.html`
- [Presentation](https://github.com/jamestomasino/stitchy/blob/master/styles.css): CSS · `styles.css`
- [App coordinator](https://github.com/jamestomasino/stitchy/blob/master/scripts.js): browser JavaScript · Coordinates events, canvas updates, editing, and output. · `scripts.js`
- [Print / save](https://github.com/jamestomasino/stitchy/blob/master/scripts.js): browser output · Exports the client-side rendered pattern. · `scripts.js`

### Pattern processing

Transforms source imagery into editable stitch cells.

- [Uploaded image](https://github.com/jamestomasino/stitchy/blob/master/index.html): browser file input · `index.html`
- [Image transform](https://github.com/jamestomasino/stitchy/blob/master/scripts.js): grid alignment · Applies rotation, scale, and positioning before sampling. · `scripts.js`
- [Block color sampling](https://github.com/jamestomasino/stitchy/blob/master/scripts.js): pattern generator · Converts image blocks into black-and-white or dominant colors. · `scripts.js`
- [Dominant color extractor](https://github.com/jamestomasino/stitchy/blob/master/color-thief.umd.js): client-side library · `color-thief.umd.js`
- [Palette matcher](https://github.com/jamestomasino/stitchy/blob/master/nearestColor.js): client-side library · Maps sampled colors to nearest palette colors. · `nearestColor.js`
- [Editable stitch grid](https://github.com/jamestomasino/stitchy/blob/master/scripts.js): rendered pattern · Printable cell-based pattern artifact. · `scripts.js`
- [Cell correction](https://github.com/jamestomasino/stitchy/blob/master/scripts.js): click editing · Cycles a cell through palette options. · `scripts.js`

## Connections

- Application page → Pattern controls: hosts
- Application page → App coordinator: loads
- Application page → Presentation: applies
- Pattern controls → Uploaded image: selects
- Pattern controls → App coordinator: events
- Uploaded image → Image transform: image
- App coordinator → Image transform: controls
- Image transform → Block color sampling: aligned pixels
- Block color sampling → Dominant color extractor: extracts dominant colors
- Block color sampling → Palette matcher: matches palette
- Block color sampling → Editable stitch grid: renders cells
- Editable stitch grid → Cell correction: clickable cells
- Cell correction → Editable stitch grid: updates color
- Editable stitch grid → Print / save: print / save
