# agamnentzar/ag-psd architecture

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

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

## Overview

##### Main Components

a. Core Processing Components:
- Reader Module (psdReader.ts)
- Writer Module (psdWriter.ts)
- Data Parser/Processor (multiple specialized parsers)
- Canvas Initializer (initialize-canvas.js)

b. Feature Modules:
- Text Processing (text.ts)
- Image Resources Handler (imageResources.ts)
- Effects Processing (effectsHelpers.ts)
- Engine Data Processor (engineData.ts)

**[PSD File Input] → [Buffer/ArrayBuffer] → [Processing Pipeline] → [Output Buffer] → [PSD File Output]**

- ┌─── [Image Resources Parser]
**[Buffer Input] ─→ [PSD Reader] ─→ [Data Processors] ─→ [PSD Writer] ─→ [Buffer Output]**
- [Layer Information Parser]

**[Canvas Initializer] ←→ [Processing Pipeline]**
**[Type Definitions] ─→ [All Components]**

##### Component Relationships

- Double lines for primary data flow

##### Implementation Details

Notes for:
- Browser vs Node.js paths
- Worker thread support
- Memory management
- Error handling

##### Optional feature paths

Key Architectural Patterns to Highlight:

##### Pipeline Processing
- Sequential processing of PSD data
- Parallel processing opportunities

##### Module Independence
- Demonstrate loose coupling between components
- Clear interfaces between modules

##### Platform Abstraction
- How canvas operations are abstracted
- Browser/Node.js compatibility paths

##### Error Handling
- Validation checkpoints
- Error propagation paths

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph IO["Input/Output Layer"]
        Input[PSD File Input]:::input
        IBuffer[Buffer/ArrayBuffer]:::buffer
        OBuffer[Output Buffer]:::buffer
        Output[PSD File Output]:::output
    end

    subgraph Core["Core Processing Layer"]
        Reader["PSD Reader"]:::core
        Writer["PSD Writer"]:::core
        CorePSD["Core PSD Handler"]:::core
    end

    subgraph Processors["Data Processors"]
        ImgRes["Image Resources Parser"]:::processor
        LayerInfo["Layer Information Parser"]:::processor
        TextProc["Text Processor"]:::processor
        EffProc["Effects Processor"]:::processor
        EngineProc["Engine Data Processor"]:::processor
        AddInfo["Additional Info Processor"]:::processor
        JPEGProc["JPEG Processor"]:::processor
        DescProc["Descriptor Processor"]:::processor
    end

    subgraph Support["Support Systems"]
        Canvas["Canvas Initializer"]:::support
        Types["Type Definitions"]:::support
        Utils["Helper Utilities"]:::support
        UTF8["UTF8 Text Support"]:::support
    end

    %% Main Flow
    Input --> IBuffer
    IBuffer --> Reader
    Reader --> CorePSD
    CorePSD --> Writer
    Writer --> OBuffer
    OBuffer --> Output

    %% Processor Connections
    CorePSD --> ImgRes
    CorePSD --> LayerInfo
    CorePSD --> TextProc
    CorePSD --> EffProc
    CorePSD --> EngineProc
    CorePSD --> AddInfo
    CorePSD --> JPEGProc
    CorePSD --> DescProc

    %% Support System Connections
    Canvas -.-> CorePSD
    Types -.-> CorePSD
    Utils -.-> CorePSD
    UTF8 -.-> TextProc

    %% Click Events
    click Reader "https://github.com/Agamnentzar/ag-psd/blob/master/src/psdReader.ts"
    click Writer "https://github.com/Agamnentzar/ag-psd/blob/master/src/psdWriter.ts"
    click Canvas "https://github.com/Agamnentzar/ag-psd/blob/master/src/initializeCanvas.ts"
    click TextProc "https://github.com/Agamnentzar/ag-psd/blob/master/src/text.ts"
    click ImgRes "https://github.com/Agamnentzar/ag-psd/blob/master/src/imageResources.ts"
    click EffProc "https://github.com/Agamnentzar/ag-psd/blob/master/src/effectsHelpers.ts"
    click EngineProc "https://github.com/Agamnentzar/ag-psd/blob/master/src/engineData.ts"
    click CorePSD "https://github.com/Agamnentzar/ag-psd/blob/master/src/psd.ts"
    click Types "https://github.com/Agamnentzar/ag-psd/blob/master/index.d.ts"
    click AddInfo "https://github.com/Agamnentzar/ag-psd/blob/master/src/additionalInfo.ts"
    click Utils "https://github.com/Agamnentzar/ag-psd/blob/master/src/helpers.ts"
    click UTF8 "https://github.com/Agamnentzar/ag-psd/blob/master/src/utf8.ts"
    click JPEGProc "https://github.com/Agamnentzar/ag-psd/blob/master/src/jpeg.ts"
    click DescProc "https://github.com/Agamnentzar/ag-psd/blob/master/src/descriptor.ts"

    %% Styles
    classDef core fill:#2374ab,stroke:#2374ab,color:white
    classDef processor fill:#57a773,stroke:#57a773,color:white
    classDef support fill:#808080,stroke:#808080,color:white
    classDef input fill:#ffc857,stroke:#ffc857,color:black
    classDef output fill:#ffc857,stroke:#ffc857,color:black
    classDef buffer fill:#d1d1d1,stroke:#d1d1d1,color:black

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Processors]:::processor
        L3[Support Systems]:::support
        L4[Input/Output]:::input
        L5[Buffers]:::buffer
    end
```
