--- 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`). - **Printing:** USB printer-class (`rusb`), Windows spooler (Windows), USB-serial (`serialport`), and optional LAN raw TCP 9100 via `src/print/`. ## Module responsibilities | Module | Responsibility | |--------|----------------| | `dsl/` | Parse template text → `Document` AST | | `params.rs` | Collect `${Name}` tokens; substitute at print / preview | | `escpos.rs` | AST → ESC/POS bytes (in-tree; no `escpos` crate) | | `preview.rs` | AST → `PreviewModel` for UI canvas | | `io/` | `PosFile` JSON load/save | | `print/` | Discovery + transports (USB-direct, spooler, serial, LAN TCP 9100, mock) | | `print_dialog.rs` | Shared print UI | | `app.rs` | Full designer egui UI | 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 set includes: - `eframe`, `serde`, `serde_json`, `serialport`, `rusb`, `image`, `rfd`, `barcoders`, `qrcode`, `clap`, `chrono` Do **not** add `escpos`, `nusb`, `tauri`, or a JS toolchain without a deliberate stack change and doc update. ## Preview vs print - **Preview:** layout from shared wrap; bitmaps for image/barcode/QR; sample or dialog params for `${Param}`. - **Print:** substitute parameters, encode ESC/POS, write via the chosen transport (serial baud is probed). ## Planned features (not in codebase yet) Bluetooth SPP (OS-paired devices only), persisted recent files/parameters, syntax highlighting. Document these only under "Planned" sections — do not implement stubs without a task.