# svg-net/svg architecture

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

- Interactive diagram: https://gitdiagram.com/svg-net/svg
- Repository: https://github.com/svg-net/svg

## Overview

This project is an SVG library for .NET that provides functionality to parse, create, edit, and render SVG 1.1 images. It is designed as a standalone library (with a NuGet package available) that can be used by any .NET application. In addition to the core library code (found in the Source folder), the project contains sample applications (in the Samples directory), code generators (in the Generators folder), comprehensive test suites (in the Tests directory), and detailed documentation (in the Docs directory).

##### Main Components
- Core SVG.NET Library:
– This is the heart of the project found under the Source folder. It contains multiple subcomponents such as:
▪ SVG DOM & Document Structure (Document Structure, SvgElement, non-SVG elements, etc.)
▪ Data Types and Converters (found in the DataTypes folder for handling measurement units, aspect ratios, etc.)
▪ CSS Integration (modules under the Css folder)
▪ Filter Effects and Painting (the Filter Effects and Painting directories reveal modules to render gradients, blur, displacement, and other SVG effects)
▪ Transformations (such as translation, rotation, scaling, and skewing located in the Transforms directory)
▪ Text and Font Handling (under the Text folder)
▪ Rendering and Graphics Provider (in the Rendering folder)
▪ Extensions and Helpers (extension methods, helper utilities, and linking features)
- Generators:
– The code in the Generators folder (like AvailableElementsGenerator.cs and related files) is likely used to dynamically generate code or element lists based on the SVG specification.
- Samples:
– Several sample projects (e.g., SVGBuilder, SVGViewer, SvgConsole) demonstrate how an application might consume this library.
- Tests:
– Test suites (unit, benchmark, and web test runners) ensure the library works correctly across diverse scenarios.
- Documentation & CI:
– A Docs folder containing markdown files, API docs, and doc generation scripts; in addition, GitHub workflows and CI tools (build and test workflows) support continuous integration and documentation building.

##### Out Component Relationships and Interactions
- The Core Library acts as the engine. At its center, the SVG Document Parser produces an internal representation (DOM) of an SVG file. This representation is then used by various modules:
- The Rendering Engine picks the parsed elements and applies styling, transforms, and filter effects before outputting the final rendered image.
- The Element Factory (or SVG Element Creation logic) constructs and manages individual SVG elements.
- Data Type modules and Converters enforce consistency and help parse numeric values, units, etc.
- Extensions and Helpers provide additional operations (e.g., string parsing, linking elements) used across the library.
- The Generators module interacts with the core by providing auto-generated code which may help in updating or extending available SVG elements dynamically.
- Sample applications demonstrate how external client applications call into the library’s APIs to load or render SVG files.
- The Test suites verify components in isolation (unit tests), as well as end-to-end behavior (benchmark, rendering accuracy, and web compliance tests).
- CI/CD (via GitHub workflows) ensures that tests run on each commit and documentation is built automatically.

##### Architectural Patterns/Design Principles
- Modularity & Separation of Concerns: Each responsibility—parsing, rendering, path building, etc.—resides in separate submodules.
- Layered Abstraction: There is a clear separation between the SVG DOM model, business logic of rendering, and the interfaces that client applications use.
- Extensibility: There are designated extension points (e.g., in the ExtensionMethods and Extensibility directories) which foster customization.
- Testability: Presence of multiple test projects and a robust CI pipeline underscores a focus on maintainability.

##### Technologies, Frameworks, and Tools
- The project is built using C# for .NET (compatible with .NET Standard 2.0).
- It leverages MSBuild (.csproj files) and includes GitHub workflows for CI.
- NuGet is used for dependencies such as ExCSS.
- Documentation is generated using DocFX (indicated by the docfx.json file in Docs).

##### Putting It All Together
– SVG Parsing & DOM Building
– Element Factories and Document Structure Management
– Data Types / Converters
– Rendering Pipeline (includes Painting, CSS, and Transformations)
– Filter Effects Processing
– Text and Font Handling
3. Complement this with Sample Applications consuming the library.
4. External layers for Automated Testing, CI/CD, and Documentation, which feed into quality assurance and developer knowledge.

