# pekim/go-svg architecture

> Architecture diagram of the GitHub repository pekim/go-svg, 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/pekim/go-svg
- Repository: https://github.com/pekim/go-svg

## Overview

##### Core Processing Pipeline
- This as the central flow of the system
a. SVG Input
b. Parser
c. Internal Representation
d. Renderer Interface
e. Output Renderers

##### Main Functional Blocks (derived from file structure)
- SVG Parsing Layer (parse.go, parse_path.go)
- Path Processing (path.go, patterns.go)
- Units and Matrix Operations (units.go, matrix.go)
- Masking System (mask.go)

##### Renderer Implementation Layer
- draw2d implementation
- gg implementation
- rasterx implementation

**[SVG Input] → [Parser Components] → [Internal Representation] → [Renderer Interface] → [Output Renderers]**

##### Component Relationships

Specific Implementation Details to Highlight:

##### Parser Section
- Relationship between parse.go and parse_path.go
- To svg_elements.go for element definitions
- Types.go connections

##### Renderer Interface
- Options.go as configuration input
- Demonstrate how the renderer interface connects to all three implementations
- Limitations of each renderer (as mentioned in README)

##### Supporting Systems
- How matrix.go and units.go support both parsing and rendering
- Mask.go's relationship with the rendering process
- Patterns.go in the processing pipeline

Additional Recommendations:

##### Version/status indicators
- Experimental features
- Deprecated components
- Planned improvements

- Grouping related components
- Using consistent spacing
- Maintaining clear flow direction
- Adding appropriate whitespace between sections

Remember to indicate the experimental nature of the project (as mentioned in the README) and show the current limitations of each rendering backend in a clear, visual way.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        SVG[SVG File Input]:::input
    end

    subgraph "Parser Layer"
        Parser["SVG Parser"]:::parser
        click Parser "https://github.com/pekim/go-svg/blob/main/parse.go"
        PathParser["Path Parser"]:::parser
        click PathParser "https://github.com/pekim/go-svg/blob/main/parse_path.go"
        Elements["SVG Elements"]:::parser
        click Elements "https://github.com/pekim/go-svg/blob/main/svg_elements.go"
        Types["Type System"]:::parser
        click Types "https://github.com/pekim/go-svg/blob/main/types.go"
    end

    subgraph "Core Processing"
        Path["Path Processor"]:::core
        click Path "https://github.com/pekim/go-svg/blob/main/path.go"
        Patterns["Pattern System"]:::core
        click Patterns "https://github.com/pekim/go-svg/blob/main/patterns.go"
        Shapes["Shape Handler"]:::core
        click Shapes "https://github.com/pekim/go-svg/blob/main/shapes.go"
    end

    subgraph "Support Systems"
        Matrix["Matrix Operations"]:::support
        click Matrix "https://github.com/pekim/go-svg/blob/main/matrix.go"
        Units["Units Handler"]:::support
        click Units "https://github.com/pekim/go-svg/blob/main/units.go"
        Mask["Masking System"]:::support
        click Mask "https://github.com/pekim/go-svg/blob/main/mask.go"
    end

    subgraph "Renderer System"
        RenderInterface["Renderer Interface"]:::interface
        click RenderInterface "https://github.com/pekim/go-svg/blob/main/renderer/options.go"
        
        subgraph "Rendering Backends"
            Draw2D["Draw2D Implementation"]:::renderer
            click Draw2D "https://github.com/pekim/go-svg/blob/main/renderer/draw2d/draw.go"
            GG["GG Implementation"]:::renderer
            click GG "https://github.com/pekim/go-svg/blob/main/renderer/gg/draw.go"
            RasterX["RasterX Implementation"]:::renderer
            click RasterX "https://github.com/pekim/go-svg/blob/main/renderer/rasterx/draw.go"
        end

        subgraph "Example Implementations"
            Draw2DEx["Draw2D Example"]:::example
            click Draw2DEx "https://github.com/pekim/go-svg/blob/main/renderer/draw2d/example/draw_example.go"
            GGEx["GG Example"]:::example
            click GGEx "https://github.com/pekim/go-svg/blob/main/renderer/gg/example/draw_example.go"
            RasterXEx["RasterX Example"]:::example
            click RasterXEx "https://github.com/pekim/go-svg/blob/main/renderer/rasterx/example/draw_example.go"
        end
    end

    %% Connections
    SVG --> Parser
    Parser --> PathParser
    Parser --> Elements
    Parser --> Types
    PathParser --> Path
    Path --> Patterns
    Path --> Shapes
    
    Matrix --> Parser
    Matrix --> Path
    Units --> Parser
    Units --> Path
    Mask --> RenderInterface
    
    Path --> RenderInterface
    Patterns --> RenderInterface
    Shapes --> RenderInterface
    
    RenderInterface --> Draw2D
    RenderInterface --> GG
    RenderInterface --> RasterX
    
    Draw2D --> Draw2DEx
    GG --> GGEx
    RasterX --> RasterXEx

    %% Styles
    classDef input fill:#4a9eff,stroke:#333,stroke-width:2px
    classDef parser fill:#6b8e23,stroke:#333,stroke-width:2px
    classDef core fill:#32cd32,stroke:#333,stroke-width:2px
    classDef support fill:#a9a9a9,stroke:#333,stroke-width:2px
    classDef interface fill:#ffa500,stroke:#333,stroke-width:2px
    classDef renderer fill:#9370db,stroke:#333,stroke-width:2px
    classDef example fill:#deb887,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Input]:::input
        L2[Parser Components]:::parser
        L3[Core Processing]:::core
        L4[Support Systems]:::support
        L5[Renderer Interface]:::interface
        L6[Renderers]:::renderer
        L7[Examples]:::example
    end
```
