# jmerriweather/gcode architecture

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

- Interactive diagram: https://gitdiagram.com/jmerriweather/gcode
- Repository: https://github.com/jmerriweather/gcode

## Overview

##### Core Components Organization

a) Interface Layer:
- Entry point: `Gcode` module
- Command handling: `GcodeCommand` module
- Handler interface: `Gcode.Handler` and `Gcode.DefaultHandler`

b) State Machine Layer:
- Central component: `Gcode.Machine`
- State management: `Gcode.Machine.State`

c) Processing States Layer (arranged in logical flow):

##### Component Relationships

- State transitions between different machine states
- Data flow from the interface layer through the state machine
- Error handling paths
- Command processing flow

##### Specific Implementation Details

Key architectural elements:
- State machine pattern implementation
- Handler pattern for extensibility
- Error handling pathways
- Command processing pipeline

- Interface     |
- Layer        |

- ↓

- State Machine |
- Controller    |

- ↓

- Processing    |
- States        |

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef interface fill:#a8d1f0,stroke:#333
    classDef stateMachine fill:#b8e994,stroke:#333
    classDef processingState fill:#f8c291,stroke:#333
    classDef errorState fill:#ff7979,stroke:#333
    classDef utility fill:#dfe4ea,stroke:#333

    subgraph Interface
        Gcode["Gcode Module"]
        GcodeCommand["GCode Command"]
        Handler["Handler Interface"]
        DefaultHandler["Default Handler"]
    end

    subgraph StateMachine
        Machine["State Machine Controller"]
        MachineState["State Management"]
    end

    subgraph ProcessingStates
        Detecting["Detecting"]
        Connecting["Connecting"]
        Connected["Connected"]
        Analysing["Analysing"]
        Sanitising["Sanitising"]
        Parsing["Parsing"]
        Decompressing["Decompressing"]
        Printing["Printing"]
        Error["Error State"]
    end

    %% Relationships
    Gcode --> GcodeCommand
    GcodeCommand --> Handler
    Handler --> DefaultHandler
    Handler --> Machine
    Machine --> MachineState
    MachineState --> Detecting
    Detecting --> Connecting
    Connecting --> Connected
    Connected --> Analysing
    Analysing --> Sanitising
    Sanitising --> Parsing
    Parsing --> Decompressing
    Decompressing --> Printing
    
    %% Error handling paths
    Detecting --> Error
    Connecting --> Error
    Connected --> Error
    Analysing --> Error
    Sanitising --> Error
    Parsing --> Error
    Decompressing --> Error
    Printing --> Error
    Error --> MachineState

    %% Click events
    click Gcode "https://github.com/jmerriweather/gcode/blob/master/lib/gcode.ex"
    click GcodeCommand "https://github.com/jmerriweather/gcode/blob/master/lib/gcode_command.ex"
    click Handler "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/handler.ex"
    click DefaultHandler "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/default_handler.ex"
    click Machine "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/machine.ex"
    click MachineState "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/machine/state.ex"
    click Detecting "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/machine/detecting.ex"
    click Connecting "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/machine/connecting.ex"
    click Connected "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/machine/connected.ex"
    click Analysing "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/machine/analysing.ex"
    click Sanitising "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/machine/sanitising.ex"
    click Parsing "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/machine/parsing.ex"
    click Decompressing "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/machine/decompressing.ex"
    click Printing "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/machine/printing.ex"
    click Error "https://github.com/jmerriweather/gcode/blob/master/lib/gcode/machine/error.ex"

    %% Style applications
    class Gcode,GcodeCommand,Handler,DefaultHandler interface
    class Machine,MachineState stateMachine
    class Detecting,Connecting,Connected,Analysing,Sanitising,Parsing,Decompressing,Printing processingState
    class Error errorState

    %% Legend
    subgraph Legend
        L1["Interface Component"]:::interface
        L2["State Machine Component"]:::stateMachine
        L3["Processing State"]:::processingState
        L4["Error State"]:::errorState
    end
```