– How SVG files are parsed and converted into an internal DOM,
– How this DOM is manipulated (through modules such as CSS and Transformation),
– And finally, how rendering is performed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Input and Output
    SvgInput["SVG File Input"]:::external
    RenderedOutput["Rendered SVG Output"]:::external

    %% Core SVG.NET Library Subgraph
    subgraph "Core SVG.NET Library"
        CoreLib["Core SVG.NET Library"]:::core
        SVGDom["SVG DOM & Document Structure"]:::core
        BasicShapes["Basic Shapes Module"]:::core
        DataTypes["Data Types & Converters"]:::core
        CssIntegration["CSS Integration"]:::core
        FilterEffects["Filter Effects"]:::core
        Painting["Painting Module"]:::core
        Transforms["Transformations Module"]:::core
        TextHandling["Text and Font Handling"]:::core
        RenderingEngine["Rendering & Graphics Engine"]:::core
        Extensions["Extensions & Helpers"]:::core
    end

    %% External Interfaces Subgraph
    subgraph "External Interfaces"
        CodeGenerators["Code Generators"]:::external
        SampleApps["Sample Applications"]:::external
        TestSuites["Test Suites"]:::external
        Documentation["Documentation"]:::external
        Docfx["API Doc Config"]:::external
        CI["CI/CD"]:::external
    end

    %% Flow Connections
    SvgInput -->|"feeds"| CoreLib
    CoreLib -->|"builds DOM"| SVGDom
    SVGDom -->|"creates shapes"| BasicShapes
    SVGDom -->|"parses data"| DataTypes
    BasicShapes -->|"rendered by"| RenderingEngine
    DataTypes -->|"processed by"| RenderingEngine
    CssIntegration -->|"styles"| RenderingEngine
    FilterEffects -->|"applied in"| RenderingEngine
    Painting -->|"used in"| RenderingEngine
    Transforms -->|"transforms"| RenderingEngine
    TextHandling -->|"adds text"| RenderingEngine
    Extensions -->|"enhances"| SVGDom
    RenderingEngine -->|"final output"| RenderedOutput

    %% External Interfaces to Core connections
    CodeGenerators -->|"generates code for"| CoreLib
    SampleApps -->|"consumes"| CoreLib
    TestSuites -->|"verifies"| CoreLib
    Documentation -->|"documents"| CoreLib
    CI -->|"builds/tests"| CoreLib

    %% Documentation sub connection
    Documentation -->|"config via"| Docfx

    %% Click Events for Core Components
    click CoreLib "https://github.com/svg-net/svg/tree/master/Source"
    click SVGDom "https://github.com/svg-net/svg/tree/master/Source/Document Structure"
    click BasicShapes "https://github.com/svg-net/svg/tree/master/Source/Basic Shapes"
    click DataTypes "https://github.com/svg-net/svg/tree/master/Source/DataTypes"
    click CssIntegration "https://github.com/svg-net/svg/tree/master/Source/Css"
    click FilterEffects "https://github.com/svg-net/svg/tree/master/Source/Filter Effects"
    click Painting "https://github.com/svg-net/svg/tree/master/Source/Painting"
    click Transforms "https://github.com/svg-net/svg/tree/master/Source/Transforms"
    click TextHandling "https://github.com/svg-net/svg/tree/master/Source/Text"
    click RenderingEngine "https://github.com/svg-net/svg/tree/master/Source/Rendering"
    click Extensions "https://github.com/svg-net/svg/tree/master/Source/ExtensionMethods"

    %% Click Events for External Components
    click CodeGenerators "https://github.com/svg-net/svg/tree/master/Generators"
    click SampleApps "https://github.com/svg-net/svg/tree/master/Samples"
    click TestSuites "https://github.com/svg-net/svg/tree/master/Tests"
    click Documentation "https://github.com/svg-net/svg/tree/master/Docs"
    click Docfx "https://github.com/svg-net/svg/blob/master/Docs/docfx.json"
    click CI "https://github.com/svg-net/svg/tree/master/.github/workflows"

    %% Styles
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
