Technical reference for the JetPrint system: Cloud Relay HTTP/WebSocket APIs, Tauri v2 Rust backend, React/TypeScript frontend, production deployment, and GitHub Actions release pipeline.
See
README.mdfor quick-start,OWNER_SETUP_GUIDE.mdfor shop-owner setup, anddesktop-kiosk/src-tauri/UPDATER_SETUP.mdfor signing key setup.
- 1. System Architecture & Data Flow
- 2. Cloud Relay (
cloud-relay/) - 3. Tauri v2 Rust Backend (
desktop-kiosk/src-tauri/) - 4. React / TypeScript Frontend (
desktop-kiosk/src/) - 5. GitHub Actions Release Pipeline & Auto-Updater
- 6. Production Deployment & Shop Onboarding
- 7. Local Development & Testing Commands
Customer Mobile Browser
│ 1. Scans QR -> GET /upload?machine_id=<id>
│ 2. Fetches pricing -> GET /api/machines/:machineId
│ 3. Uploads PDF/Images -> POST /api/jobs (EXIF auto-rotation, PDF normalization, creates Razorpay order)
│ 4. Completes UPI payment -> Razorpay sends POST /api/webhooks/razorpay
▼
Cloud Relay (cloud-relay/)
│ 5. Verifies x-razorpay-signature (HMAC-SHA256), generates 6-digit OTP
│ 6. Dispatches job over WebSocket (/ws); if kiosk is offline, job stays queued as unacknowledged
▼
Tauri v2 Desktop Kiosk (desktop-kiosk/src-tauri/)
│ 7. ws_client.rs receives job_dispatch (or flushes unacknowledged jobs on connect/reconnect)
│ 8. Downloads files via GET /api/jobs/:jobId/files/:fileId with 3-attempt progressive backoff
│ 9. Inserts job + OTP into local SQLite (jetprint.db -> print_jobs), emits "job-received", and sends job_ack
│ 10. Background sync: polls GET /api/machines/:machineId/active-jobs on connect and queue refresh
▼
Kiosk UI & Print Engines (desktop-kiosk/src/ + printer.rs + macos_print.m)
11. Self-Service OTP keypad (with on-demand GET /api/jobs/by-otp/:otp fallback) OR Owner Mode Queue
12. Dispatches to native macOS PDFKit (Apple) or sanitized CUPS / WinSpool spooler
| Variable | Description | Default |
|---|---|---|
PORT |
HTTP & WebSocket server port | 3000 |
PUBLIC_URL |
Base URL for download_url (auto-detected from Host if empty) |
"" |
RAZORPAY_KEY_ID |
Razorpay Key ID (unset = Dev/Test fallback mode) | "" |
RAZORPAY_KEY_SECRET |
Razorpay Key Secret | "" |
RAZORPAY_WEBHOOK_SECRET |
HMAC-SHA256 secret for POST /api/webhooks/razorpay |
dev_webhook_secret |
DEFAULT_BW_PRICE_PAISE |
Fallback B&W price per page in paise | 200 |
DEFAULT_COLOR_PRICE_PAISE |
Fallback Color price per page in paise | 1000 |
UPLOAD_DIR |
Temporary upload directory | ./uploads |
FILE_TTL_MS |
File retention TTL in milliseconds | 3600000 |
getJpegExifOrientation(buffer): Binary parser for JPEG APP1 markers extracting EXIF Tag0x0112(Orientation).exifOrientationToDegrees(orientation): Converts EXIF tags (3 -> 180°, 6 -> 270° in PDF coordinates, 8 -> 90°) to compensate for camera rotation.checkPdfNeedsNormalization(buffer, mime, name, settings): Detects whether a document contains non-standard page rotations, landscape viewports, or custom sheet sizes.buildPrintReadyPdf(buffer, mime, name, settings): Pre-rotates pages and embeds raster images into a normalized PDF document with standardized media boxes, marked withprint_ready: true.
| Method & Path | Purpose |
|---|---|
GET /upload?machine_id=<id> |
Serves the mobile upload & UPI checkout web app (cloud-relay/public/). |
GET /api/health |
Health check and current payment mode (devMode). |
GET /api/machines/:machineId |
Returns kiosk online status and synced pricing (bwPerPagePaise, colorPerPagePaise, shopName, supportedPaperSizes). |
GET /api/machines/:machineId/active-jobs |
Returns active unprinted jobs for kiosk synchronization. Requires Authorization: Bearer <auth_token> (or ?token=<auth_token>). |
GET /api/jobs/by-otp/:otp |
On-demand OTP lookup fallback returning full job payload and file download URLs. Requires kiosk Authorization: Bearer <auth_token> matching the target machine. |
POST /api/jobs |
Accepts multipart files, machine_id, copies, color (plus per_file_settings); detects PDF page counts; calculates amount in paise; creates Razorpay order (or dev order). |
GET /api/jobs/:jobId/status |
Polls job payment/print status; returns 6-digit otp once paid. |
GET /api/jobs/:jobId/files/:fileId |
Downloads an uploaded file. Requires Authorization: Bearer <auth_token> (or ?token=<auth_token>). |
POST /api/webhooks/razorpay |
Verifies x-razorpay-signature for payment.captured / order.paid, generates 6-digit OTP, pushes job_dispatch via WebSocket. |
POST /api/dev/jobs/:jobId/pay |
Simulates payment when devMode is active (disabled when Razorpay keys are set). |
When a kiosk connects to /ws, it establishes its identity using either a registration or authentication handshake:
- Registration (
type: 'register'): Sent when the kiosk lacks an active authentication token (e.g., initial startup, factory reset, or afterreset_machine_identity).- Deterministic
preferredMachineIdPreservation: If the kiosk transmits amachine_id(the client's hardware/persisted identity), the relay honors and preserves it rather than assigning a random machine ID. - The relay generates a new
authToken, stores the pricing and paper size capabilities, marks the machine online, responds withregistered, and immediately initiates an unacknowledged job flush.
- Deterministic
- Authentication (
type: 'auth'): Sent during standard reconnects when the kiosk has a persistedauth_token.- The relay verifies the token against its registry. If valid, it responds with
auth_okand flushes any pending unacknowledged jobs. - If a kiosk reconnects with a blank or invalid token, the relay re-issues credentials under the preferred machine ID without dropping kiosk identity.
- The relay verifies the token against its registry. If valid, it responds with
- Clearing Stale Auth Errors:
During reconnection attempts (in
RelayHandle::request_reconnectandset_status), any previously recorded auth errors (guard.2) are explicitly cleared (None), ensuring UI badges immediately reflect the active retry state rather than remaining stuck on stale error notices.
To guarantee that jobs paid while the desktop app is closed, suspended, or offline are never lost:
- Unacknowledged Job Flush on Connect/Reconnect:
When customer payment is confirmed via Razorpay webhook or dev pay while a kiosk is offline, the relay generates the 6-digit OTP and holds the job in memory. When the kiosk connects (via either
registerorauth), the relay immediately invokesflushPendingJobs(machineId). This queriesgetUnacknowledgedPaidJobs(machineId)to retrieve all paid/dispatched jobs that have not yet been acknowledged (job.acknowledged !== true), dispatching them in chronological order. - Kiosk Delivery Acknowledgement (
job_ack): Once the desktop kiosk successfully downloads all job files to local disk and commits the job record to SQLite, it transmits ajob_ackmessage over the WebSocket:{ "type": "job_ack", "job_id": "..." }. - Relay Acknowledgement State:
Upon receiving
job_ack(or a terminaljob_status_updateofprinting,printed,failed, orcancelled), the relay marks the job as acknowledged (job.acknowledged = true,job.acknowledgedAt = Date.now()), removing it from subsequent reconnection flushes.
Kiosk → Relay Messages:
register:{ "type": "register", "machine_id"?: string, "pricing": { "bwPerPagePaise", "colorPerPagePaise", "shopName"? }, "supportedPaperSizes"?: string[] }auth:{ "type": "auth", "machine_id": string, "auth_token"?: string, "pricing": { "bwPerPagePaise", "colorPerPagePaise" }, "supportedPaperSizes"?: string[] }pricing_update:{ "type": "pricing_update", "bwPerPagePaise": number, "colorPerPagePaise": number, "shopName"?: string }job_ack:{ "type": "job_ack", "job_id": string }job_status_update:{ "type": "job_status_update", "job_id": string, "status": "printing" | "printed" | "failed" | "cancelled", "error"?: string }ping:{ "type": "ping" }
Relay → Kiosk Messages:
registered/auth_ok:{ "type": "registered" | "auth_ok", "machine_id": string, "auth_token": string, "pricing": { ... }, "supportedPaperSizes": [...] }pricing_ack:{ "type": "pricing_ack", "pricing": { ... } }job_dispatch:{ "type": "job_dispatch", "job_id": "job_...", "otp": "482910", "amount_paise": 1200, "print_settings": { "copies": 2, "color": false }, "files": [ { "file_id": "file_...", "filename": "doc.pdf", "mime_type": "application/pdf", "size_bytes": 12345, "page_count": 3, "download_url": "https://relay.example.com/api/jobs/job_.../files/file_..." } ], "created_at": "2026-11-12T07:00:00.000Z" }pong:{ "type": "pong" }error:{ "type": "error", "code"?: string, "message": string }
src/lib.rs: Initializestauri_plugin_updater,tauri_plugin_process, andtauri_plugin_dialog. Sets upSharedStoragedefaulting to~/Documents/JetPrint KIOSK(with auto-migration from legacy app data), background 48-hour expired job cleanup task, managesAppState, spawnsws_client::spawn_relay_loop, and registers all 24 Tauri commands.src/storage.rs: Dedicated kiosk storage and file lifecycle management:- Default directory
~/Documents/JetPrint KIOSK(or OS Documents directory) housingjetprint.db, downloaded print files injobs/, and rolling diagnostics inlogs/jetprint.log. - Automatic migration from legacy system app data directories on upgrade.
- Background task running hourly to delete printed or cancelled job files older than 48 hours.
- Custom storage folder selection with live disk usage calculation.
- Default directory
src/logger.rs: Rotating application file logger writing tologs/jetprint.logwith support for frontend retrieval and clearing.src/db.rs: SQLite persistence (rusqlite, WAL mode).app_config(singleton rowid = 1):machine_id,relay_url,auth_token,password_hash,recovery_phrase_hash,bw_price_paise(default200),color_price_paise(default1000),default_printer,kiosk_mode('self_service'|'owner'),rush_mode(0|1),setup_complete(0|1).configured_printers:name(PK),nickname,pool(bw|color|large_format|default),capabilities(JSON),is_enabled(0/1),priority(integer).print_jobs:id(PK),otp(indexed),files_json,copies,color,status(pending|printing|printed|failed),created_at,printed_at.
src/security.rs:generate_recovery_phrase(): 12-word BIP39 mnemonic (bip39crate).normalize_phrase()/validate_phrase(): Lowercases, trims whitespace, validates 12-word BIP39.hash_secret()/verify_secret(): Argon2id PHC hashing/verification (argon2crate).
src/macos_print.m: Native macOS PDFKit printing integration (macos_print_pdf):- Bridges Objective-C Cocoa APIs to Rust
extern "C". - Instantiates
PDFDocumentfrom file path and generatesNSPrintOperation. - Configures
kPDFPrintPageScaleToFitwithautoRotate: NO(since pages are pre-normalized), completely eliminating printer manual feed tray prompts and orientation distortions on macOS.
- Bridges Objective-C Cocoa APIs to Rust
src/printer.rs:is_pdf_file(): Inspects file extension, MIME type,print_readysetting, and%PDFmagic bytes to route converted images and documents to native PDFKit or CUPS.build_file_print_properties(): Assembles sanitized CUPS options (fit-to-page,orientation-requested: 3,media-source: auto) while preventing duplicatelandscapetags for pre-composed print-ready documents.list_system_printers(): Enumerates system printers via theprinterscrate, performs canonical name matching, resolves Bonjour ghost loopback aliases (<PrinterName> @ <Host>), and deduplicates network loopback entries.resolve_printer_with_alias_handling(): Intelligent alias resolution matching requested printer names against canonical hardware queues or network aliases, with automatic fallback to the OS default printer.route_file_to_printer(): Capability-based routing matching document requirements (Color/BW, A4/A3/Legal/Letter) with round-robin multi-printer load balancing and graceful fallback cascade.print_job_files_pooled(): Dispatches each file in a job to its resolved printer with fallback handling.print_test_page(): Sends an aligned diagnostic test page to any selected printer.
src/ws_client.rs:build_ws_url(): Convertshttp(s)://tows(s)://.../ws.spawn_relay_loop(): Connects viatokio-tungstenite. Inspectsauth_token: sendsAuthif token exists, orRegisterwith client-persistedmachine_id(preferredMachineId) if token is absent.- Clearing Stale Auth Errors: Clears previously captured connection error states on every reconnect attempt (
guard.2 = None). - Download Retry Backoff (
download_and_save_job): Downloads each file viareqwestwith Bearer auth, using up to 3 attempts with progressive linear backoff (500ms * attempt delay). - Job Acknowledgement: Sends
job_ackover WebSocket upon successful local persistence, emitsjob-receivedto the UI, and updatesrelay-status. - Active Jobs Background Sync (
sync_active_jobs): Spawns automatically upon authentication to reconcile and download unprinted orders fromGET /api/machines/:machineId/active-jobs.
src/commands.rs: Implements all Tauri IPC invocations:verify_otp_and_print: Validates OTP against local SQLite; if not found locally, falls back to querying Cloud Relay (GET /api/jobs/by-otp/:otp), downloads files with retry backoff, saves the job, returnsjob_ack, and proceeds with printing.sync_active_jobs: Reconciles active unprinted jobs from Cloud Relay into local SQLite.
| Command | Category | Arguments | Return Type | Description |
|---|---|---|---|---|
get_kiosk_state |
State | — | KioskState |
Returns active kiosk settings, connection status, and storage path. |
complete_first_run |
Setup | password: string |
CompleteFirstRunResult |
Hashes owner password, creates BIP39 phrase, and finalizes setup. |
verify_owner_password |
Auth | password: string |
boolean |
Verifies Argon2id password hash for Owner Settings. |
reset_password_with_phrase |
Auth | phrase: string, newPassword: string |
void |
Validates BIP39 recovery phrase and updates owner password. |
update_settings |
Settings | settings: UpdateSettingsInput |
KioskState |
Updates printer, pricing, kiosk mode, and reconnects relay. |
reset_machine_identity |
Settings | — | KioskState |
Clears auth token while preserving machine identity for relay re-registration. |
keep_existing_data |
Storage | — | KioskState |
Dismisses existing data prompt and continues with saved DB. |
reset_installation_data |
Storage | — | KioskState |
Deletes local database, clears credentials, and re-triggers setup. |
pick_storage_folder |
Storage | — | string | null |
Native OS folder picker to choose custom storage directory. |
set_storage_path |
Storage | path: string |
KioskState |
Moves database, jobs, and logs to selected storage folder. |
get_logs |
Logs | lines?: number |
string[] |
Reads recent entries from logs/jetprint.log. |
clear_logs |
Logs | — | void |
Clears diagnostic log file contents. |
open_logs_window |
Logs | — | void |
Opens standalone Tauri window to monitor live logs. |
list_printers |
Printer | — | PrinterInfo[] |
Enumerates available OS printers (CUPS / spooler). |
get_configured_printers |
Printer | — | ConfiguredPrinter[] |
Loads configured printers, pool assignments, and capability tags. |
save_configured_printers |
Printer | printers: ConfiguredPrinter[] |
void |
Persists printer pool configurations, nicknames, and active flags. |
test_print |
Printer | printerName: string |
void |
Async command (spawn_blocking, 30s timeout) to print an alignment test page on target printer. |
verify_otp_and_print |
otp: string |
PrintResult |
Async command validating OTP (local DB + on-demand Cloud Relay fallback with download retry backoff) and dispatching job files. | |
print_job_direct |
jobId: string, printerOverrides?: Record<string, string> |
PrintResult |
Async direct print (spawn_blocking, 30s timeout) without OTP (used in Owner Queue & Rush Hour). |
|
sync_active_jobs |
Sync | — | number |
Synchronizes active unprinted jobs from Cloud Relay (GET /api/machines/:machineId/active-jobs) into local SQLite. |
list_jobs |
limit?: number, date?: string |
PrintJob[] |
Queries job history from local SQLite database. | |
cancel_job |
jobId: string |
void |
Marks pending job as failed/cancelled. | |
connect_relay |
Relay | relayUrl?: string |
KioskState |
Updates relay address and forces WebSocket reconnection. |
is_fullscreen |
Window | — | boolean |
Queries current window fullscreen state. |
toggle_fullscreen |
Window | — | boolean |
Toggles between windowed and fullscreen display. |
set_fullscreen |
Window | fullscreen: boolean |
void |
Sets fullscreen mode explicitly. |
check_for_updates |
Updater | — | UpdateCheckResult |
Resilient dual-path update check (GitHub API + Fastly CDN fallback). |
install_update |
Updater | — | void |
Downloads, Minisign-verifies, installs update, and restarts kiosk. |
Emitted Events:
job-received(PrintJobpayload) — fired when a paid job is downloaded and saved to SQLite.relay-status(RelayStatusEvent:{ connected, machineId, message }) — fired on WebSocket connect/disconnect/error.
src/api/tauri.ts: Typed wrappers around all Tauri commands (including printer pooling, direct print, andsyncActiveJobs), event listeners (listenKioskEvents), window controls (toggleFullscreen,setFullscreen), and update helpers (checkForAppUpdate,installUpdateAndRelaunch).src/types.ts: TypeScript interfaces matchingsrc-tauri/src/models.rs(camelCase), includingConfiguredPrinter,PrinterPoolType, andPrinterPoolConfig.src/App.tsx: LoadsKioskState, runs silent background update check on mount, listens forjob-receivedandrelay-status, handlesCtrl+Shift+S/Cmd+Shift+Sand 5-tap corner trigger, handlesF11(toggle fullscreen) andEscape(exit fullscreen), triggerssyncActiveJobs()on reconnect or state refresh when in Owner Mode, and coordinates the Rush Hour Auto-Print Engine:printQueueRef: Sequential First-In, First-Out (FIFO) queue for auto-print jobs.isProcessingQueueRef: Concurrency lock ensuring single-threaded spooler dispatch to prevent driver collisions.enqueueJobForPrint(): Enqueues incoming paid jobs and triggers sequential execution.- Pending Job Recovery Sweep: Sweeps SQLite on Rush Hour toggle and initial state load for
pendingjobs, recovering unprinted jobs after offline or idle periods. - Renders:
QrPanel.tsx: QR code for<relayUrl>/upload?machine_id=<machineId>and pricing.OtpKeypad.tsx: 6-digit touch/keyboard keypad (Self-Service mode) with on-demand cloud relay lookup fallback.OwnerModeQueue.tsx: High-throughput queue with 4 workflow tabs (Action Needed,Completed,Printed,All Jobs), real-time search filtering (Quick search OTP or file...), 10px touch-friendly scrollbar, fluid responsive grid, 10s auto-dismissing banner notice, per-file printer overrides (printerOverrides), Refresh button with spin indicator that triggerssyncActiveJobs(), and removed reprint button for purged documents.FirstRunWizard.tsx: First-run password creation & BIP39 phrase confirmation.OwnerUnlockModal.tsx: Keypad PIN/Password authentication dialog before entering settings.DedicatedSettingsPage.tsx: Full-page settings workspace with Master-Detail printer & pool assignments, interactive pool filter tabs, per-page pricing, mode selection, relay status, and system controls.LogsWindow.tsx: Dedicated live logs inspector.
- Config (
desktop-kiosk/src-tauri/tauri.conf.json):app.windows: Windowed by default (fullscreen: false,center: true,resizable: true).bundle.createUpdaterArtifacts: trueplugins.updater.endpoints:https://github.com/dharantej1/JetPrint/releases/latest/download/latest.jsonplugins.updater.pubkey: Cryptographic Minisign public key (seeUPDATER_SETUP.md).
- Workflow (
.github/workflows/release.yml):- Triggers only on
v*tags. - Matrix builds across 5 runner targets:
macos-latest(aarch64-apple-darwin— Apple Silicon M1–M4)macos-latest(x86_64-apple-darwin— Intel Mac)ubuntu-22.04(x86_64 Linux.deband.AppImage)ubuntu-22.04-arm(native ARM64 Linux.deband.AppImagefor Raspberry Pi 4/5 & ARM64 SBCs)windows-latest(x86_64 NSIS.exeand.msi)
- Linux dependency installation: Installs
libwebkit2gtk-4.1-dev,libappindicator3-dev,librsvg2-dev,patchelf,libcups2-devon all Linux runners (runner.os == 'Linux'). - Multi-Platform Matrix Updater Consolidation (
consolidate-updaterjob):- Solves the GitHub Actions matrix upload race condition where parallel builder jobs overwrite each other's updater manifest.
- Runs
.github/scripts/consolidate-latest-json.jsafter all builder jobs complete. - Inspects release assets and generates a single unified
latest.jsonmanifest mapping 15 platform targets:darwin-aarch64,darwin-aarch64-appdarwin-x86_64,darwin-x86_64-appwindows-x86_64,windows-x86_64-nsiswindows-x86_64-msilinux-x86_64,linux-x86_64-appimagelinux-x86_64-deblinux-x86_64-rpmlinux-aarch64,linux-aarch64-appimage(Raspberry Pi ARM64)linux-aarch64-deb(Raspberry Pi ARM64)linux-aarch64-rpm(Raspberry Pi ARM64)
- Resilient In-App Update Engine:
check_for_updates: Uses dual-path resolution: attempts manifest check with a 2.5-second connect timeout and no-proxy configuration, falling back immediately to the direct GitHub Releases API (api.github.com/repos/.../releases/latest) to bypass CDN cold-start latencies.install_update: Downloads target binary, verifies Minisign signature, installs package, and cleanly relaunches JetPrint viaapp.restart().
- Triggers only on
Tag-Only Release Flow — create and push a semver tag:
git tag vX.Y.Z
git push origin main && git push origin vX.Y.ZThe Sync version from git tag step strips the leading v, validates X.Y.Z, and stamps it into tauri.conf.json, package.json, and Cargo.toml. tauri-action builds the platform installers, and consolidate-updater publishes the unified latest.json.
cloud-relay/ must be deployed on a persistent Node.js host with WebSocket support — such as Render, Railway, Fly.io, or a VPS (DigitalOcean, AWS EC2, Hetzner).
Why not Vercel / serverless? Stateless platforms cannot maintain persistent WebSocket connections (
/ws) or store temporary files (UPLOAD_DIR) across requests.
| Setting | Value |
|---|---|
| Root Directory | cloud-relay |
| Build Command | npm install && npm run build |
| Start Command | npm start |
| Required Env Vars | PUBLIC_URL=https://<your-relay-domain>, RAZORPAY_KEY_ID, RAZORPAY_KEY_SECRET, RAZORPAY_WEBHOOK_SECRET |
In Razorpay Dashboard → Settings → Webhooks, add:
- Webhook URL:
https://<your-relay-domain>/api/webhooks/razorpay - Secret: Same value as
RAZORPAY_WEBHOOK_SECRETin your Cloud Relay env. - Active Events:
payment.captured(and optionallyorder.paid).
- Generate Updater Signing Keypair:
npx tauri signer generate -w ~/.tauri/jetprint.keyand place the public key intauri.conf.json(plugins.updater.pubkey). - Configure GitHub Secrets: Add
TAURI_SIGNING_PRIVATE_KEYandTAURI_SIGNING_PRIVATE_KEY_PASSWORDin Settings → Secrets and variables → Actions. - Build Release Installers: Push a version tag (
git tag v0.1.0 && git push origin v0.1.0) to trigger the workflow and publish installers +updater.json. - Onboard the Shop: Share the OS-specific installer and
OWNER_SETUP_GUIDE.mdwith the shop's publichttps://Cloud Relay URL.
# Cloud Relay: typecheck, test, run cd cloud-relay npx tsc --noEmit npm test npm run dev # Desktop Kiosk Frontend: typecheck & build cd desktop-kiosk npx tsc --noEmit npm run build # Desktop Kiosk Rust Backend: check & test cd desktop-kiosk/src-tauri cargo check cargo test # Full Desktop App (dev mode) cd desktop-kiosk npx tauri dev