# thomthom/true-bend architecture

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

- Interactive diagram: https://gitdiagram.com/thomthom/true-bend
- Repository: https://github.com/thomthom/true-bend

## Overview

##### Main Components
- Extension Initialization & Bootstrap: The entry points are the main script (src/tt_truebend/main.rb) and bootstrap files (src/tt_truebend/bootstrap.rb). These modules initialize the extension when loaded within SketchUp.
- Command & VCB Input Handling: The modules that parse input and manage commands (e.g., src/tt_truebend/command.rb and src/tt_truebend/vcb_parser.rb) handle user commands including VCB input for angles, segment counts, and distance values.
- Geometry Manipulation: The “bender” (src/tt_truebend/bender.rb) and various geometry modules (e.g., src/tt_truebend/geom, which contains polar_projection, polygon, and segment) are core to the bending logic. They perform calculations to adjust the geometry without altering the original length.
- Graphics & Rendering: The modules under src/tt_truebend/gl (like bender_drawer.rb, grid.rb, slicer.rb, etc.) are responsible for drawing the updated geometry and displaying it to the user.
- Configuration & Settings: Files such as app_settings.rb and settings.rb provide the ability to read and manage the extension’s configuration, including user preferences and internal constants found in the constants directory.
- Helpers, Observers, and Tools: Supporting functionalities are provided by helper modules (e.g., src/tt_truebend/helpers/), observers for transaction handling (src/tt_truebend/observers/transaction.rb) and tools (src/tt_truebend/tools/truebend.rb). These help keep the code modular and maintain separation of concerns.

##### Relationships & Interactions
- The Extension Initialization component triggers the setup process (bootstrap), which then loads configuration settings and registers commands.
- When a SketchUp user interacts with the extension (for example with a VCB input), the command handler and VCB parser interpret the input. They pass the instructions to the bender module, which updates the underlying geometry.
- Observer modules monitor transactions and assist with undo/redo capabilities, ensuring consistent application state.

##### Architectural Patterns & Design Principles
- Modularity: The clear separation into directories (commands, constants, geom, gl, helpers, etc.) shows a modular design. Each module focuses on a specific concern such as input management, computation, or rendering.
- Command Pattern: The handling of VCB inputs and extension commands suggests a command pattern for decoupling the input handling from execution.
- MVC-like Separation: Though not a strict implementation, components like the model (geometry and bender), view (gl/drawing modules), and controller (command handling and bootstrap) illustrate separation of responsibilities.
- Extensibility: With a “vendor” folder and an extension.json file, the design is ready for further integration or customization if external libraries or additional settings are needed.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interface
    UI("User Interface: SketchUp VCB Input"):::ui

    %% External Entity
    VIEW("SketchUp Viewport"):::external

    %% Initialization & Configuration
    subgraph "Initialization & Configuration"
        MAIN("Bootstrap: main.rb"):::init
        BOOT("Bootstrap: bootstrap.rb"):::init
        APP("Configuration: app_settings.rb"):::config
        SET("Configuration: settings.rb"):::config
        CONST("Configuration: constants"):::config
    end

    %% Command & VCB Input Handling
    subgraph "Command & VCB Input Handling"
        CMD("Command: command.rb"):::command
        VCB("VCB Parser: vcb_parser.rb"):::command
    end

    %% Geometry Manipulation
    subgraph "Geometry Manipulation"
        BENDER("Bender: bender.rb"):::geometry
        GEOM("Geometry Modules: geom"):::geometry
    end

    %% Graphics & Rendering
    subgraph "Graphics & Rendering"
        GL("GL Modules: gl"):::rendering
    end

    %% Supporting Modules
    subgraph "Supporting Modules"
        HELP("Helpers: helpers"):::support
        OBS("Transaction Observer: transaction.rb"):::support
        TOOL("Tool: truebend.rb"):::support
    end

    %% Additional Assets & Resources
    subgraph "Additional Assets & Resources"
        MEDIA("Media"):::assets
        DOCS("Documentation"):::assets
    end

    %% Data Flow Connections
    UI -->|"input"| CMD
    UI -->|"input"| VCB

    %% Initialization influences command processing
    MAIN -->|"initializes"| CMD
    BOOT -->|"bootstraps"| CMD
    APP -->|"configures"| CMD
    SET -->|"configures"| CMD
    CONST -->|"configures"| CMD

    %% Initialization influences rendering configuration
    APP -->|"configures"| GL
    SET -->|"configures"| GL
    CONST -->|"configures"| GL

    %% Command & VCB handling to Geometry
    CMD -->|"sends command"| BENDER
    VCB -->|"sends input"| BENDER

    %% Supporting modules help processing
    HELP -->|"assists"| CMD
    HELP -->|"assists"| BENDER
    OBS -->|"observes"| CMD
    TOOL -->|"assists"| CMD

    %% Geometry Manipulation Workflow
    BENDER -->|"calculates"| GEOM
    GEOM -->|"provides data"| GL

    %% Rendering to SketchUp Viewport
    GL -->|"renders"| VIEW

    %% Additional Assets feeds UI for reference
    DOCS -->|"provides guidance"| UI

    %% Click Events for Initialization & Configuration
    click MAIN "https://github.com/thomthom/true-bend/blob/master/src/tt_truebend/main.rb"
    click BOOT "https://github.com/thomthom/true-bend/blob/master/src/tt_truebend/bootstrap.rb"
    click APP "https://github.com/thomthom/true-bend/blob/master/src/tt_truebend/app_settings.rb"
    click SET "https://github.com/thomthom/true-bend/blob/master/src/tt_truebend/settings.rb"
    click CONST "https://github.com/thomthom/true-bend/tree/master/src/tt_truebend/constants"

    %% Click Events for Command & VCB Input Handling
    click CMD "https://github.com/thomthom/true-bend/blob/master/src/tt_truebend/command.rb"
    click VCB "https://github.com/thomthom/true-bend/blob/master/src/tt_truebend/vcb_parser.rb"

    %% Click Events for Geometry Manipulation
    click BENDER "https://github.com/thomthom/true-bend/blob/master/src/tt_truebend/bender.rb"
    click GEOM "https://github.com/thomthom/true-bend/tree/master/src/tt_truebend/geom"

    %% Click Events for Graphics & Rendering
    click GL "https://github.com/thomthom/true-bend/tree/master/src/tt_truebend/gl"

    %% Click Events for Supporting Modules
    click HELP "https://github.com/thomthom/true-bend/tree/master/src/tt_truebend/helpers"
    click OBS "https://github.com/thomthom/true-bend/blob/master/src/tt_truebend/observers/transaction.rb"
    click TOOL "https://github.com/thomthom/true-bend/blob/master/src/tt_truebend/tools/truebend.rb"

    %% Click Events for Additional Assets & Resources
    click MEDIA "https://github.com/thomthom/true-bend/tree/master/media"
    click DOCS "https://github.com/thomthom/true-bend/tree/master/docs"

    %% Styles
    classDef init fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef config fill:#B0E0E6,stroke:#000,stroke-width:1px;
    classDef command fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef geometry fill:#FFFACD,stroke:#000,stroke-width:1px;
    classDef rendering fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef support fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef assets fill:#F5DEB3,stroke:#000,stroke-width:1px;
    classDef ui fill:#FFDEAD,stroke:#000,stroke-width:1px;
    classDef external fill:#C0C0C0,stroke:#000,stroke-width:1px;
```
