# eli3162/diw_printer architecture

> Architecture diagram of the GitHub repository eli3162/diw_printer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eli3162/diw_printer
- Repository: https://github.com/eli3162/diw_printer

## Overview

This repository implements firmware and browser-side tools for a low-cost direct-ink-writing 3D printer. The apparent workflow is to prepare or generate printer motion commands, execute them through the printer driver, and communicate with the device; the tree also includes a browser Python environment and editor/terminal assets. The README confirms the printer goal but does not document the browser workflow. Several browser relationships below are therefore shown only where imports are indexed, or left dashed when the runtime connection is not established by the available excerpts.

Main entry points: [`firmware/pyscript/core-7nKZylPm.js`](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/core-7nKZylPm.js) (PyScript runtime), [`firmware/pyscript/codemirror_language-hp5FIdgW.js`](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror_language-hp5FIdgW.js) (Editor language), [`firmware/pyscript/codemirror-DEwTncU0.js`](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror-DEwTncU0.js) (CodeMirror editor), [`firmware/pyscript/codemirror_commands-7WzQPAvy.js`](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror_commands-7WzQPAvy.js) (Editor commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_motion["Motion and G-code"]
  node_gcode_parser["G-code parser<br/>[gcodeparser.py]"]
  node_slice["Path slicing<br/>[slice.py]"]
  node_gcode_generation["G-code generation<br/>[gcodegen.py]"]
  node_generated_runner["Generated runner<br/>[rungcode.py]"]
end

subgraph group_device["Printer Hardware"]
  node_printer_driver["Printer motion driver<br/>[printerdriver.py]"]
  node_firmware_entry["Serial command loop<br/>[main.py]"]
  node_sensor["BME680 sensor<br/>[bme680.py]"]
end

subgraph group_browser["Browser Python Tools"]
  node_printer_gui["Printer GUI<br/>[gui.py]"]
  node_pyscript_core["PyScript runtime<br/>[core-7nKZylPm.js]"]
  node_python_runtime["Pyodide runtime<br/>[pyodide.mjs]"]
  node_micropython_runtime["MicroPython runtime<br/>[micropython.mjs]"]
  node_python_editor["Python editor"]
  node_codemirror_editor["CodeMirror editor"]
  node_editor_state["Editor state"]
  node_editor_view["Editor view"]
  node_editor_language["Editor language"]
  node_editor_commands["Editor commands"]
  node_python_language["Python language support"]
  node_terminal["Browser terminal<br/>[xterm-Bdboj2r8.js]"]
end

subgraph group_transport["Device Communication"]
  node_serial_comms["Serial communications<br/>[serialcom.py]"]
  node_web_serial["Web Serial bridge<br/>[webserial.py]"]
  node_web_serial_client["Web Serial client<br/>[webserial.js]"]
end

node_operator(("Printer operator"))

node_operator -.->|"provides commands"| node_gcode_parser
node_slice -->|"provides paths"| node_gcode_generation
node_gcode_generation -->|"generates driver script"| node_printer_driver
node_generated_runner -->|"uses driver"| node_printer_driver
node_firmware_entry -->|"imports driver"| node_printer_driver
node_operator -.->|"operates printer"| node_printer_gui
node_printer_gui -.->|"uses runtime"| node_pyscript_core
node_pyscript_core -->|"loads editor support"| node_python_editor
node_python_editor -->|"uses runtime"| node_pyscript_core
node_pyscript_core -->|"loads runtime"| node_python_runtime
node_codemirror_editor -->|"imports state"| node_editor_state
node_codemirror_editor -->|"imports view"| node_editor_view
node_codemirror_editor -->|"imports language"| node_editor_language
node_codemirror_editor -->|"imports commands"| node_editor_commands
node_python_language -->|"extends language support"| node_editor_language
node_editor_view -->|"imports state"| node_editor_state
node_editor_language -->|"imports state"| node_editor_state
node_editor_language -->|"imports view"| node_editor_view
node_editor_commands -->|"imports state"| node_editor_state
node_editor_commands -->|"imports view"| node_editor_view
node_editor_commands -->|"imports language"| node_editor_language
node_pyscript_core -->|"loads terminal support"| node_terminal
node_web_serial -->|"imports communications"| node_serial_comms
node_web_serial_client -.->|"uses serial bridge"| node_web_serial
node_operator -.->|"sends commands"| node_web_serial_client
node_serial_comms -.->|"communicates with firmware"| node_firmware_entry

click node_gcode_parser "https://github.com/eli3162/diw_printer/blob/production/firmware/gcodeparser.py"
click node_slice "https://github.com/eli3162/diw_printer/blob/production/firmware/gcodeparsing/slice.py"
click node_gcode_generation "https://github.com/eli3162/diw_printer/blob/production/firmware/gcodeparsing/gcodegen.py"
click node_generated_runner "https://github.com/eli3162/diw_printer/blob/production/firmware/gcodeparsing/rungcode.py"
click node_printer_driver "https://github.com/eli3162/diw_printer/blob/production/firmware/printerdriver.py"
click node_firmware_entry "https://github.com/eli3162/diw_printer/blob/production/firmware/main.py"
click node_sensor "https://github.com/eli3162/diw_printer/blob/production/firmware/bme680.py"
click node_printer_gui "https://github.com/eli3162/diw_printer/blob/production/firmware/gui.py"
click node_pyscript_core "https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/core-7nKZylPm.js"
click node_python_runtime "https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/pyodide/pyodide.mjs"
click node_micropython_runtime "https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/micropython/micropython.mjs"
click node_python_editor "https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/py-editor-CkR6M58-.js"
click node_codemirror_editor "https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror-DEwTncU0.js"
click node_editor_state "https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror_state-bz5DyDhY.js"
click node_editor_view "https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror_view-B9awT57h.js"
click node_editor_language "https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror_language-hp5FIdgW.js"
click node_editor_commands "https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror_commands-7WzQPAvy.js"
click node_python_language "https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror_lang-python-0Uzjxlfw.js"
click node_terminal "https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/xterm-Bdboj2r8.js"
click node_serial_comms "https://github.com/eli3162/diw_printer/blob/production/firmware/serialcom.py"
click node_web_serial "https://github.com/eli3162/diw_printer/blob/production/firmware/webserial.py"
click node_web_serial_client "https://github.com/eli3162/diw_printer/blob/production/firmware/script/webserial.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gcode_parser,node_slice,node_gcode_generation,node_generated_runner toneBlue
class node_printer_driver,node_firmware_entry,node_sensor toneAmber
class node_printer_gui,node_pyscript_core,node_python_runtime,node_micropython_runtime,node_python_editor,node_codemirror_editor,node_editor_state,node_editor_view,node_editor_language,node_editor_commands,node_python_language,node_terminal toneMint
class node_serial_comms,node_web_serial,node_web_serial_client toneRose
class node_operator toneIndigo
```

## Components

### Motion and G-code

- [G-code parser](https://github.com/eli3162/diw_printer/blob/production/firmware/gcodeparser.py): `firmware/gcodeparser.py`
- [Path slicing](https://github.com/eli3162/diw_printer/blob/production/firmware/gcodeparsing/slice.py): `firmware/gcodeparsing/slice.py`
- [G-code generation](https://github.com/eli3162/diw_printer/blob/production/firmware/gcodeparsing/gcodegen.py): `firmware/gcodeparsing/gcodegen.py`
- [Generated runner](https://github.com/eli3162/diw_printer/blob/production/firmware/gcodeparsing/rungcode.py): `firmware/gcodeparsing/rungcode.py`

### Printer Hardware

- [Printer motion driver](https://github.com/eli3162/diw_printer/blob/production/firmware/printerdriver.py): `firmware/printerdriver.py`
- [Serial command loop](https://github.com/eli3162/diw_printer/blob/production/firmware/main.py): `firmware/main.py`
- [BME680 sensor](https://github.com/eli3162/diw_printer/blob/production/firmware/bme680.py): `firmware/bme680.py`

### Browser Python Tools

- [Printer GUI](https://github.com/eli3162/diw_printer/blob/production/firmware/gui.py): `firmware/gui.py`
- [PyScript runtime](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/core-7nKZylPm.js): `firmware/pyscript/core-7nKZylPm.js`
- [Pyodide runtime](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/pyodide/pyodide.mjs): `firmware/pyscript/pyodide/pyodide.mjs`
- [MicroPython runtime](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/micropython/micropython.mjs): `firmware/pyscript/micropython/micropython.mjs`
- [Python editor](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/py-editor-CkR6M58-.js): `firmware/pyscript/py-editor-CkR6M58-.js`
- [CodeMirror editor](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror-DEwTncU0.js): `firmware/pyscript/codemirror-DEwTncU0.js`
- [Editor state](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror_state-bz5DyDhY.js): `firmware/pyscript/codemirror_state-bz5DyDhY.js`
- [Editor view](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror_view-B9awT57h.js): `firmware/pyscript/codemirror_view-B9awT57h.js`
- [Editor language](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror_language-hp5FIdgW.js): `firmware/pyscript/codemirror_language-hp5FIdgW.js`
- [Editor commands](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror_commands-7WzQPAvy.js): `firmware/pyscript/codemirror_commands-7WzQPAvy.js`
- [Python language support](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/codemirror_lang-python-0Uzjxlfw.js): `firmware/pyscript/codemirror_lang-python-0Uzjxlfw.js`
- [Browser terminal](https://github.com/eli3162/diw_printer/blob/production/firmware/pyscript/xterm-Bdboj2r8.js): `firmware/pyscript/xterm-Bdboj2r8.js`

### Device Communication

- [Serial communications](https://github.com/eli3162/diw_printer/blob/production/firmware/serialcom.py): `firmware/serialcom.py`
- [Web Serial bridge](https://github.com/eli3162/diw_printer/blob/production/firmware/webserial.py): `firmware/webserial.py`
- [Web Serial client](https://github.com/eli3162/diw_printer/blob/production/firmware/script/webserial.js): `firmware/script/webserial.js`

### Other components

- **Printer operator**

## Connections

- Printer operator → G-code parser: provides commands
- Path slicing → G-code generation: provides paths (evidence: `firmware/gcodeparsing/slice.py`)
- G-code generation → Printer motion driver: generates driver script (evidence: `firmware/gcodeparsing/gcodegen.py`)
- Generated runner → Printer motion driver: uses driver (evidence: `firmware/gcodeparsing/rungcode.py`)
- Serial command loop → Printer motion driver: imports driver (evidence: `firmware/main.py`)
- Printer operator → Printer GUI: operates printer
- Printer GUI → PyScript runtime: uses runtime
- PyScript runtime → Python editor: loads editor support (evidence: `firmware/pyscript/core-7nKZylPm.js`)
- Python editor → PyScript runtime: uses runtime (evidence: `firmware/pyscript/py-editor-CkR6M58-.js`)
- PyScript runtime → Pyodide runtime: loads runtime (evidence: `firmware/pyscript/core-7nKZylPm.js`)
- CodeMirror editor → Editor state: imports state (evidence: `firmware/pyscript/codemirror-DEwTncU0.js`)
- CodeMirror editor → Editor view: imports view (evidence: `firmware/pyscript/codemirror-DEwTncU0.js`)
- CodeMirror editor → Editor language: imports language (evidence: `firmware/pyscript/codemirror-DEwTncU0.js`)
- CodeMirror editor → Editor commands: imports commands (evidence: `firmware/pyscript/codemirror-DEwTncU0.js`)
- Python language support → Editor language: extends language support (evidence: `firmware/pyscript/codemirror_lang-python-0Uzjxlfw.js`)
- Editor view → Editor state: imports state (evidence: `firmware/pyscript/codemirror_view-B9awT57h.js`)
- Editor language → Editor state: imports state (evidence: `firmware/pyscript/codemirror_language-hp5FIdgW.js`)
- Editor language → Editor view: imports view (evidence: `firmware/pyscript/codemirror_language-hp5FIdgW.js`)
- Editor commands → Editor state: imports state (evidence: `firmware/pyscript/codemirror_commands-7WzQPAvy.js`)
- Editor commands → Editor view: imports view (evidence: `firmware/pyscript/codemirror_commands-7WzQPAvy.js`)
- Editor commands → Editor language: imports language (evidence: `firmware/pyscript/codemirror_commands-7WzQPAvy.js`)
- PyScript runtime → Browser terminal: loads terminal support (evidence: `firmware/pyscript/core-7nKZylPm.js`)
- Web Serial bridge → Serial communications: imports communications (evidence: `firmware/webserial.py`)
- Web Serial client → Web Serial bridge: uses serial bridge
- Printer operator → Web Serial client: sends commands
- Serial communications → Serial command loop: communicates with firmware
