# nandodev1997/neoprinter-sdk-android architecture

> Architecture diagram of the GitHub repository nandodev1997/neoprinter-sdk-android, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nandodev1997/neoprinter-sdk-android
- Repository: https://github.com/nandodev1997/neoprinter-sdk-android

## Overview

1. **Repository type and runtime**
   - This is an **Android library module** (`NeoPrinterSDK`) written in **Kotlin**, designed to be consumed by other Android apps.
   - It targets **ESC/POS thermal printing** and exposes both **Kotlin DSL** and **Java-friendly callback/builder APIs**.

2. **Top-level architecture**
   - The library is organized around a single orchestration layer, `PrinterManager`, which coordinates:
     - permission checks,
     - printer discovery/selection,
     - connection creation,
     - print execution,
     - and network diagnostics.
   - Around that core are smaller, focused components for transport, UI, and print command building.

3. **Connection/transport layer**
   - The repo clearly supports two printer transport paths:
     - **Bluetooth** via `BluetoothPrinter.kt`
     - **TCP/IP network** via `NetworkPrinter.kt`
   - These are the concrete device-connection boundaries, separating transport details from the higher-level printing API.

4. **Printer abstraction and catalog**
   - `PrinterDevice.kt` likely represents a printer identity/configuration model used across the SDK.
   - `PrinterCatalog.kt` suggests a saved or known-printer registry that the picker and manager use to present available devices.
   - This creates a clean split between **device metadata** and **live connection objects**.

5. **Main orchestration service**
   - `PrinterManager.kt` is the central façade.
   - From the README, it appears to provide methods such as:
     - opening the picker and connecting,
     - running ping/network checks,
     - and likely mediating access to the builder-based print API.
   - For an architecture diagram, this is the main hub that connects UI, permissions, catalog, and transport.

6. **Print command construction**
   - `PrintBuilder.kt` is the print-engine layer.
   - It exposes a fluent/DSL-style API for composing ESC/POS commands: text formatting, layout rows, dividers, QR/barcodes, bitmap output, paper feed, cut, and drawer pulse.
   - This is the key boundary between **application content generation** and **printer-specific command encoding**.

7. **User-facing selection flow**
   - `PrinterPickerDialog.kt` provides the UI for discovering or choosing printers.
   - The README indicates `pickAndConnect(...)` opens this dialog, then returns a connection on success.
   - This makes the selection flow: **user action → picker dialog → chosen device → connection setup**.

8. **Permission boundary**
   - `PrinterPermissionHelper.kt` encapsulates runtime permission handling, especially important for:
     - Bluetooth permissions on Android 12+,
     - location-related access for discovery,
     - and internet access for network printers.
   - This isolates Android permission complexity from the rest of the SDK.

9. **Progress / feedback UI**
   - `PrintingProgressDialog.kt` indicates a small UI component for showing print-related progress or connection status.
   - This suggests the SDK includes user feedback during potentially long operations like connecting, discovering, or sending print jobs.

10. **Error model**
   - `PrinterException.kt` is the library’s dedicated failure boundary.
   - It likely normalizes transport, permission, discovery, and print-command errors into a consistent exception type for consumers.

11. **Support for Kotlin and Java consumers**
   - The README shows both Kotlin DSL usage and Java callback-based usage.
   - That implies the public API is designed to be **language-interoperable**, with the core fluent API wrapped in Java-compatible entry points where needed.

12. **Resources and Android packaging**
   - The `res/` folder contains icons, colors, styles, and strings used by the picker/progress UI.
   - Drawable assets differentiate Bluetooth vs network printers visually, reinforcing the two transport types in the UI.
   - Gradle/Kotlin build files and `jitpack.yml` show this is intended for publishing as a reusable dependency.

13. **Data flow summary**
   - Typical flow is:
     - app requests permission via `PrinterPermissionHelper`,
     - `PrinterManager` opens `PrinterPickerDialog`,
     - user selects a `PrinterDevice` from the `PrinterCatalog`,
     - a `BluetoothPrinter` or `NetworkPrinter` connection is created,
     - `PrintBuilder` generates ESC/POS commands,
     - commands are sent to the printer,
     - success/failure is returned to the caller.

14. **Architectural boundaries to draw**
   - For a diagram, the main boundaries are:
     - **Host app** vs **NeoPrinter SDK**
     - **Permission/UI layer** vs **core orchestration**
     - **Print composition** vs **transport execution**
     - **Bluetooth** vs **TCP/IP network** as parallel adapter paths
     - **Reusable models/catalog** vs **runtime connections**

