# rough-stuff/rough architecture

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

- Interactive diagram: https://gitdiagram.com/rough-stuff/rough
- Repository: https://github.com/rough-stuff/rough

## Overview

##### Main Components

a) Core Engine Layer:
- Core.ts, math.ts, and geometry.ts as fundamental components
- These handle the basic calculations and geometric operations

b) Rendering Layer:
- Split into two parallel branches:
- Canvas Renderer (canvas.ts)
- SVG Renderer (svg.ts)
- Both to the core engine

c) Filler System:
- Inheritance hierarchy from filler-interface.ts
- Filler types:
- Hachure
- Dots
- ZigZag
- etc.

d) Generator Layer:
- Generator.ts as an intermediary between core and renderers
- How it processes drawing operations

##### Component Relationships

**User Input -> Generator -> Core Engine -> Fillers -> Renderers -> Output (Canvas/SVG)**

##### Specific Implementation Details

- Drawing Types  |

- Lines        |
- Curves       |
- Rectangles   |
- Circles      |
- Paths        |
- Polygons     |

##### Architecture Patterns

Highlight:
- Strategy Pattern (for different fillers)
- Factory Pattern (for renderer creation)
- Bridge Pattern (between core and renderers)

- Input     |     |  Core Engine   |     |  Renderers  |
- (API Calls) | --> | (Geometry/Math)| --> | (Canvas/SVG)|

- Fillers     |
- (Fill Styles)  |

##### Additional Elements

Include:
- Version information
- External dependencies
- Build/Bundle information
- Performance considerations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        API[API Calls]:::input
    end

    subgraph Core ["Core Engine Layer"]
        Core["Core Engine"]:::core
        Math["Math Operations"]:::core
        Geom["Geometry Operations"]:::core
        Main["Main Module"]:::core
    end

    subgraph Generator ["Generator Layer"]
        Gen["Generator"]:::generator
    end

    subgraph Renderers ["Rendering Layer"]
        BaseR["Base Renderer"]:::renderer
        CanvasR["Canvas Renderer"]:::renderer
        SVGR["SVG Renderer"]:::renderer
    end

    subgraph Fillers ["Filler System"]
        FillerI["Filler Interface"]:::interface
        BaseF["Base Filler"]:::filler
        HachureF["Hachure Filler"]:::filler
        DotF["Dot Filler"]:::filler
        DashedF["Dashed Filler"]:::filler
        ZigZagF["ZigZag Filler"]:::filler
        HatchF["Hatch Filler"]:::filler
        ScanLineF["Scan Line Hachure"]:::filler
        ZigZagLineF["ZigZag Line Filler"]:::filler
    end

    subgraph Output
        Canvas["Canvas Output"]:::output
        SVG["SVG Output"]:::output
    end

    %% Relationships
    API --> Main
    Main --> Gen
    Gen --> Core
    Core --> Math
    Core --> Geom
    Gen --> BaseR
    BaseR --> CanvasR
    BaseR --> SVGR
    CanvasR --> Canvas
    SVGR --> SVG
    
    FillerI --> BaseF
    BaseF --> HachureF
    BaseF --> DotF
    BaseF --> DashedF
    BaseF --> ZigZagF
    BaseF --> HatchF
    BaseF --> ScanLineF
    BaseF --> ZigZagLineF
    
    BaseR --> FillerI

    %% Click Events
    click Core "https://github.com/rough-stuff/rough/blob/master/src/core.ts"
    click Math "https://github.com/rough-stuff/rough/blob/master/src/math.ts"
    click Geom "https://github.com/rough-stuff/rough/blob/master/src/geometry.ts"
    click Main "https://github.com/rough-stuff/rough/blob/master/src/rough.ts"
    click Gen "https://github.com/rough-stuff/rough/blob/master/src/generator.ts"
    click BaseR "https://github.com/rough-stuff/rough/blob/master/src/renderer.ts"
    click CanvasR "https://github.com/rough-stuff/rough/blob/master/src/canvas.ts"
    click SVGR "https://github.com/rough-stuff/rough/blob/master/src/svg.ts"
    click FillerI "https://github.com/rough-stuff/rough/blob/master/src/fillers/filler-interface.ts"
    click BaseF "https://github.com/rough-stuff/rough/blob/master/src/fillers/filler.ts"
    click HachureF "https://github.com/rough-stuff/rough/blob/master/src/fillers/hachure-filler.ts"
    click DotF "https://github.com/rough-stuff/rough/blob/master/src/fillers/dot-filler.ts"
    click DashedF "https://github.com/rough-stuff/rough/blob/master/src/fillers/dashed-filler.ts"
    click ZigZagF "https://github.com/rough-stuff/rough/blob/master/src/fillers/zigzag-filler.ts"
    click HatchF "https://github.com/rough-stuff/rough/blob/master/src/fillers/hatch-filler.ts"
    click ScanLineF "https://github.com/rough-stuff/rough/blob/master/src/fillers/scan-line-hachure.ts"
    click ZigZagLineF "https://github.com/rough-stuff/rough/blob/master/src/fillers/zigzag-line-filler.ts"

    %% Styles
    classDef core fill:#2374ab
    classDef input fill:#457b9d
    classDef generator fill:#a8dadc
    classDef renderer fill:#48cae4
    classDef interface fill:#adb5bd
    classDef filler fill:#fca311
    classDef output fill:#90be6d

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Input Layer]:::input
        L3[Generator]:::generator
        L4[Renderers]:::renderer
        L5[Interfaces]:::interface
        L6[Fillers]:::filler
        L7[Output]:::output
    end
```
