# svenhb/grbl-plotter architecture

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

- Interactive diagram: https://gitdiagram.com/svenhb/grbl-plotter
- Repository: https://github.com/svenhb/grbl-plotter

## Overview

##### Project Type and Purpose
- GRBL-Plotter is a Windows desktop “full-stack” application written in C# and .NET 4.0.
- Its purpose is to import, create, manipulate and send G-Code to GRBL-based CNC/plotting hardware via serial ports (and optionally control a 2nd GRBL device or 4th axis).

##### File-Structure Analysis
- Top level:
- GRBL-Plotter.sln – Visual Studio solution
- Firmware/hex_files – static firmware builds for GRBL hardware (supporting multiple versions/configurations)
- GRBL-Plotter/ – main application folder
- data/ – configuration, sample scripts, fonts, automations, buttons, usecases, etc.
- doc/ – markdown docs and screenshots
- Under GRBL-Plotter/:
- GUI/ – WinForms presentation layer
- ImportFromFile/ – domain services to parse incoming file formats (SVG, DXF, Gerber, HPGL, CSV, images) into G-Code or intermediate representations
- Vectorize/ – wrapper around Potrace functionality for vectorizing bitmaps
- MachineControl/ – modules to manage serial communication, GRBL commands, jogging, streaming, 4th-axis control, camera integration, probing
- Properties, Resources – application metadata, localization, settings, logs (NLog.config), and resources
- Program.cs – application entry point

##### Key Architectural Patterns
- Layered architecture:
- Presentation Layer (GUI)
- Application/Domain Layer (GCodeCreation, ImportFromFile, Vectorize, MachineControl, common utilities)
- Infrastructure Layer (serial port abstraction, file I/O, configuration via IniFile.cs, logging via NLog, external notifications via email/pushbullet)
- Plugin/extension style: file-import and G-code creation paths are pluggable by dropping new modules under GCodeCreation or ImportFromFile.
- MVC-style separation: UI forms call into controller classes in Application/Domain; UI contains no business logic.

##### Main Components and Interactions
- GUI (WinForms)
- MainForm, various dialogs (AboutForm, MessageForm, SetupForms…)
- Displays project settings, file dialogs, visual G-Code paths, camera overlay
- Routes user actions to Application services
- G-Code Processing
- ImportFromFile modules parse external files → produce intermediate vector or G-Code model
- Vectorize modules convert bitmaps → vector paths → feed into GCodeCreation
- MachineControl
- SerialPort manager streams G-Code lines to GRBL, interprets status responses
- Supports reconnect, feed/spindle override, jog, probe, height mapping, 4th axis, dual-GRBL control
- Data/Configuration
- data/automations, buttons, usecases – XML/INI presets loaded at runtime for automation scripts and UIBUTTON definitions
- data/fonts, data/tools – resource files used by GCodeCreation
- Infrastructure & External
- IniFile, Settings – persistence of user preferences
- Logging (NLog) – file and console logging
- External notifications – email/pushbullet for progress updates
- Firmware folder – shipped hex images for users to flash GRBL

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point
    Program["Program.cs"]:::presentation

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        GUI["GUI Forms"]:::presentation
        Notifier["External Notifier"]:::presentation
    end

    %% Domain/Application Layer
    subgraph "Application/Domain Layer"
        direction TB
        Import["GCodeImportService"]:::domain
        Vector["VectorizationService"]:::domain
        Create["GCodeCreationService"]:::domain
        Machine["MachineControlService"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        Serial["SerialCommAdapter"]:::infra
        Ini["Configuration Persistence"]:::infra
        Logging["Logging Infrastructure"]:::infra
        FileIO["File I/O"]:::infra
    end

    %% Data & Static Resources
    subgraph "Data & Resources"
        direction TB
        DataRepo["Data/Config Repository"]:::infra
        Firmware["Static Firmware Hex Files"]:::external
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        GRBL["GRBL Hardware"]:::external
        NotifyExt["Email/Pushbullet API"]:::external
    end

    %% Relationships
    Program --> GUI
    GUI -->|calls| Import
    GUI -->|calls| Vector
    GUI -->|calls| Create
    GUI -->|calls| Machine
    Import -->|vector model| Create
    Vector -->|vector paths| Create
    Create -->|G-Code stream| Machine
    Machine <-->|serial I/O| GRBL
    Machine -->|feedback| Vector
    Machine -->|notify| Notifier
    Notifier -->|API calls| NotifyExt

    %% Common infrastructure usage
    subgraph "Infrastructure Dependencies" 
        direction TB
        GUI --> DataRepo
        Import --> DataRepo
        Vector --> DataRepo
        Create --> DataRepo
        Machine --> DataRepo
        GUI --> FileIO
        Import --> FileIO
        Vector --> FileIO
        Create --> FileIO
        Machine --> FileIO
        GUI --> Logging
        Import --> Logging
        Vector --> Logging
        Create --> Logging
        Machine --> Logging
    end

    %% Click Events
    click Program "https://github.com/svenhb/grbl-plotter/blob/master/GRBL-Plotter/Program.cs"
    click GUI "https://github.com/svenhb/grbl-plotter/tree/master/GRBL-Plotter/GUI/"
    click Notifier "https://github.com/svenhb/grbl-plotter/blob/master/GRBL-Plotter/GUI/Notifier.cs"
    click Import "https://github.com/svenhb/grbl-plotter/tree/master/GRBL-Plotter/GCodeCreation/ImportFromFile/"
    click Vector "https://github.com/svenhb/grbl-plotter/tree/master/GRBL-Plotter/GCodeCreation/Vectorize/"
    click Create "https://github.com/svenhb/grbl-plotter/tree/master/GRBL-Plotter/GCodeCreation/"
    click Machine "https://github.com/svenhb/grbl-plotter/tree/master/GRBL-Plotter/MachineControl/"
    click Serial "https://github.com/svenhb/grbl-plotter/blob/master/GRBL-Plotter/MachineControl/SerialPortFixer.cs"
    click Ini "https://github.com/svenhb/grbl-plotter/blob/master/GRBL-Plotter/MachineControl/IniFile.cs"
    click Logging "https://github.com/svenhb/grbl-plotter/blob/master/GRBL-Plotter/NLog.config"
    click DataRepo "https://github.com/svenhb/grbl-plotter/tree/master/GRBL-Plotter/data/"
    click Firmware "https://github.com/svenhb/grbl-plotter/tree/master/Firmware/hex_files/"

    %% Styles
    classDef presentation fill:#C6F6D5,stroke:#2F855A,stroke-width:1px;
    classDef domain fill:#BEE3F8,stroke:#2B6CB0,stroke-width:1px;
    classDef infra fill:#FEEBC8,stroke:#DD6B20,stroke-width:1px;
    classDef external fill:#E2E8F0,stroke:#4A5568,stroke-width:1px;
```
