# playform/compress architecture

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

- Interactive diagram: https://gitdiagram.com/playform/compress
- Repository: https://github.com/playform/compress

## Overview

##### Main Components Identification

a) Input/Output Processing Layer
- Input directories/files
- Output compressed files
- Path mapping functionality

b) Compression Engine Core
- Parallel processing capabilities

c) File Type Processors
Processors into categories:
- Style Processors (CSS)
- CSSO processor
- LightningCSS processor
- Markup Processors
- HTML (html-minifier-terser)
- SVG (SVGO)
- Script Processor
- JavaScript (Terser)
- Image Processor
- Sharp (for multiple image formats)

##### Component Relationships

**[Input Files] → [File Type Detection] → [Processor Selection] → [Compression] → [Output Files]**

- Rectangle: Core components
- Hexagon: File processors

##### Integration Points

Integration with Astro:
- Configuration intake
- Build process hooks
- Output directory handling

##### Specific Implementation Details

Key features:
- File filtering system
- Logger functionality
- Configuration override capabilities
- Path mapping system

**┌─ Configuration Layer ─────────────────────┐**
- Path configurations                     │
- Compression options                     │
- Filtering rules                         │
- ┬─┘
- ↓                       │
**┌─ Core Processing Layer ─────────────────┤**
- ┌─ File Detection ─┐ ┌─ Orchestrator ─┐ │

- ┘ └───────────────┬┘ │
- ┼─┘
- ↓                     │
**┌─ Processor Layer ───────────────────────┐**
- ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐       │
- CSS │ │ HTML│ │ JS  │ │Image│       │
- ┘ └─────┘ └─────┘ └─────┘       │
- ┘

##### Important Elements

- Version compatibility
- Performance optimization paths
- Error handling flows
- Logging points
- Configuration validation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Configuration
        Config["Configuration Options"]
        Options["Options Interface"]:::interface
        Parser["Parser Interface"]:::interface
    end

    subgraph "Core Processing"
        Integration["Core Integration Orchestrator"]:::core
        DirHandler["Directory Handler"]:::core
        PathMap["Path Mapping"]:::core
        Middleware["Middleware Handler"]:::core
    end

    subgraph "File Processors"
        direction TB
        subgraph "Style Processing"
            direction TB
            CSSParser["CSS Parser"]:::processor
            CSSO["CSSO Implementation"]:::implementation
            Lightning["LightningCSS Implementation"]:::implementation
        end

        subgraph "Markup Processing"
            direction TB
            HTMLParser["HTML Parser"]:::processor
            HTMLMin["HTML Minifier"]:::implementation
            SVGParser["SVG Parser"]:::processor
            SVGO["SVGO Implementation"]:::implementation
        end

        subgraph "Script Processing"
            direction TB
            JSParser["JavaScript Parser"]:::processor
            Terser["Terser Implementation"]:::implementation
        end

        subgraph "Image Processing"
            direction TB
            ImgParser["Image Parser"]:::processor
            Sharp["Sharp Implementation"]:::implementation
            ImgWriter["Image Writer"]:::implementation
        end
    end

    Config --> Integration
    Options --> Integration
    Parser --> Integration
    Integration --> DirHandler
    Integration --> PathMap
    Integration --> Middleware

    Middleware --> CSSParser
    Middleware --> HTMLParser
    Middleware --> SVGParser
    Middleware --> JSParser
    Middleware --> ImgParser

    CSSParser --> CSSO
    CSSParser --> Lightning
    HTMLParser --> HTMLMin
    SVGParser --> SVGO
    JSParser --> Terser
    ImgParser --> Sharp
    Sharp --> ImgWriter

    %% Click Events
    click Integration "https://github.com/playform/compress/blob/Current/Source/Function/Integration.ts"
    click DirHandler "https://github.com/playform/compress/blob/Current/Source/Function/Directory.ts"
    click PathMap "https://github.com/playform/compress/blob/Current/Source/Interface/Map.ts"
    click CSSParser "https://github.com/playform/compress/blob/Current/Source/Type/Parser/CSS.ts"
    click CSSO "https://github.com/playform/compress/blob/Current/Source/Variable/CSS/csso.ts"
    click Lightning "https://github.com/playform/compress/blob/Current/Source/Variable/CSS/lightningcss.ts"
    click HTMLParser "https://github.com/playform/compress/blob/Current/Source/Type/Parser/HTML.ts"
    click HTMLMin "https://github.com/playform/compress/blob/Current/Source/Type/HTML/html-minifier-terser.ts"
    click SVGParser "https://github.com/playform/compress/blob/Current/Source/Type/Parser/SVG.ts"
    click SVGO "https://github.com/playform/compress/blob/Current/Source/Type/SVG/svgo.ts"
    click JSParser "https://github.com/playform/compress/blob/Current/Source/Type/Parser/JavaScript.ts"
    click Terser "https://github.com/playform/compress/blob/Current/Source/Type/JavaScript/terser.ts"
    click ImgParser "https://github.com/playform/compress/blob/Current/Source/Type/Parser/Image.ts"
    click Sharp "https://github.com/playform/compress/blob/Current/Source/Variable/Image/sharp.ts"
    click ImgWriter "https://github.com/playform/compress/blob/Current/Source/Function/Image/Writesharp.ts"
    click Options "https://github.com/playform/compress/blob/Current/Source/Interface/Option.ts"
    click Parser "https://github.com/playform/compress/blob/Current/Source/Interface/Parser.ts"
    click Config "https://github.com/playform/compress/blob/Current/Source/Variable/Option.ts"
    click Middleware "https://github.com/playform/compress/blob/Current/Source/Variable/Middleware.ts"

    %% Styles
    classDef core fill:#2374ab,stroke:#2374ab,color:#fff
    classDef processor fill:#48a9a6,stroke:#48a9a6,color:#fff
    classDef implementation fill:#4ea5d9,stroke:#4ea5d9,color:#fff
    classDef interface fill:#444554,stroke:#444554,color:#fff

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Processors]:::processor
        L3[Implementations]:::implementation
        L4[Interfaces]:::interface
    end
```
