# kaijesussek/zplprinterpro architecture

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

- Interactive diagram: https://gitdiagram.com/kaijesussek/zplprinterpro
- Repository: https://github.com/kaijesussek/zplprinterpro

## Overview

ZplPrinterPro parses ZPL II into label and printer-memory representations, rasterizes labels, and serves the result through a TCP print server and HTTP interface. The main workflow is a ZPL client sending a session to the server, which parses each label, renders a PNG, and archives the raw ZPL span and image. The server also handles host-status queries and exposes labels, printer state, and storage to the web UI. The README documents additional parser and renderer capabilities; some server wiring is inferred from that documentation because its implementation was not sampled.

Main entry points: [`zpl-server/src/tcp.rs`](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/tcp.rs) (TCP Sessions), [`zpl/src/cmd.rs`](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/cmd.rs) (Command Dispatch), [`zpl/src/ir.rs`](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/ir.rs) (Label IR), [`zpl/src/render/mod.rs`](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/render/mod.rs) (Bitmap and PNG)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_parser["ZPL Parsing"]
  node_scanner["Stream Scanner<br/>[scanner.rs]"]
  node_commands["Command Dispatch<br/>[cmd.rs]"]
  node_parse_state["Parse Context<br/>[state.rs]"]
  node_label_ir["Label IR<br/>[ir.rs]"]
  node_printer_memory[("Printer Memory<br/>[memory.rs]")]
  node_codepages["Codepages<br/>[codepage.rs]"]
end

subgraph group_render["Label Rendering"]
  node_graphics["Graphics<br/>[draw.rs]"]
  node_text_render["Text Rendering<br/>[text.rs]"]
  node_barcode_render["Barcode Rendering<br/>[barcode.rs]"]
  node_barcode_encoders["Barcode Encoders<br/>[bc2d.rs]"]
  node_bitmap["Bitmap and PNG<br/>[mod.rs]"]
end

subgraph group_server["Print Server"]
  node_tcp["TCP Sessions<br/>[tcp.rs]"]
  node_host_queries["Host Queries<br/>[hs.rs]"]
  node_protocol["Session Protocol<br/>[proto.rs]"]
  node_archive[("Label Archive<br/>[archive.rs]")]
  node_app_state["Application State<br/>[state.rs]"]
end

subgraph group_web["HTTP and UI"]
  node_http_api["HTTP API<br/>[http.rs]"]
  node_web_ui["Web UI<br/>[app.js]"]
end

node_zpl_client(("ZPL Client"))
node_browser(("Browser User"))

node_zpl_client -->|"sends ZPL"| node_tcp
node_tcp -->|"processes sessions"| node_protocol
node_tcp -->|"parses stream"| node_scanner
node_scanner -->|"yields tokens"| node_commands
node_commands -->|"updates state"| node_parse_state
node_commands -->|"builds labels"| node_label_ir
node_commands -->|"stores objects"| node_printer_memory
node_commands -->|"decodes text"| node_codepages
node_tcp -->|"answers queries"| node_host_queries
node_tcp -->|"renders parsed labels"| node_label_ir
node_tcp -->|"archives raw and PNG"| node_archive
node_label_ir -->|"supplies fields"| node_graphics
node_label_ir -->|"supplies text fields"| node_text_render
node_label_ir -->|"supplies barcode fields"| node_barcode_render
node_barcode_render -->|"encodes symbols"| node_barcode_encoders
node_graphics -->|"paints graphics"| node_bitmap
node_text_render -->|"paints text"| node_bitmap
node_barcode_render -->|"paints barcodes"| node_bitmap
node_printer_memory -->|"provides stored objects"| node_bitmap
node_bitmap -->|"provides PNG"| node_archive
node_tcp -->|"updates state"| node_app_state
node_browser -->|"uses interface"| node_web_ui
node_web_ui -->|"requests API"| node_http_api
node_http_api -->|"reads label archive"| node_archive
node_http_api -->|"reads and updates"| node_app_state

