# alexiusy/svglib architecture

> Architecture diagram of the GitHub repository alexiusy/svglib, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alexiusy/svglib
- Repository: https://github.com/alexiusy/svglib

## Overview

SVGlib is a Swift SVG renderer for Apple platforms. Its main workflow loads SVG data or a resource into an XML-parsed element tree, resolves styles, references, and geometry into an ordered display list, then draws through SVGDocument or presents through SVGView. The graph also captures documented selection, sizing, text/image, gradients, filters, and rasterization capabilities. Some subsystem links are based on README documentation because their source was not sampled.

Main entry points: [`Sources/SVGlib/SVGElement.swift`](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGElement.swift) (Element tree), [`Sources/SVGlib/SVGDocument.swift`](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGDocument.swift) (SVG document), [`Sources/SVGlib/SVGParser.swift`](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGParser.swift) (XML parser), [`Sources/SVGlib/SVGView.swift`](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGView.swift) (SVG view)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_load["Loading and parsing"]
  node_resource["Resource loading<br/>[SVGResource.swift]"]
  node_parser["XML parser<br/>[SVGParser.swift]"]
  node_registry["Element registry"]
end

subgraph group_resolve["SVG resolution"]
  node_tree["Element tree<br/>[SVGElement.swift]"]
  node_styles["Style resolution<br/>[SVGStyle.swift]"]
  node_stylesheet["Style sheets"]
  node_geometry["Paths and shapes<br/>[SVGPath.swift]"]
  node_paint["Paint and gradients<br/>[SVGGradient.swift]"]
  node_text["Text layout<br/>[SVGText.swift]"]
  node_images["Image elements<br/>[SVGImage.swift]"]
end

subgraph group_render["Rendering and interaction"]
  node_document["SVG document<br/>[SVGDocument.swift]"]
  node_display_list["Rendered shapes"]
  node_filters["Filter processing"]
  node_rasterization["Filter rasterization<br/>[SVGDocument.swift]"]
  node_view["SVG view<br/>[SVGView.swift]"]
  node_scaling["Content scaling"]
  node_selection["Selection and hit testing<br/>[SVGView.swift]"]
end

subgraph group_integrations["Platform services"]
  node_graphics["Apple graphics APIs"]
end

node_client(("App or caller"))
node_svg_input["SVG input"]

node_client -->|"loads by name"| node_resource
node_client -->|"provides data"| node_parser
node_svg_input -->|"parsed by"| node_parser
node_resource -->|"provides data"| node_parser
node_parser -->|"creates elements"| node_registry
node_registry -->|"instantiates"| node_tree
node_parser -->|"builds tree"| node_tree
node_stylesheet -->|"applies rules"| node_tree
node_tree -->|"resolves styles"| node_styles
node_tree -->|"provides geometry"| node_geometry
node_tree -->|"resolves paint"| node_paint
node_tree -->|"lays out text"| node_text
node_tree -->|"resolves images"| node_images
node_client -->|"creates document"| node_document
node_document -->|"parses input"| node_parser
node_document -->|"resolves elements"| node_tree
node_document -->|"builds display list"| node_display_list
node_display_list -->|"evaluates filters"| node_filters
node_document -->|"rasterizes shapes"| node_rasterization
node_client -->|"creates view"| node_view
node_view -->|"displays document"| node_document
node_view -->|"maps coordinates"| node_scaling
node_view -->|"handles selection"| node_selection
node_document -->|"draws with"| node_graphics
node_filters -->|"uses Core Image"| node_graphics
node_text -->|"uses Core Text"| node_graphics
node_images -->|"decodes with ImageIO"| node_graphics
node_view -->|"presents with UIKit"| node_graphics

