# ajjahn/psd architecture

> Architecture diagram of the GitHub repository ajjahn/psd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ajjahn/psd
- Repository: https://github.com/ajjahn/psd

## Overview

##### Main Components Identification

a) Core Processing Components:
- File Header Parser
- Image Resources Parser
- Layer & Mask Information Parser
- Image Data Parser
- Blend Mode Engine

b) Data Flow Components:
- Input Handler (Raw PSD bytes)
- Channel Processing
- Layer Management
- Output Generation (RGBA)

##### Input Layer
- PSD byte input
- File validation components

##### Processing Layer
- Section parsers (arranged horizontally)
- Parallel processing capabilities
- Channel compression handlers

##### Layer Management
- Handling
- Layer blending
- RGBA composition

##### Output Layer
- Final image composition
- Layer extraction
- WASM bridge (for browser support)

##### Specific Design Elements

Use these visual elements:

- Rectangles: Core processing modules
- Hexagons: Data transformation components
- Blue: Input/Output operations
- Green: Core processing
- Yellow: Layer management
- Purple: Blend operations

##### Key Relationships to Highlight

- Relationship between:
- File sections and their parsers
- Layer groups and individual layers
- Channel compression and decompression
- Blend mode calculations
- WASM integration points

##### Implementation Details

- Channel processing pipeline
- Compression handling (RLE and Raw)
- Layer group hierarchy
- Blend mode operations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        L1[Processing Module]
        L2{{Data Transformation}}
        L3[(Data Store)]
        L4>Output Component]
        style L1 fill:#90EE90
        style L2 fill:#ADD8E6
        style L3 fill:#FFD700
        style L4 fill:#DDA0DD
    end

    subgraph "Input Layer"
        PSDInput[Raw PSD Input]
        FileValidation{{File Validation}}
    end

    subgraph "Processing Layer"
        CoreLib[Core Library]
        HeaderParser[File Header Parser]
        ResourceParser[Image Resources Parser]
        LayerMaskParser[Layer & Mask Parser]
        ImageDataParser[Image Data Parser]
        ChannelProc[Channel Processing]
    end

    subgraph "Layer Management"
        LayerMgmt[Layer Management]
        GroupHandler[Layer Groups Handler]
        BlendEngine[Blend Mode Engine]
        LayerProc[Layer Processing]
    end

    subgraph "Output Layer"
        OutputGen[Output Generation]
        WASMBridge[WASM Bridge]
        FinalImage>Final RGBA Image]
    end

    PSDInput --> FileValidation
    FileValidation --> CoreLib
    CoreLib --> HeaderParser
    CoreLib --> ResourceParser
    CoreLib --> LayerMaskParser
    CoreLib --> ImageDataParser
    
    ImageDataParser --> ChannelProc
    ChannelProc --> LayerProc
    LayerProc --> LayerMgmt
    LayerMgmt --> GroupHandler
    LayerMgmt --> BlendEngine
    
    BlendEngine --> OutputGen
    GroupHandler --> OutputGen
    OutputGen --> FinalImage
    OutputGen --> WASMBridge

    click HeaderParser "https://github.com/ajjahn/psd/blob/master/src/sections/file_header_section.rs"
    click ResourceParser "https://github.com/ajjahn/psd/blob/master/src/sections/image_resources_section/image_resource.rs"
    click LayerMaskParser "https://github.com/ajjahn/psd/blob/master/src/sections/layer_and_mask_information_section/mod.rs"
    click ImageDataParser "https://github.com/ajjahn/psd/blob/master/src/sections/image_data_section.rs"
    click BlendEngine "https://github.com/ajjahn/psd/blob/master/src/blend.rs"
    click ChannelProc "https://github.com/ajjahn/psd/blob/master/src/psd_channel.rs"
    click LayerMgmt "https://github.com/ajjahn/psd/blob/master/src/sections/layer_and_mask_information_section/layers.rs"
    click GroupHandler "https://github.com/ajjahn/psd/blob/master/src/sections/layer_and_mask_information_section/groups.rs"
    click OutputGen "https://github.com/ajjahn/psd/blob/master/src/render.rs"
    click WASMBridge "https://github.com/ajjahn/psd/blob/master/examples/drag-drop-browser/src/lib.rs"
    click CoreLib "https://github.com/ajjahn/psd/blob/master/src/lib.rs"
    click LayerProc "https://github.com/ajjahn/psd/blob/master/src/sections/layer_and_mask_information_section/layer.rs"

    classDef processing fill:#90EE90
    classDef dataTransform fill:#ADD8E6
    classDef layerMgmt fill:#FFD700
    classDef output fill:#DDA0DD

    class HeaderParser,ResourceParser,LayerMaskParser,ImageDataParser,CoreLib processing
    class FileValidation,ChannelProc dataTransform
    class LayerMgmt,GroupHandler,BlendEngine,LayerProc layerMgmt
    class OutputGen,WASMBridge,FinalImage output
```
