# gladtek/squish architecture

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

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

## Overview

##### Project Type & Purpose
- Squish is a full-stack (client-only) web application built using React & TypeScript. Its main purpose is to allow users to compress images in the browser without needing server uploads.
- The project uses modern web technologies including Vite, Tailwind CSS, and WebAssembly-based image codecs (e.g., via jSquash). It supports several image formats (AVIF, JPEG, JPEG XL, PNG, and WebP).

##### Analyzing the File Structure
- Top-Level Files: You have configuration files (e.g., eslint.config.js, tailwind.config.js, vite.config.ts) and root files (index.html, README.md, package.json) that set up the project environment.
- src Directory: This is where all the application logic lives.
- App.tsx: The main entry point for the React application.
- components: Contains core UI components:
▪ DropZone.tsx – handles the drag and drop or file selection interface.
▪ ImageList.tsx – displays images loaded by the user.
▪ CompressionOptions.tsx – provides controls for adjusting quality/format settings.
▪ DownloadAll.tsx – supports downloading processed images in batch.
- hooks: Custom React hooks (useImageProcessing.ts, useImageQueue.ts) that manage the image processing workflow and the smart queue functionality.
- utils: Utility functions that perform various tasks:
▪ canvas.ts, resize.ts – likely used for image manipulation.
▪ imageProcessing.ts – integrates with compression algorithms.
▪ wasm.ts – acts as an interface to WebAssembly modules for high-performance processing.
▪ download.ts and formatDefaults.ts – possibly handle downloads and default configuration values.
- types: Contains type definitions used throughout the codebase (which includes specialized types for image encoders).

##### Key Components & Their Interactions
- User Interface (Frontend):
- The UI is composed of React components (DropZone, ImageList, CompressionOptions, DownloadAll) managed by App.tsx.
- These components collect user input (drag and drop, quality selection) and display real-time previews and statistics.
- Business Logic / Hooks:
- Custom hooks (useImageProcessing and useImageQueue) serve as the intermediary between the UI and the processing utilities. They manage state, handle the processing queue, and trigger image compression tasks.
- Utility Functions & WebAssembly:
- Utility functions (canvas operations, image resizing, processing, and downloading) abstract the image manipulation logic.
- The wasm.ts file abstracts the interaction with WebAssembly modules, which execute high-performance image compression tasks by interfacing with native libraries (jSquash, MozJPEG, libavif, libjxl, Oxipng).
- External Dependencies:
- Libraries, frameworks, and codecs (React, WebAssembly codecs via jSquash, Tailwind CSS, etc.) should be depicted as external services or dependencies interacting with the internal modules.

##### Final Step – Create & Annotate
▪ UI Layer: Components – App.tsx with DropZone, ImageList, CompressionOptions, DownloadAll.
▪ Business Logic: Hooks – useImageProcessing and useImageQueue.
▪ Processing Utilities: Utility functions for canvas, resizing, downloads, and the wasm interface.
▪ External Dependencies: WebAssembly-based codecs and libraries (jSquash, MozJPEG, etc.).
▪ How data flows from user actions to processed outcomes.
▪ Any critical integration points (e.g., switching between image formats and quality settings).

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "User Interface"
        A["App Component"]:::ui
        B["DropZone Component"]:::ui
        C["ImageList Component"]:::ui
        D["CompressionOptions Component"]:::ui
        E["DownloadAll Component"]:::ui
    end

    %% Business Logic / Custom Hooks
    subgraph "Business Logic"
        F["useImageProcessing Hook"]:::business
        G["useImageQueue Hook"]:::business
    end

    %% Utility Functions & WebAssembly Interface
    subgraph "Processing Utilities"
        H["Image Processing Utility"]:::utility
        I["Canvas Manipulation Utility"]:::utility
        J["Image Resizing Utility"]:::utility
        K["WebAssembly Interface"]:::utility
        L["Download Utility"]:::utility
        M["Format Defaults"]:::utility
        N["Type Definitions"]:::type
    end

    %% External Dependencies
    subgraph "External Dependencies"
        O["WASM Codecs"]:::external
    end

    %% Data Flow - from User actions through the architecture
    %% UI interactions
    A -->|"triggers"| B
    A -->|"triggers"| C
    A -->|"triggers"| D
    A -->|"triggers"| E

    %% Application logic: UI to Hooks
    A -->|"initiates"| F
    A -->|"initiates"| G

    %% Hooks to Processing Utilities
    F -->|"processes"| H
    G -->|"queues"| H

    %% Processing Utilities internal interactions
    H -->|"uses"| I
    H -->|"uses"| J
    H -->|"calls"| K
    H -->|"references"| N

    %% WASM interface calls External Codecs
    K -->|"executes"| O

    %% UI components triggering utilities directly
    D -->|"selectsFormat"| M
    E -->|"downloads"| L

    %% Class Definitions
    classDef ui fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef business fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef utility fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#943126,stroke-width:2px;
    classDef type fill:#D2B4DE,stroke:#5B2C6F,stroke-width:2px;

    %% Click Events
    click A "https://github.com/gladtek/squish/blob/main/src/App.tsx"
    click B "https://github.com/gladtek/squish/blob/main/src/components/DropZone.tsx"
    click C "https://github.com/gladtek/squish/blob/main/src/components/ImageList.tsx"
    click D "https://github.com/gladtek/squish/blob/main/src/components/CompressionOptions.tsx"
    click E "https://github.com/gladtek/squish/blob/main/src/components/DownloadAll.tsx"
    click F "https://github.com/gladtek/squish/blob/main/src/hooks/useImageProcessing.ts"
    click G "https://github.com/gladtek/squish/blob/main/src/hooks/useImageQueue.ts"
    click I "https://github.com/gladtek/squish/blob/main/src/utils/canvas.ts"
    click J "https://github.com/gladtek/squish/blob/main/src/utils/resize.ts"
    click H "https://github.com/gladtek/squish/blob/main/src/utils/imageProcessing.ts"
    click K "https://github.com/gladtek/squish/blob/main/src/utils/wasm.ts"
    click L "https://github.com/gladtek/squish/blob/main/src/utils/download.ts"
    click M "https://github.com/gladtek/squish/blob/main/src/utils/formatDefaults.ts"
    click N "https://github.com/gladtek/squish/tree/main/src/types"
    click N "https://github.com/gladtek/squish/blob/main/src/types/encoders.ts"
```
