| 1 | ---
|
| 2 | description: posprint architecture and stack conventions
|
| 3 | globs: src/**/*
|
| 4 | alwaysApply: true
|
| 5 | ---
|
| 6 |
|
| 7 | # Architecture rules
|
| 8 |
|
| 9 | ## Stack (do not change without updating docs)
|
| 10 |
|
| 11 | - **Rust only** — no TypeScript/JavaScript frontend.
|
| 12 | - **egui / eframe** for UI (`src/app.rs`, `src/main.rs`).
|
| 13 | - **USB-serial printing only** — `src/print/mod.rs` via `serialport`. No Bluetooth or USB printer-class code until explicitly requested.
|
| 14 |
|
| 15 | ## Module responsibilities
|
| 16 |
|
| 17 | | Module | Responsibility |
|
| 18 | |--------|----------------|
|
| 19 | | `dsl/` | Parse template text → `Document` AST |
|
| 20 | | `params.rs` | Collect `${Name}` tokens; substitute at print time |
|
| 21 | | `escpos.rs` | AST → ESC/POS bytes (in-tree; no `escpos` crate) |
|
| 22 | | `preview.rs` | AST → `PreviewModel` for UI canvas |
|
| 23 | | `io/` | `PosFile` JSON load/save |
|
| 24 | | `print/` | Port enumeration, `SerialTransport`, `MockTransport` |
|
| 25 | | `app.rs` | All egui UI: editor, preview, help, print dialog |
|
| 26 |
|
| 27 | Keep business logic out of `app.rs` where possible — UI should call `lib` modules.
|
| 28 |
|
| 29 | ## Dependencies
|
| 30 |
|
| 31 | Add a crate only when hand-rolling is unreasonable. Current allowed set:
|
| 32 |
|
| 33 | - `eframe`, `serde`, `serde_json`, `serialport`, `image`, `rfd`
|
| 34 |
|
| 35 | Do **not** add `escpos`, `nusb`, `tauri`, or a JS toolchain without a deliberate stack change and doc update.
|
| 36 |
|
| 37 | ## Preview vs print
|
| 38 |
|
| 39 | - **Preview:** approximate layout; placeholders for barcode/QR/image; unresolved `${Param}` shown literally.
|
| 40 | - **Print:** substitute parameters first, then encode ESC/POS, then write to serial port at **9600 baud**.
|
| 41 |
|
| 42 | ## Planned features (not in codebase yet)
|
| 43 |
|
| 44 | 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.
|