# vilemduha/blendercam architecture

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

- Interactive diagram: https://gitdiagram.com/vilemduha/blendercam
- Repository: https://github.com/vilemduha/blendercam

## Overview

##### Project Type and Main Purpose
- Project Type: A Blender add-on (a plugin) that adds CAM capabilities.
- Purpose: It provides users with artistic, personal, or industrial CNC milling guidance by generating toolpaths and g-code, simulating milling operations, and incorporating various post-processors.

##### Main Components
a. Blender Environment & Integration:
– Represent Blender as the host environment.
– Show “config” files (startup.blend, userpref.blend) and “Examples” that demonstrate how the add-on is loaded and used.
– Include the add-on’s integration points with Blender’s UI (panels, menus, pie menus) which are implemented in the “scripts/addons/cam/ui/” and “scripts/addons/cam/ui/panels” directories.

b. Core CAM Engine:
– Point out that it uses several modules from “scripts/addons/cam” such as “bas_relief.py”, “collision.py”, and “gcode_import_parser.py”.
– Include “utilities” submodule for geometry, machine, and material utilities (files in “scripts/addons/cam/utilities/”) which support the core algorithms.

c. Operations & Operators:
– Represent a block for Operator Modules (scripts/addons/cam/operators) that implement various cutting operations such as pocketing, slicing, pattern creation, and more.
– Indicate that these modules serve as the interface between user actions (from Blender’s UI) and the CAM engine.

d. Presets and Configuration:
– Show a section for “Presets” which contain cutter definitions, machine setups, and predefined operations (located under “scripts/addons/cam/presets”).
– This part lets users quickly load specific settings for different milling setups.

e. Post-Processors:
– Create a dedicated block for Post-Processors (found in “scripts/addons/cam/post_processors”), which are responsible for converting the CAM engine’s output into machine-specific g-code.
– Label several of the supported post-processors used for GRBL, LinuxCNC/EMC2, Fadal, and others.

f. Testing and CI/CD:
– Include a block for the “tests” folder (scripts/addons/cam/tests) that holds developer tests and test data, ensuring the functionality is continuously validated.
– Optionally, include a note on the GitHub workflows (.github/workflows) which automate building, testing, documentation generation, and release management.

##### Relationships and Data Flow
- UI events call the CAM Engine (business logic) which processes geometry and simulates the toolpath generation.
- The CAM Engine then hands off data to the Post-Processors for generating g-code.
- Presets and user preferences provide configuration inputs to the CAM engine.
- Testing and CI workflows support the entire codebase, ensuring quality and integration.

##### Architectural Patterns and Design Principles
- Modular structure: separation of UI components, core processing routines, utility libraries, and post-processing modules.
- That the add-on leverages the Model-View-Controller (MVC) concept – where the “model” represents the CAM engine and data structures; the “view” is implemented via Blender’s UI panels and menus; and the “controller” is distributed among the operator modules.
- Extensibility: the clear separation of post-processors and presets makes it simple to add support for new machines or operations.

##### Technologies, Frameworks, and Libraries
- Python is the primary language.
- Integration with Blender’s Python API.
- External libraries referenced through the “wheels” folder (e.g., OpenCAMLib, Shapely, and any numba/ocl utilities) that assist with computational geometry and performance enhancements.
- CI/CD workflows on GitHub integrate tools like Black (code formatter) for maintaining code quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Blender Environment & Integration
    subgraph "Blender Environment & Integration"
        BHost("Blender (Host)"):::ui
        Startup("Startup Config"):::ui
        UserPref("User Pref Config"):::ui
        UI_Scripts("UI Scripts"):::ui
        UI_Panels("UI Panels"):::ui
        BHost -->|"loads"| Startup
        BHost -->|"loads"| UserPref
        BHost -->|"provides"| UI_Scripts
        BHost -->|"provides"| UI_Panels
    end

    %% Operations & Operators
    subgraph "Operations & Operators"
        Operators("Operators"):::op
        UI_Scripts -->|"triggers"| Operators
        UI_Panels -->|"triggers"| Operators
    end

    %% Core CAM Engine
    subgraph "Core CAM Engine"
        Engine("Engine"):::core
        Strategy("Strategy"):::core
        Slice("Slice"):::core
        Simulation("Simulation"):::core
        BasRelief("Bas Relief"):::core
        Collision("Collision"):::core
        GcodeParser("Gcode Import Parser"):::core
        Utilities("Utilities"):::core

        Operators -->|"calls"| Engine
        Operators -->|"calls"| Strategy
        Operators -->|"calls"| Slice
        Operators -->|"calls"| Simulation
        Operators -->|"calls"| BasRelief
        Operators -->|"calls"| Collision
        Operators -->|"calls"| GcodeParser
        Operators -->|"calls"| Utilities

        Presets -->|"configures"| Engine
        Simulation -->|"generates"| PostProc
    end

    %% Presets & Configurations
    subgraph "Presets & Configurations"
        Presets("Presets"):::preset
    end

    %% Post-Processors
    subgraph "Post-Processors"
        PostProc("Post-Processors"):::post
        Engine -->|"gcode"| PostProc
    end

    %% Testing and CI/CD
    subgraph "Testing and CI/CD"
        Tests("Tests"):::test
        CI("CI/CD Workflows"):::test
        Tests -->|"validates"| Operators
        CI -->|"automates"| Operators
    end

    %% Styles
    classDef ui fill:#AED6F1,stroke:#2980B9,stroke-width:2px;
    classDef op fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef core fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef preset fill:#D5DBDB,stroke:#7B7D7D,stroke-width:2px;
    classDef post fill:#FAD7A0,stroke:#F39C12,stroke-width:2px;
    classDef test fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;

click Startup "https://github.com/vilemduha/blendercam/blob/master/config/startup.blend"
click UserPref "https://github.com/vilemduha/blendercam/blob/master/config/userpref.blend"
click UI_Scripts "https://github.com/vilemduha/blendercam/tree/master/scripts/addons/cam/ui"
click UI_Panels "https://github.com/vilemduha/blendercam/tree/master/scripts/addons/cam/ui/panels"
click Engine "https://github.com/vilemduha/blendercam/blob/master/scripts/addons/cam/engine.py"
click Strategy "https://github.com/vilemduha/blendercam/blob/master/scripts/addons/cam/strategy.py"
click Slice "https://github.com/vilemduha/blendercam/blob/master/scripts/addons/cam/slice.py"
click Simulation "https://github.com/vilemduha/blendercam/blob/master/scripts/addons/cam/simulation.py"
click BasRelief "https://github.com/vilemduha/blendercam/blob/master/scripts/addons/cam/bas_relief.py"
click Collision "https://github.com/vilemduha/blendercam/blob/master/scripts/addons/cam/collision.py"
click GcodeParser "https://github.com/vilemduha/blendercam/blob/master/scripts/addons/cam/gcode_import_parser.py"
click Utilities "https://github.com/vilemduha/blendercam/tree/master/scripts/addons/cam/utilities/"
click Operators "https://github.com/vilemduha/blendercam/tree/master/scripts/addons/cam/operators/"
click Presets "https://github.com/vilemduha/blendercam/tree/master/scripts/addons/cam/presets/"
click PostProc "https://github.com/vilemduha/blendercam/tree/master/scripts/addons/cam/post_processors/"
click Tests "https://github.com/vilemduha/blendercam/tree/master/scripts/addons/cam/tests/"
click CI "https://github.com/vilemduha/blendercam/tree/master/.github/workflows/"
```
