# addyosmani/squish architecture

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

- Interactive diagram: https://gitdiagram.com/addyosmani/squish
- Repository: https://github.com/addyosmani/squish

## Overview

##### Project Type and Purpose
- This is a browser-only, full-stack-in-the-sense-of-client-only web application (no backend).
- Purpose: Provide a React+TypeScript UI that uses WebAssembly image codecs (via jSquash and related libs) to compress and convert images entirely in the browser.

##### Top-Level File Structure
- index.html / public: Static hosting root and assets.
- src/: Application code
- App.tsx, main.tsx: React entry points
- components/: UI building blocks (DropZone, ImageList, CompressionOptions, DownloadAll)
- hooks/: State and side-effect logic (useImageQueue, useImageProcessing)
- utils/: Low-level helpers (canvas operations, download logic, wasm loader, format defaults)
- types/: Shared TypeScript definitions and encoder interfaces
- Configuration: vite.config.ts, tsconfig*.json, tailwind.config.js, eslint.config.js

##### Key Architectural Patterns
- Component-based UI (React) with unidirectional data flow
- Custom React hooks encapsulating queue and processing logic
- Modular utils to isolate side effects (canvas, downloads, wasm loading)

##### Main Components
a. Browser Environment
- Container for entire system; hosts Vite dev server in development or static files in production.
b. UI Layer (React App)
- DropZone Component: Captures user file input
- CompressionOptions Component: Sets format/quality parameters
- ImageList Component: Displays queue and previews
- DownloadAll / Download Component: Triggers file downloads
c. State & Logic Layer (Hooks)
- useImageQueue: Manages file queue, order, batch logic
- useImageProcessing: Invokes utils + wasm for each file
d. Processing Layer (Utils + WASM)
- wasm.ts Loader: Dynamically imports jSquash codecs (MozJPEG, libavif, libjxl, Oxipng, WebP)
- canvas.ts & resize.ts: Prepare pixel data for encoding
- imageProcessing.ts: Orchestrates encode calls
- download.ts: Converts output buffer to Blob/URL for user download
e. External Dependencies
- jSquash / wasm modules (compiled from C/C++)
- Tailwind CSS for styling
- Vite as build & dev server

##### Relationships & Data Flow
- User → DropZone (UI) → queue hook → processing hook
- processing hook → utils / canvas → wasm encoder → result buffer
- result buffer → utils/download → browser file save
- CompressionOptions settings → processing hook → passed to wasm encoder
- ImageList subscribes to queue hook for real-time preview and stats

