How barebaric/rayforge works
Project Type and Purpose
• Rayforge is a full-featured, cross-platform desktop application (Python + GTK4 + Libadwaita) for sending and controlling G-code on GRBL-based laser cutters.
• It combines a rich GUI, a core data/model layer for vector and geometry operations, an importer subsystem, a pipeline for path generation and transformation, and a machine-communication layer.
High-Level Architectural Components
a. User Interface Layer (GTK4/Libadwaita)
• MainWindow, dialogs, preferences, canvas (2D/3D), camera overlay, machine status widgets.
• Modules: rayforge/app.py, main_menu.py, mainwindow.py; subpackages: camera/ui, doceditor/ui, machine/ui, shared/ui, workbench, undo/ui.
b. Core Data & Domain Logic
• Data models (items, layers, workflows), geometry operations, config, grouping, undo/redo.
• Modules: rayforge/core, rayforge/shared/units, rayforge/shared/util, rayforge/undo/models.
c. Importer Subsystem
• Parses and renders input formats (SVG, DXF, PDF, PNG, BMP, Ruida).
• Modules: rayforge/importer/*; format-specific importer/parser/renderer.
d. Pipeline & G-code Generation
• Takes core data to produce toolpaths, applies modifiers (filters, tabs), encodes to G-code or preview contexts.
• Modules: rayforge/pipeline/{producer,transformer,modifier,encoder,steprunner}.
e. Machine Communication Layer
• Sends G-code over Serial, HTTP, Telnet, WebSocket; driver abstraction for GRBL, Smoothieware, dummy.
• Modules: rayforge/machine/{driver,transport,models,ui}.
f. Background Tasking & Concurrency
• Offloads long-running jobs (import, pipeline, machine I/O) to a task manager.
• Modules: rayforge/shared/tasker.
g. Localization & Resources
Component Relationships and Data Flows
• User clicks or imports a file → UI Layer dispatches action to Core or Importer.
• Importer reads format → produces vector/document model in Core.
• Core model → passed to Pipeline Producer → generates raw path segments.
• Transformer and Modifier components → optimize, add tabs, apply filters.
• Encoder → produces G-code or preview context → displayed in 3D preview or sent to Machine layer.
• Machine Transport uses selected Driver to send G-code to laser cutter.
• Tasker runs heavy operations asynchronously, reporting progress back to UI.
Architectural Patterns & Design Principles
• Modular separation by responsibility: UI vs domain vs import vs pipeline vs machine.
• MVC/MVP flavor: UI views interact with controllers (actions.py, app.py) and update underlying model.
• Strategy/Plugin pattern in Importer and Machine Driver subsystems to support extensibility.
• Command pattern for undo/redo in core and doceditor (undo/models, doceditor/edit_cmd).
• Task queue for concurrency (shared/tasker).
Key Technologies & Frameworks
• Python 3, GTK4, Libadwaita for GUI.
• PyGObject for GObject introspection.
• External libs: pyvips, potrace, optional OpenCV for camera integration.
• Build/packaging: Pixi (pixi.toml), Meson/pyproject.toml, Snap, Flatpak, Debian packaging.