Main entry points: [`NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterManager.kt`](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterManager.kt) (Printer Manager), [`NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterPickerDialog.kt`](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterPickerDialog.kt) (Picker Dialog), [`NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrintBuilder.kt`](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrintBuilder.kt) (Print Builder), [`NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrintingProgressDialog.kt`](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrintingProgressDialog.kt) (Progress Dialog)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sdk_core["SDK Core"]
  node_printer_manager["Printer Manager<br/>facade<br/>[PrinterManager.kt]"]
  node_printer_permission_helper["Permissions<br/>helper"]
  node_printer_catalog[("Printer Catalog<br/>registry<br/>[PrinterCatalog.kt]")]
  node_printer_device["Printer Device<br/>model<br/>[PrinterDevice.kt]"]
  node_print_builder["Print Builder<br/>dsl<br/>[PrintBuilder.kt]"]
  node_printer_exception["Printer Error<br/>error model"]
end

subgraph group_transport["Transports"]
  node_bluetooth_printer["Bluetooth Printer<br/>transport adapter"]
  node_network_printer["Network Printer<br/>transport adapter<br/>[NetworkPrinter.kt]"]
end

subgraph group_ui["Android UI"]
  node_printer_picker_dialog(("Picker Dialog<br/>ui dialog"))
  node_printing_progress_dialog(("Progress Dialog<br/>ui dialog"))
end

subgraph group_assets["Resources"]
  node_res_strings["Strings<br/>resource bundle<br/>[strings.xml]"]
  node_res_colors["Colors<br/>resource bundle<br/>[colors.xml]"]
  node_res_styles["Styles<br/>resource bundle<br/>[styles.xml]"]
  node_ic_bt["BT Icon<br/>drawable<br/>[ic_printer_bt.xml]"]
  node_ic_network["Net Icon<br/>drawable"]
end

node_host_app["Host App<br/>consumer"]

node_host_app -->|"uses"| node_printer_manager
node_printer_manager -->|"checks"| node_printer_permission_helper
node_printer_manager -->|"opens"| node_printer_picker_dialog
node_printer_manager -->|"reads"| node_printer_catalog
node_printer_picker_dialog -->|"selects"| node_printer_device
node_printer_catalog -->|"contains"| node_printer_device
node_printer_manager -->|"connects"| node_bluetooth_printer
node_printer_manager -->|"connects"| node_network_printer
node_printer_manager -->|"executes"| node_print_builder
node_print_builder -.->|"encodes for"| node_bluetooth_printer
node_print_builder -.->|"encodes for"| node_network_printer
node_printer_picker_dialog -->|"labels"| node_res_strings
node_printer_picker_dialog -->|"styles"| node_res_styles
node_printing_progress_dialog -->|"labels"| node_res_strings
node_printing_progress_dialog -->|"themes"| node_res_colors
node_printer_picker_dialog -->|"shows"| node_ic_bt
node_printer_picker_dialog -->|"shows"| node_ic_network
node_printer_manager -->|"shows"| node_printing_progress_dialog
node_printer_manager -->|"throws"| node_printer_exception
node_bluetooth_printer -->|"reports"| node_printer_exception
node_network_printer -->|"reports"| node_printer_exception