##### Essential Elements to Capture
- Component hierarchy (App → children components)
- Flow of image data from user input to final download
- Interaction between hooks and utils
- Dynamic loading of WebAssembly codecs
- Styling/build toolchain as supportive infrastructure (Tailwind, Vite)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Environment
    subgraph "Browser Environment"
        direction TB
        BE_index["index.html"]:::browser
        BE_public["public/ (static assets)"]:::browser
        BE_vite["vite.config.ts"]:::browser
    end

    %% UI Layer
    subgraph "UI Layer (React Components)"
        direction TB
        Main["main.tsx"]:::frontend
        App["App.tsx"]:::frontend
        Drop["DropZone.tsx"]:::frontend
        CompOpt["CompressionOptions.tsx"]:::frontend
        ImgList["ImageList.tsx"]:::frontend
        DownloadAll["DownloadAll.tsx"]:::frontend
    end

    %% State & Logic Layer
    subgraph "State & Logic (Hooks)"
        direction TB
        Queue["useImageQueue.ts"]:::hooks
        ProcHook["useImageProcessing.ts"]:::hooks
    end

    %% Processing & Utils
    subgraph "Processing & Utils"
        direction TB
        WasmLoader["wasm.ts"]:::wasm
        Canvas["canvas.ts"]:::utils
        Resize["resize.ts"]:::utils
        ImgProc["imageProcessing.ts"]:::utils
        DownloadUtil["download.ts"]:::utils
        FormatDef["formatDefaults.ts"]:::utils
    end

    %% Types & Interfaces
    subgraph "Types & Interfaces"
        direction TB
        SharedTypes["types.ts"]:::types
        Encoders["encoders.ts"]:::types
    end

    %% Build & Styling
    subgraph "Styling & Build Toolchain"
        direction TB
        TailwindConf["tailwind.config.js"]:::build
        PostCSS["postcss.config.js"]:::build
        ESLintConf["eslint.config.js"]:::build
        TSConfig["tsconfig*.json"]:::build
        ViteEnv["vite-env.d.ts"]:::build
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        JSquash["jSquash WASM Modules"]:::external
        TailwindCSS["Tailwind CSS"]:::external
        ViteDev["Vite Dev Server"]:::external
    end

    %% Connections
    BE_index --> Main
    BE_vite --> ViteDev
    ViteDev --> Main
    Main --> App
    App --> Drop
    App --> CompOpt
    App --> ImgList
    App --> DownloadAll

    Drop --> Queue
    CompOpt --> ProcHook
    ImgList --> Queue
    DownloadAll --> ProcHook

    Queue --> ProcHook
    ProcHook --> Canvas
    ProcHook --> Resize
    ProcHook --> ImgProc
    ProcHook --> DownloadUtil

    ImgProc --> WasmLoader
    WasmLoader --> JSquash
    DownloadUtil --> BE_public

    TailwindConf --> TailwindCSS

    SharedTypes --> Queue
    SharedTypes --> ProcHook
    Encoders --> WasmLoader

    %% Click Events
    click BE_index "https://github.com/addyosmani/squish/blob/main/index.html"
    click BE_public "https://github.com/addyosmani/squish/tree/main/public/"
    click BE_vite "https://github.com/addyosmani/squish/blob/main/vite.config.ts"
    click Main "https://github.com/addyosmani/squish/blob/main/src/main.tsx"
    click App "https://github.com/addyosmani/squish/blob/main/src/App.tsx"
    click Drop "https://github.com/addyosmani/squish/blob/main/src/components/DropZone.tsx"
    click CompOpt "https://github.com/addyosmani/squish/blob/main/src/components/CompressionOptions.tsx"
    click ImgList "https://github.com/addyosmani/squish/blob/main/src/components/ImageList.tsx"
    click DownloadAll "https://github.com/addyosmani/squish/blob/main/src/components/DownloadAll.tsx"
    click Queue "https://github.com/addyosmani/squish/blob/main/src/hooks/useImageQueue.ts"
    click ProcHook "https://github.com/addyosmani/squish/blob/main/src/hooks/useImageProcessing.ts"
    click WasmLoader "https://github.com/addyosmani/squish/blob/main/src/utils/wasm.ts"
    click Canvas "https://github.com/addyosmani/squish/blob/main/src/utils/canvas.ts"
    click Resize "https://github.com/addyosmani/squish/blob/main/src/utils/resize.ts"
    click ImgProc "https://github.com/addyosmani/squish/blob/main/src/utils/imageProcessing.ts"
    click DownloadUtil "https://github.com/addyosmani/squish/blob/main/src/utils/download.ts"
    click FormatDef "https://github.com/addyosmani/squish/blob/main/src/utils/formatDefaults.ts"
    click SharedTypes "https://github.com/addyosmani/squish/blob/main/src/types.ts"
    click Encoders "https://github.com/addyosmani/squish/blob/main/src/types/encoders.ts"
    click TailwindConf "https://github.com/addyosmani/squish/blob/main/tailwind.config.js"
    click PostCSS "https://github.com/addyosmani/squish/blob/main/postcss.config.js"
    click ESLintConf "https://github.com/addyosmani/squish/blob/main/eslint.config.js"
    click TSConfig "https://github.com/addyosmani/squish/blob/main/tsconfig.json"
    click ViteEnv "https://github.com/addyosmani/squish/blob/main/src/vite-env.d.ts"

    %% Styles
    classDef browser fill:#f0f8ff,stroke:#333,stroke-width:1px
    classDef frontend fill:#bbdefb,stroke:#333,stroke-width:1px
    classDef hooks fill:#c8e6c9,stroke:#333,stroke-width:1px
    classDef utils fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef wasm fill:#e1bee7,stroke:#333,stroke-width:1px
    classDef types fill:#d7ccc8,stroke:#333,stroke-width:1px
    classDef build fill:#f5f5f5,stroke:#333,stroke-width:1px
    classDef external fill:#eceff1,stroke:#333,stroke-width:1px
```
