# epsitec-sa/grafix architecture

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

- Interactive diagram: https://gitdiagram.com/epsitec-sa/grafix
- Repository: https://github.com/epsitec-sa/grafix

## Overview

##### Main Components

a. Core Layers:
- C# Binding Layer (AggUI)
- Native C++ Layer (aggcpp)
- External Dependencies (Antigrain Geometry, FreeType)

b. Platform-Specific Components:
- Windows Implementation
- macOS Implementation (with Xorg)
- Linux Implementation

**[Application Layer]**
- ↓
**[C# Binding Layer]**
- ↓
**[Native C++ Layer]**
- ↓
**[Platform-Specific Layer]**

##### Component Details

C# Binding Layer should show:
- AggWindow (Window management)
- GraphicContext (Drawing context)
- GraphicBuffer (Memory management)
- FontManager (Font handling)
- Rasterizer (Rendering pipeline)
- Renderer (Drawing operations)

Native C++ Layer should include:
- Antigrain Geometry integration
- FreeType integration
- Platform-specific window handling

##### Data Flow

Following interactions:
- Application → C# Bindings (method calls)
- C# Bindings → Native Layer (P/Invoke)
- Native Layer → External Libraries
- Native Layer → Platform-specific implementations

##### Component Relationships

- How GraphicContext orchestrates rendering operations
- How FontManager interfaces with FreeType
- How AggWindow interfaces with platform-specific window implementations
- How Rasterizer and Renderer work together

##### Implementation Details

Implementation patterns:
- P/Invoke boundary between C# and C++
- Platform abstraction layer
- Memory management strategy
- Event handling system

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef csharp fill:#3498db,color:white
    classDef cpp fill:#2ecc71,color:white
    classDef external fill:#e67e22,color:white
    classDef platform fill:#95a5a6,color:white
    
    %% Application Layer
    subgraph AppLayer["Application Layer"]
        App[Client Application]:::csharp
    end

    %% C# Binding Layer
    subgraph CSharpLayer["C# Binding Layer"]
        AggWindow["AggWindow"]:::csharp
        GraphicContext["GraphicContext"]:::csharp
        GraphicBuffer["GraphicBuffer"]:::csharp
        FontManager["FontManager"]:::csharp
        Path["Path"]:::csharp
        Rasterizer["Rasterizer"]:::csharp
        Renderer["Renderer"]:::csharp
        Native["Native Interface"]:::csharp
    end

    %% Native C++ Layer
    subgraph NativeLayer["Native C++ Layer"]
        GCImpl["GraphicContext Impl"]:::cpp
        GBImpl["GraphicBuffer Impl"]:::cpp
        FMImpl["FontManager Impl"]:::cpp
        PathImpl["Path Impl"]:::cpp
        RastImpl["Rasterizer Impl"]:::cpp
        RendImpl["Renderer Impl"]:::cpp
    end

    %% External Dependencies
    subgraph ExternalDeps["External Dependencies"]
        AGG["Antigrain Geometry"]:::external
        FreeType["FreeType"]:::external
    end

    %% Platform Layer
    subgraph PlatformLayer["Platform-Specific Layer"]
        Win["Windows Support"]:::platform
        Mac["macOS/Xorg Support"]:::platform
        Linux["Linux Support"]:::platform
    end

    %% Relationships
    App --> AggWindow & GraphicContext
    AggWindow --> Native
    GraphicContext --> Native
    GraphicBuffer --> Native
    FontManager --> Native
    Path --> Native
    Rasterizer --> Native
    Renderer --> Native

    Native --> GCImpl & GBImpl & FMImpl & PathImpl & RastImpl & RendImpl
    
    GCImpl & GBImpl & PathImpl & RastImpl & RendImpl --> AGG
    FMImpl --> FreeType
    
    GCImpl & GBImpl --> Win & Mac & Linux

    %% Click Events
    click AggWindow "https://github.com/epsitec-sa/grafix/blob/master/AggUI/AggWindow.cs"
    click GraphicContext "https://github.com/epsitec-sa/grafix/blob/master/AggUI/GraphicContext.cs"
    click GraphicBuffer "https://github.com/epsitec-sa/grafix/blob/master/AggUI/GraphicBuffer.cs"
    click FontManager "https://github.com/epsitec-sa/grafix/blob/master/AggUI/FontManager.cs"
    click Path "https://github.com/epsitec-sa/grafix/blob/master/AggUI/Path.cs"
    click Rasterizer "https://github.com/epsitec-sa/grafix/blob/master/AggUI/Rasterizer.cs"
    click Renderer "https://github.com/epsitec-sa/grafix/blob/master/AggUI/Renderer.cs"
    click Native "https://github.com/epsitec-sa/grafix/blob/master/AggUI/Native.cs"
    click GCImpl "https://github.com/epsitec-sa/grafix/blob/master/AggUI/aggcpp/graphic_context.cpp"
    click GBImpl "https://github.com/epsitec-sa/grafix/blob/master/AggUI/aggcpp/graphic_buffer.cpp"
    click FMImpl "https://github.com/epsitec-sa/grafix/blob/master/AggUI/aggcpp/font_manager.cpp"
    click PathImpl "https://github.com/epsitec-sa/grafix/blob/master/AggUI/aggcpp/path.cpp"
    click RastImpl "https://github.com/epsitec-sa/grafix/blob/master/AggUI/aggcpp/rasterizer.cpp"
    click RendImpl "https://github.com/epsitec-sa/grafix/blob/master/AggUI/aggcpp/renderer.cpp"
    click Win "https://github.com/epsitec-sa/grafix/blob/master/AggUI/aggcpp/agg_patch_files/src/platform/win32/agg_platform_support.cpp"
    click FreeType "https://github.com/epsitec-sa/grafix/blob/master/AggUI/aggcpp/agg_patch_files/font_freetype/agg_font_freetype.cpp"
```