click node_scanner "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/scanner.rs"
click node_commands "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/cmd.rs"
click node_parse_state "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/state.rs"
click node_label_ir "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/ir.rs"
click node_printer_memory "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/memory.rs"
click node_codepages "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/codepage.rs"
click node_graphics "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/render/draw.rs"
click node_text_render "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/render/text.rs"
click node_barcode_render "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/render/barcode.rs"
click node_barcode_encoders "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/bc2d.rs"
click node_bitmap "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/render/mod.rs"
click node_tcp "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/tcp.rs"
click node_host_queries "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/hs.rs"
click node_protocol "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/proto.rs"
click node_archive "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/archive.rs"
click node_app_state "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/state.rs"
click node_http_api "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/http.rs"
click node_web_ui "https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/static/app.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_scanner,node_commands,node_parse_state,node_label_ir,node_printer_memory,node_codepages,node_zpl_client,node_browser toneBlue
class node_graphics,node_text_render,node_barcode_render,node_barcode_encoders,node_bitmap toneAmber
class node_tcp,node_host_queries,node_protocol,node_archive,node_app_state toneMint
class node_http_api,node_web_ui toneRose
```

## Components

### ZPL Parsing

- [Stream Scanner](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/scanner.rs): `zpl/src/scanner.rs`
- [Command Dispatch](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/cmd.rs): `zpl/src/cmd.rs`
- [Parse Context](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/state.rs): `zpl/src/state.rs`
- [Label IR](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/ir.rs): `zpl/src/ir.rs`
- [Printer Memory](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/memory.rs): `zpl/src/memory.rs`
- [Codepages](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/codepage.rs): `zpl/src/codepage.rs`

### Label Rendering

- [Graphics](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/render/draw.rs): `zpl/src/render/draw.rs`
- [Text Rendering](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/render/text.rs): `zpl/src/render/text.rs`
- [Barcode Rendering](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/render/barcode.rs): `zpl/src/render/barcode.rs`
- [Barcode Encoders](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/bc2d.rs): `zpl/src/bc2d.rs`
- [Bitmap and PNG](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl/src/render/mod.rs): `zpl/src/render/mod.rs`

### Print Server

- [TCP Sessions](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/tcp.rs): `zpl-server/src/tcp.rs`
- [Host Queries](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/hs.rs): `zpl-server/src/hs.rs`
- [Session Protocol](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/proto.rs): `zpl-server/src/proto.rs`
- [Label Archive](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/archive.rs): `zpl-server/src/archive.rs`
- [Application State](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/state.rs): `zpl-server/src/state.rs`

### HTTP and UI

- [HTTP API](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/src/http.rs): `zpl-server/src/http.rs`
- [Web UI](https://github.com/kaijesussek/zplprinterpro/blob/master/zpl-server/static/app.js): `zpl-server/static/app.js`

### Other components

- **ZPL Client**
- **Browser User**

## Connections

- ZPL Client → TCP Sessions: sends ZPL
- TCP Sessions → Session Protocol: processes sessions
- TCP Sessions → Stream Scanner: parses stream
- Stream Scanner → Command Dispatch: yields tokens
- Command Dispatch → Parse Context: updates state
- Command Dispatch → Label IR: builds labels
- Command Dispatch → Printer Memory: stores objects
- Command Dispatch → Codepages: decodes text
- TCP Sessions → Host Queries: answers queries
- TCP Sessions → Label IR: renders parsed labels
- TCP Sessions → Label Archive: archives raw and PNG
- Label IR → Graphics: supplies fields
- Label IR → Text Rendering: supplies text fields
- Label IR → Barcode Rendering: supplies barcode fields
- Barcode Rendering → Barcode Encoders: encodes symbols
- Graphics → Bitmap and PNG: paints graphics
- Text Rendering → Bitmap and PNG: paints text
- Barcode Rendering → Bitmap and PNG: paints barcodes
- Printer Memory → Bitmap and PNG: provides stored objects
- Bitmap and PNG → Label Archive: provides PNG
- TCP Sessions → Application State: updates state
- Browser User → Web UI: uses interface
- Web UI → HTTP API: requests API
- HTTP API → Label Archive: reads label archive
- HTTP API → Application State: reads and updates
