# stszone/aspos-print-agent architecture

> Architecture diagram of the GitHub repository stszone/aspos-print-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stszone/aspos-print-agent
- Repository: https://github.com/stszone/aspos-print-agent

## Overview

ASPOS Print Agent is an on-site Node.js service that receives print jobs from ASPOS over Reverb, prints raw ESC/POS bytes to network printers, and reports outcomes. The main workflow is connection → entry-point job handling → worker → printer, with failed jobs persisted and retried; successful receipts also enter local history for emergency reprints. The agent additionally exposes health and local-receipt endpoints and sends heartbeats. Relationships follow the README and shown source/import references; installer and service-management files are outside the runtime map.

Main entry points: [`src/index.js`](https://github.com/stszone/aspos-print-agent/blob/main/src/index.js) (Agent entry point), [`src/backend.js`](https://github.com/stszone/aspos-print-agent/blob/main/src/backend.js) (Backend API client), [`src/connection.js`](https://github.com/stszone/aspos-print-agent/blob/main/src/connection.js) (Reverb connection), [`src/health.js`](https://github.com/stszone/aspos-print-agent/blob/main/src/health.js) (Health and reprint API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Agent runtime"]
  node_entry["Agent entry point<br/>[index.js]"]
  node_config["Configuration<br/>[config.js]"]
  node_logger["Logging<br/>[logger.js]"]
end

subgraph group_delivery["Job delivery"]
  node_connection["Reverb connection<br/>[connection.js]"]
  node_backendapi["Backend API client<br/>[backend.js]"]
  node_worker["Print job worker<br/>[worker.js]"]
  node_printer["TCP printer dispatch<br/>[printer.js]"]
end

subgraph group_persistence["Local persistence"]
  node_buffer[("Retry queue<br/>[buffer.js]")]
  node_history[("Print history<br/>[history.js]")]
  node_sqljs["SQLite runtime<br/>[sqljs.js]"]
end

subgraph group_operations["Operations"]
  node_health["Health and reprint API<br/>[health.js]"]
end

node_operator(("POS staff"))
node_adminui(("Admin UI"))
node_cloud["ASPOS backend"]
node_printerdevice["Network printer"]

node_entry -->|"loads"| node_config
node_entry -->|"opens and manages"| node_buffer
node_entry -->|"opens and records"| node_history
node_entry -->|"starts"| node_connection
node_entry -->|"starts"| node_health
node_entry -->|"processes jobs with"| node_worker
node_entry -->|"reports heartbeat"| node_backendapi
node_connection -->|"delivers job events"| node_entry
node_connection -->|"authenticates channel"| node_backendapi
node_backendapi -->|"calls API"| node_cloud
node_connection -->|"receives WebSocket jobs"| node_cloud
node_worker -->|"sends ESC/POS bytes"| node_printer
node_printer -->|"writes TCP"| node_printerdevice
node_worker -->|"reports result"| node_backendapi
node_entry -->|"queues and retries"| node_buffer
node_entry -->|"records successful receipts"| node_history
node_entry -->|"reports abandoned jobs"| node_backendapi
node_health -->|"reads recent receipts"| node_history
node_health -->|"dispatches reprint callback"| node_entry
node_adminui -->|"requests status or reprint"| node_health
node_operator -.->|"requests reprint"| node_adminui
node_buffer -->|"initializes database"| node_sqljs
node_history -->|"initializes database"| node_sqljs
node_connection -->|"reads settings"| node_config
node_backendapi -->|"reads credentials and URL"| node_config
node_health -->|"reads endpoint settings"| node_config
node_logger -->|"reads log level"| node_config
node_buffer -->|"logs queue events"| node_logger
node_history -->|"logs history events"| node_logger
node_worker -->|"logs processing"| node_logger
node_printer -->|"logs dispatch"| node_logger

click node_entry "https://github.com/stszone/aspos-print-agent/blob/main/src/index.js"
click node_config "https://github.com/stszone/aspos-print-agent/blob/main/src/config.js"
click node_logger "https://github.com/stszone/aspos-print-agent/blob/main/src/logger.js"
click node_connection "https://github.com/stszone/aspos-print-agent/blob/main/src/connection.js"
click node_backendapi "https://github.com/stszone/aspos-print-agent/blob/main/src/backend.js"
click node_worker "https://github.com/stszone/aspos-print-agent/blob/main/src/worker.js"
click node_printer "https://github.com/stszone/aspos-print-agent/blob/main/src/printer.js"
click node_buffer "https://github.com/stszone/aspos-print-agent/blob/main/src/buffer.js"
click node_history "https://github.com/stszone/aspos-print-agent/blob/main/src/history.js"
click node_sqljs "https://github.com/stszone/aspos-print-agent/blob/main/src/sqljs.js"
click node_health "https://github.com/stszone/aspos-print-agent/blob/main/src/health.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_entry,node_config,node_logger,node_adminui toneBlue
class node_connection,node_backendapi,node_worker,node_printer toneAmber
class node_buffer,node_history,node_sqljs toneMint
class node_health toneRose
class node_operator,node_cloud,node_printerdevice toneIndigo
```

## Components

### Agent runtime

- [Agent entry point](https://github.com/stszone/aspos-print-agent/blob/main/src/index.js): `src/index.js`
- [Configuration](https://github.com/stszone/aspos-print-agent/blob/main/src/config.js): `src/config.js`
- [Logging](https://github.com/stszone/aspos-print-agent/blob/main/src/logger.js): `src/logger.js`

### Job delivery

- [Reverb connection](https://github.com/stszone/aspos-print-agent/blob/main/src/connection.js): `src/connection.js`
- [Backend API client](https://github.com/stszone/aspos-print-agent/blob/main/src/backend.js): `src/backend.js`
- [Print job worker](https://github.com/stszone/aspos-print-agent/blob/main/src/worker.js): `src/worker.js`
- [TCP printer dispatch](https://github.com/stszone/aspos-print-agent/blob/main/src/printer.js): `src/printer.js`

### Local persistence

- [Retry queue](https://github.com/stszone/aspos-print-agent/blob/main/src/buffer.js): `src/buffer.js`
- [Print history](https://github.com/stszone/aspos-print-agent/blob/main/src/history.js): `src/history.js`
- [SQLite runtime](https://github.com/stszone/aspos-print-agent/blob/main/src/sqljs.js): `src/sqljs.js`

### Operations

- [Health and reprint API](https://github.com/stszone/aspos-print-agent/blob/main/src/health.js): `src/health.js`

### Other components

- **POS staff**
- **Admin UI**
- **ASPOS backend**
- **Network printer**

## Connections

- Agent entry point → Configuration: loads (evidence: `src/index.js`)
- Agent entry point → Retry queue: opens and manages (evidence: `src/index.js`)
- Agent entry point → Print history: opens and records (evidence: `src/index.js`)
- Agent entry point → Reverb connection: starts (evidence: `src/index.js`)
- Agent entry point → Health and reprint API: starts (evidence: `src/index.js`)
- Agent entry point → Print job worker: processes jobs with (evidence: `src/index.js`)
- Agent entry point → Backend API client: reports heartbeat (evidence: `src/index.js`)
- Reverb connection → Agent entry point: delivers job events (evidence: `src/index.js`)
- Reverb connection → Backend API client: authenticates channel (evidence: `src/connection.js`)
- Backend API client → ASPOS backend: calls API (evidence: `src/backend.js`)
- Reverb connection → ASPOS backend: receives WebSocket jobs (evidence: `README.md`)
- Print job worker → TCP printer dispatch: sends ESC/POS bytes (evidence: `src/worker.js`)
- TCP printer dispatch → Network printer: writes TCP (evidence: `README.md`)
- Print job worker → Backend API client: reports result (evidence: `src/worker.js`)
- Agent entry point → Retry queue: queues and retries (evidence: `src/index.js`)
- Agent entry point → Print history: records successful receipts (evidence: `src/index.js`)
- Agent entry point → Backend API client: reports abandoned jobs (evidence: `src/index.js`)
- Health and reprint API → Print history: reads recent receipts (evidence: `src/health.js`)
- Health and reprint API → Agent entry point: dispatches reprint callback (evidence: `src/index.js`)
- Admin UI → Health and reprint API: requests status or reprint (evidence: `README.md`)
- POS staff → Admin UI: requests reprint
- Retry queue → SQLite runtime: initializes database (evidence: `src/buffer.js`)
- Print history → SQLite runtime: initializes database (evidence: `src/history.js`)
- Reverb connection → Configuration: reads settings (evidence: `src/connection.js`)
- Backend API client → Configuration: reads credentials and URL (evidence: `src/backend.js`)
- Health and reprint API → Configuration: reads endpoint settings (evidence: `src/health.js`)
- Logging → Configuration: reads log level (evidence: `src/logger.js`)
- Retry queue → Logging: logs queue events (evidence: `src/buffer.js`)
- Print history → Logging: logs history events (evidence: `src/history.js`)
- Print job worker → Logging: logs processing (evidence: `src/worker.js`)
- TCP printer dispatch → Logging: logs dispatch (evidence: `src/printer.js`)