click node_printer_manager "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterManager.kt"
click node_printer_permission_helper "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterPermissionHelper.kt"
click node_printer_catalog "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterCatalog.kt"
click node_printer_device "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterDevice.kt"
click node_print_builder "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrintBuilder.kt"
click node_printer_exception "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterException.kt"
click node_bluetooth_printer "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/BluetoothPrinter.kt"
click node_network_printer "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/NetworkPrinter.kt"
click node_printer_picker_dialog "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterPickerDialog.kt"
click node_printing_progress_dialog "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrintingProgressDialog.kt"
click node_res_strings "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/res/values/strings.xml"
click node_res_colors "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/res/values/colors.xml"
click node_res_styles "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/res/values/styles.xml"
click node_ic_bt "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/res/drawable/ic_printer_bt.xml"
click node_ic_network "https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/res/drawable/ic_printer_network.xml"

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_printer_manager,node_printer_permission_helper,node_printer_catalog,node_printer_device,node_print_builder,node_printer_exception toneBlue
class node_bluetooth_printer,node_network_printer toneAmber
class node_printer_picker_dialog,node_printing_progress_dialog toneMint
class node_res_strings,node_res_colors,node_res_styles,node_ic_bt,node_ic_network toneRose
class node_host_app toneNeutral
```

## Components

### SDK Core

Public orchestration, models, and print composition

- [Printer Manager](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterManager.kt): facade · Main entry point coordinating permissions, picker, transport, and print flow · `NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterManager.kt`
- [Permissions](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterPermissionHelper.kt): helper · Handles runtime permission checks for Bluetooth, discovery, and network access · `NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterPermissionHelper.kt`
- [Printer Catalog](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterCatalog.kt): registry · Saved or known printers available for selection · `NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterCatalog.kt`
- [Printer Device](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterDevice.kt): model · Printer identity and configuration data · `NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterDevice.kt`
- [Print Builder](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrintBuilder.kt): dsl · Fluent ESC/POS command builder for text, layout, images, codes, feed, cut, and drawer pulse · `NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrintBuilder.kt`
- [Printer Error](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterException.kt): error model · Unified exception boundary for permission, discovery, transport, and print failures · `NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterException.kt`

### Transports

Printer connection adapters

- [Bluetooth Printer](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/BluetoothPrinter.kt): transport adapter · Bluetooth connection and send path · `NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/BluetoothPrinter.kt`
- [Network Printer](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/NetworkPrinter.kt): transport adapter · TCP/IP connection and diagnostics path · `NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/NetworkPrinter.kt`

### Android UI

Picker and progress screens

- [Picker Dialog](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterPickerDialog.kt): ui dialog · UI for discovering and choosing a printer · `NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterPickerDialog.kt`
- [Progress Dialog](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrintingProgressDialog.kt): ui dialog · Feedback UI for connect and print operations · `NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrintingProgressDialog.kt`

### Resources

Icons, strings, colors, and styles

- [Strings](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/res/values/strings.xml): resource bundle · UI text and labels used by the dialogs · `NeoPrinterSDK/src/main/res/values/strings.xml`
- [Colors](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/res/values/colors.xml): resource bundle · Theme and status colors · `NeoPrinterSDK/src/main/res/values/colors.xml`
- [Styles](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/res/values/styles.xml): resource bundle · Dialog and UI styling definitions · `NeoPrinterSDK/src/main/res/values/styles.xml`
- [BT Icon](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/res/drawable/ic_printer_bt.xml): drawable · Bluetooth printer icon · `NeoPrinterSDK/src/main/res/drawable/ic_printer_bt.xml`
- [Net Icon](https://github.com/nandodev1997/neoprinter-sdk-android/blob/main/NeoPrinterSDK/src/main/res/drawable/ic_printer_network.xml): drawable · Network printer icon · `NeoPrinterSDK/src/main/res/drawable/ic_printer_network.xml`

### Other components

- **Host App**: consumer · Android app embedding the SDK

## Connections

- Host App → Printer Manager: uses · App calls the SDK façade
- Printer Manager → Permissions: checks · Validates runtime access before discovery or connection
- Printer Manager → Picker Dialog: opens · Starts printer selection flow
- Printer Manager → Printer Catalog: reads · Uses saved or known printers for selection
- Picker Dialog → Printer Device: selects · Returns the chosen printer identity
- Printer Catalog → Printer Device: contains · Registry of printer metadata
- Printer Manager → Bluetooth Printer: connects · Creates Bluetooth printer sessions
- Printer Manager → Network Printer: connects · Creates TCP/IP printer sessions
- Printer Manager → Print Builder: executes · Sends built ESC/POS jobs to the active transport
- Print Builder → Bluetooth Printer: encodes for · Produces commands for Bluetooth delivery
- Print Builder → Network Printer: encodes for · Produces commands for network delivery
- Picker Dialog → Strings: labels · Uses resource text in the picker UI
- Picker Dialog → Styles: styles · Uses dialog styling
- Progress Dialog → Strings: labels · Uses resource text in the progress UI
- Progress Dialog → Colors: themes · Uses status and theme colors
- Picker Dialog → BT Icon: shows · Visualizes Bluetooth printers
- Picker Dialog → Net Icon: shows · Visualizes network printers
- Printer Manager → Progress Dialog: shows · Displays feedback during connect and print operations
- Printer Manager → Printer Error: throws · Normalizes failures into a shared error type
- Bluetooth Printer → Printer Error: reports · Surfaces transport errors
- Network Printer → Printer Error: reports · Surfaces transport and diagnostic errors
