# Feasibility and complexity assessment

## Executive summary

| Question | Answer |
|----------|--------|
| Is it feasible? | **Yes** — all required capabilities exist in mature libraries or documented protocols |
| Overall complexity | **Medium–high** for a complete v1; **medium** if Bluetooth is deferred |
| Biggest risk | Cross-platform raw printer I/O (USB class, serial, Bluetooth SPP) |
| Recommended MVP scope | USB-serial printers first; add USB-printer-class and Bluetooth in v1.1 |

A focused MVP is realistic for one developer in roughly **6–10 weeks**. A polished v1 with broad printer compatibility is closer to **3–4 months**.

---

## Requirements breakdown

### 1. Cross-platform desktop app (Windows + Linux)

| Aspect | Feasibility | Complexity |
|--------|-------------|------------|
| Single codebase, native binaries | High | Low–medium |
| Packaged installers (.msi/.exe, .deb/AppImage) | High | Medium |

Modern cross-platform desktop frameworks (Tauri, egui, Avalonia, Qt) all support Windows and Linux. Packaging is routine but needs CI and per-OS testing.

### 2. Markdown-like document syntax + live preview

| Aspect | Feasibility | Complexity |
|--------|-------------|------------|
| Custom lightweight DSL | High | Medium |
| Live preview pane | High | Medium |
| Width modes (auto-scale / fixed mm) | High | Low–medium |

The DSL does not need full CommonMark — a small, POS-oriented grammar keeps the parser simple. Preview renders to a monospace layout matching printer dot width (e.g. 384 dots @ 58 mm, 576 dots @ 80 mm). Matching exact printer fonts is approximate in preview; exact fidelity is only guaranteed at print time.

### 3. Save / load `.pos` files

| Aspect | Feasibility | Complexity |
|--------|-------------|------------|
| JSON or TOML envelope + body text | High | Low |

Trivial with serde (Rust) or equivalent. Version field supports forward-compatible evolution.

### 4. Parameter tokens (`${Name}`)

| Aspect | Feasibility | Complexity |
|--------|-------------|------------|
| Parse and collect unique names | High | Low |
| Print-time modal with last-used values | High | Low |
| Deduplicate same name across document | High | Low |
| Use in text, barcodes, QR, images | High | Low–medium |

Straightforward string substitution after validation. Image parameters might reference file paths or base64 — define clearly in DSL spec.

### 5. Barcodes, QR codes, images

| Aspect | Feasibility | Complexity |
|--------|-------------|------------|
| Generate ESC/POS barcode commands | High | Low |
| Generate ESC/POS QR commands | High | Low |
| Rasterize images to printer width | High | Medium |

The [`escpos`](https://crates.io/crates/escpos) Rust crate (and similar libraries in other languages) already implements barcodes, QR, and raster graphics. Preview can use the same generation path and render bitmaps in the UI.

### 6. Direct USB / Bluetooth printing (raw bytes, no spooler)

| Aspect | Feasibility | Complexity |
|--------|-------------|------------|
| USB serial (CDC-ACM, CH340, FTDI) | **High** | Medium |
| USB printer class (bulk OUT) | Medium | **High** |
| Bluetooth Classic SPP | Medium | **High** |
| Enumerate devices in UI | Medium | Medium |
| Printer-specific quirks | Ongoing | **High** |

This is the **primary technical risk**.

#### How POS printers actually connect

Most consumer thermal printers expose one of:

1. **Virtual COM port (USB-serial)** — very common; appears as `COM3` (Windows) or `/dev/ttyUSB0` / `/dev/ttyACM0` (Linux). Raw ESC/POS bytes are written to the serial port. **Easiest path.**

2. **USB printer class (interface 7)** — bulk transfers to endpoint; needs `libusb`/`nusb` on Linux and either WinUSB/Zadig or Windows `usbprint.sys` on Windows. The `escpos` crate’s `usbprint` feature uses the Windows kernel driver without replacing it.

3. **Bluetooth Classic SPP** — serial profile; paired device appears as a COM port (Windows) or `/dev/rfcomm*` (Linux). Requires platform Bluetooth APIs for discovery; connection is then serial I/O.

4. **Network (TCP 9100)** — common in production but **out of scope** unless added later.

“No drivers” in practice means **no Windows print spooler / CUPS job** — the app opens the device directly and writes bytes. USB-serial devices often need only the generic CDC driver already present. USB-printer-class devices on Windows may still use `usbprint.sys`, which is a kernel driver but not a vendor-specific print driver.

#### Compatibility reality

- **MVP:** Target Epson-compatible ESC/POS over USB-serial. Covers a large share of cheap 58/80 mm printers.
- **v1:** Add USB printer class via `nusb` / `usbprint`.
- **v1.1:** Add Bluetooth SPP discovery and pairing UX.

Expect **per-printer testing**; some devices need init sequences, code pages, or cut commands that differ slightly.

---

## Complexity by subsystem

```
                    Effort (relative)
Editor UI           ████████░░  Medium
Preview renderer    ███████░░░  Medium
DSL parser          ██████░░░░  Medium
File I/O            ██░░░░░░░░  Low
Parameters          ███░░░░░░░  Low
Barcode/QR/image    █████░░░░░  Low–medium
Printer discovery   ███████░░░  Medium
Raw print I/O       █████████░  High
Integration/polish  ██████░░░░  Medium
```

---

## Effort estimate (one experienced developer)

| Phase | Scope | Duration |
|-------|-------|----------|
| **0 — Design** | Specs, DSL, file format | 1 week |
| **1 — Core** | Parser, ESC/POS builder, preview, `.pos` I/O | 2–3 weeks |
| **2 — UI** | Editor, preview split, settings, parameters dialog | 2 weeks |
| **3 — Print MVP** | USB-serial enumeration + print | 1–2 weeks |
| **4 — Hardening** | USB class, BT, edge cases, packaging | 2–4 weeks |

**MVP (serial USB only):** ~6–8 weeks  
**Full v1 (USB + BT, packaged):** ~10–14 weeks  

Add 30–50% if the developer is new to Rust or ESC/POS.

---

## Risks and mitigations

| Risk | Impact | Mitigation |
|------|--------|------------|
| Printer hardware diversity | Prints garbled or not at all | ESC/POS subset doc; test matrix; user-selectable code page |
| Linux permissions (`dialout`) | Cannot open serial port | Document group membership; clear error UI |
| Windows USB access | Admin / driver conflicts | Prefer serial-first; use `usbprint` where applicable |
| Bluetooth pairing UX | Users cannot find printer | Defer BT; link to OS pairing instructions |
| Preview ≠ print | User confusion | Label preview as approximate; same backend for print |
| Image size on narrow paper | Slow print or clipped | Auto-scale to page width; warn in UI |

---

## Out of scope (v1)

- Network printers (TCP 9100)
- Non-ESC/POS protocols (Star Line, ZPL)
- Multi-column layout engines
- Collaborative editing / cloud sync
- macOS (feasible later with same stack)

---

## Recommendation

**Proceed.** Start with a **serial-USB MVP** on **Rust + Tauri 2**, prove the DSL and preview loop, then expand transport layers. Defer Bluetooth until USB paths are stable.

See [LANGUAGE-CHOICE.md](LANGUAGE-CHOICE.md) for stack details and [ARCHITECTURE.md](ARCHITECTURE.md) for module layout.
