--- description: posprint architecture and stack conventions globs: src/**/* alwaysApply: true --- # Architecture rules ## Stack (do not change without updating docs) - **Rust only** — no TypeScript/JavaScript frontend. - **egui / eframe** for UI (`src/app.rs`, `src/main.rs`). - **USB-serial printing only** — `src/print/mod.rs` via `serialport`. No Bluetooth or USB printer-class code until explicitly requested. ## Module responsibilities | Module | Responsibility | |--------|----------------| | `dsl/` | Parse template text → `Document` AST | | `params.rs` | Collect `${Name}` tokens; substitute at print time | | `escpos.rs` | AST → ESC/POS bytes (in-tree; no `escpos` crate) | | `preview.rs` | AST → `PreviewModel` for UI canvas | | `io/` | `PosFile` JSON load/save | | `print/` | Port enumeration, `SerialTransport`, `MockTransport` | | `app.rs` | All egui UI: editor, preview, help, print dialog | Keep business logic out of `app.rs` where possible — UI should call `lib` modules. ## Dependencies Add a crate only when hand-rolling is unreasonable. Current allowed set: - `eframe`, `serde`, `serde_json`, `serialport`, `image`, `rfd` Do **not** add `escpos`, `nusb`, `tauri`, or a JS toolchain without a deliberate stack change and doc update. ## Preview vs print - **Preview:** approximate layout; placeholders for barcode/QR/image; unresolved `${Param}` shown literally. - **Print:** substitute parameters first, then encode ESC/POS, then write to serial port at **9600 baud**. ## Planned features (not in codebase yet) USB printer class, Bluetooth, baud autodetect, persisted recent files/parameters, syntax highlighting. Document these only under "Planned" sections — do not implement stubs without a task.