How addyosmani/squish works
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)