click node_resource "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGResource.swift"
click node_parser "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGParser.swift"
click node_registry "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGElementRegistry.swift"
click node_tree "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGElement.swift"
click node_styles "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGStyle.swift"
click node_stylesheet "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGStyleSheet.swift"
click node_geometry "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGPath.swift"
click node_paint "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGGradient.swift"
click node_text "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGText.swift"
click node_images "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGImage.swift"
click node_document "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGDocument.swift"
click node_display_list "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGRenderedShape.swift"
click node_filters "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGFilterPipeline.swift"
click node_rasterization "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGDocument.swift"
click node_view "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGView.swift"
click node_scaling "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGContentScaling.swift"
click node_selection "https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGView.swift"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_resource,node_parser,node_registry toneBlue
class node_tree,node_styles,node_stylesheet,node_geometry,node_paint,node_text,node_images toneAmber
class node_document,node_display_list,node_filters,node_rasterization,node_view,node_scaling,node_selection toneMint
class node_graphics toneRose
class node_client,node_svg_input toneIndigo
```

## Components

### Loading and parsing

- [Resource loading](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGResource.swift): `Sources/SVGlib/SVGResource.swift`
- [XML parser](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGParser.swift): `Sources/SVGlib/SVGParser.swift`
- [Element registry](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGElementRegistry.swift): `Sources/SVGlib/SVGElementRegistry.swift`

### SVG resolution

- [Element tree](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGElement.swift): `Sources/SVGlib/SVGElement.swift`
- [Style resolution](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGStyle.swift): `Sources/SVGlib/SVGStyle.swift`
- [Style sheets](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGStyleSheet.swift): `Sources/SVGlib/SVGStyleSheet.swift`
- [Paths and shapes](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGPath.swift): `Sources/SVGlib/SVGPath.swift`
- [Paint and gradients](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGGradient.swift): `Sources/SVGlib/SVGGradient.swift`
- [Text layout](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGText.swift): `Sources/SVGlib/SVGText.swift`
- [Image elements](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGImage.swift): `Sources/SVGlib/SVGImage.swift`

### Rendering and interaction

- [SVG document](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGDocument.swift): `Sources/SVGlib/SVGDocument.swift`
- [Rendered shapes](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGRenderedShape.swift): `Sources/SVGlib/SVGRenderedShape.swift`
- [Filter processing](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGFilterPipeline.swift): `Sources/SVGlib/SVGFilterPipeline.swift`
- [Filter rasterization](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGDocument.swift): `Sources/SVGlib/SVGDocument.swift`
- [SVG view](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGView.swift): `Sources/SVGlib/SVGView.swift`
- [Content scaling](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGContentScaling.swift): `Sources/SVGlib/SVGContentScaling.swift`
- [Selection and hit testing](https://github.com/alexiusy/svglib/blob/master/Sources/SVGlib/SVGView.swift): `Sources/SVGlib/SVGView.swift`

### Platform services

- **Apple graphics APIs**

### Other components

- **App or caller**
- **SVG input**

## Connections

- App or caller → Resource loading: loads by name
- App or caller → XML parser: provides data
- SVG input → XML parser: parsed by
- Resource loading → XML parser: provides data
- XML parser → Element registry: creates elements
- Element registry → Element tree: instantiates
- XML parser → Element tree: builds tree
- Style sheets → Element tree: applies rules
- Element tree → Style resolution: resolves styles
- Element tree → Paths and shapes: provides geometry
- Element tree → Paint and gradients: resolves paint
- Element tree → Text layout: lays out text
- Element tree → Image elements: resolves images
- App or caller → SVG document: creates document
- SVG document → XML parser: parses input
- SVG document → Element tree: resolves elements
- SVG document → Rendered shapes: builds display list
- Rendered shapes → Filter processing: evaluates filters
- SVG document → Filter rasterization: rasterizes shapes
- App or caller → SVG view: creates view
- SVG view → SVG document: displays document
- SVG view → Content scaling: maps coordinates
- SVG view → Selection and hit testing: handles selection
- SVG document → Apple graphics APIs: draws with
- Filter processing → Apple graphics APIs: uses Core Image
- Text layout → Apple graphics APIs: uses Core Text
- Image elements → Apple graphics APIs: decodes with ImageIO
- SVG view → Apple graphics APIs: presents with UIKit
