# sahiliot/packflow architecture

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

- Interactive diagram: https://gitdiagram.com/sahiliot/packflow
- Repository: https://github.com/sahiliot/packflow

## Overview

PackFlow is an offline desktop app for composing and printing A4 packing instructions. Factory users choose or edit instructions, optionally apply a template or customize the layout, review the preview, then select a printer and print or export to PDF. Its main domain stages are instruction/template management, document layout, rendering, and print delivery; local SQLite storage preserves instructions and settings. Edges follow explicit README statements and sampled imports/calls; some UI wiring is supported only by the source index, and unsampled internals are not inferred.

Main entry points: [`app/ui/main_window.py`](https://github.com/sahiliot/packflow/blob/main/app/ui/main_window.py) (Main workflow window), [`main.py`](https://github.com/sahiliot/packflow/blob/main/main.py) (Application entry), [`app/ui/layout_editor.py`](https://github.com/sahiliot/packflow/blob/main/app/ui/layout_editor.py) (Visual layout editor), [`app/printing.py`](https://github.com/sahiliot/packflow/blob/main/app/printing.py) (Printer and PDF output)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Desktop workflow"]
  node_app_entry["Application entry<br/>[main.py]"]
  node_main_window["Main workflow window<br/>[main_window.py]"]
  node_instruction_dialog["Instruction editor"]
  node_template_dialog["Template dialog<br/>[template_dialog.py]"]
  node_layout_editor["Visual layout editor<br/>[layout_editor.py]"]
  node_ui_widgets["Preview widgets<br/>[widgets.py]"]
  node_ui_styles["Application styles<br/>[styles.py]"]
end

subgraph group_content["Instructions and layouts"]
  node_instructions["Instruction records<br/>[models.py]"]
  node_document_layout["Automatic pagination<br/>[layout.py]"]
  node_symbols["Packing symbols<br/>[symbols.py]"]
end

subgraph group_render["Preview and printing"]
  node_document_renderer["Document renderer<br/>[renderer.py]"]
  node_print_service["Printer and PDF output<br/>[printing.py]"]
end

subgraph group_local["Local data"]
  node_database[("SQLite storage<br/>[database.py]")]
  node_data_paths["User data paths<br/>[paths.py]"]
  node_diagnostics["Printer diagnostics<br/>[selftest.py]"]
end

node_user(("Factory user"))
node_printer["Windows printer"]

node_user -->|"launches"| node_app_entry
node_app_entry -->|"locates data"| node_data_paths
node_app_entry -->|"opens storage"| node_database
node_app_entry -->|"starts workflow"| node_main_window
node_app_entry -->|"loads styles"| node_ui_styles
node_user -->|"selects instructions"| node_main_window
node_main_window -->|"reads and saves"| node_database
node_main_window -->|"opens editor"| node_instruction_dialog
node_main_window -->|"manages templates"| node_template_dialog
node_main_window -->|"opens editor"| node_layout_editor
node_main_window -->|"builds document"| node_document_layout
node_main_window -->|"updates preview"| node_ui_widgets
node_main_window -->|"requests printing"| node_print_service
node_instruction_dialog -->|"edits records"| node_instructions
node_instruction_dialog -->|"shows preview"| node_ui_widgets
node_layout_editor -->|"draws elements"| node_document_renderer
node_layout_editor -->|"edits document"| node_instructions
node_layout_editor -->|"uses layout"| node_document_layout
node_ui_widgets -->|"renders preview"| node_document_renderer
node_document_layout -->|"creates document"| node_instructions
node_document_renderer -->|"draws symbols"| node_symbols
node_print_service -->|"paints pages"| node_document_renderer
node_print_service -->|"sends print job"| node_printer
node_database -->|"stores records"| node_instructions
node_database -->|"seeds defaults"| node_symbols
node_app_entry -->|"runs diagnostics"| node_diagnostics
node_diagnostics -->|"checks printers"| node_print_service

click node_app_entry "https://github.com/sahiliot/packflow/blob/main/main.py"
click node_main_window "https://github.com/sahiliot/packflow/blob/main/app/ui/main_window.py"
click node_instruction_dialog "https://github.com/sahiliot/packflow/blob/main/app/ui/instruction_dialog.py"
click node_template_dialog "https://github.com/sahiliot/packflow/blob/main/app/ui/template_dialog.py"
click node_layout_editor "https://github.com/sahiliot/packflow/blob/main/app/ui/layout_editor.py"
click node_ui_widgets "https://github.com/sahiliot/packflow/blob/main/app/ui/widgets.py"
click node_ui_styles "https://github.com/sahiliot/packflow/blob/main/app/ui/styles.py"
click node_instructions "https://github.com/sahiliot/packflow/blob/main/app/models.py"
click node_document_layout "https://github.com/sahiliot/packflow/blob/main/app/layout.py"
click node_symbols "https://github.com/sahiliot/packflow/blob/main/app/symbols.py"
click node_document_renderer "https://github.com/sahiliot/packflow/blob/main/app/renderer.py"
click node_print_service "https://github.com/sahiliot/packflow/blob/main/app/printing.py"
click node_database "https://github.com/sahiliot/packflow/blob/main/app/database.py"
click node_data_paths "https://github.com/sahiliot/packflow/blob/main/app/paths.py"
click node_diagnostics "https://github.com/sahiliot/packflow/blob/main/app/selftest.py"

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_app_entry,node_main_window,node_instruction_dialog,node_template_dialog,node_layout_editor,node_ui_widgets,node_ui_styles,node_user toneBlue
class node_instructions,node_document_layout,node_symbols toneAmber
class node_document_renderer,node_print_service toneMint
class node_database,node_data_paths,node_diagnostics toneRose
class node_printer toneIndigo
```

## Components

### Desktop workflow

- [Application entry](https://github.com/sahiliot/packflow/blob/main/main.py): `main.py`
- [Main workflow window](https://github.com/sahiliot/packflow/blob/main/app/ui/main_window.py): `app/ui/main_window.py`
- [Instruction editor](https://github.com/sahiliot/packflow/blob/main/app/ui/instruction_dialog.py): `app/ui/instruction_dialog.py`
- [Template dialog](https://github.com/sahiliot/packflow/blob/main/app/ui/template_dialog.py): `app/ui/template_dialog.py`
- [Visual layout editor](https://github.com/sahiliot/packflow/blob/main/app/ui/layout_editor.py): `app/ui/layout_editor.py`
- [Preview widgets](https://github.com/sahiliot/packflow/blob/main/app/ui/widgets.py): `app/ui/widgets.py`
- [Application styles](https://github.com/sahiliot/packflow/blob/main/app/ui/styles.py): `app/ui/styles.py`

### Instructions and layouts

- [Instruction records](https://github.com/sahiliot/packflow/blob/main/app/models.py): `app/models.py`
- [Automatic pagination](https://github.com/sahiliot/packflow/blob/main/app/layout.py): `app/layout.py`
- [Packing symbols](https://github.com/sahiliot/packflow/blob/main/app/symbols.py): `app/symbols.py`

### Preview and printing

- [Document renderer](https://github.com/sahiliot/packflow/blob/main/app/renderer.py): `app/renderer.py`
- [Printer and PDF output](https://github.com/sahiliot/packflow/blob/main/app/printing.py): `app/printing.py`

### Local data

- [SQLite storage](https://github.com/sahiliot/packflow/blob/main/app/database.py): `app/database.py`
- [User data paths](https://github.com/sahiliot/packflow/blob/main/app/paths.py): `app/paths.py`
- [Printer diagnostics](https://github.com/sahiliot/packflow/blob/main/app/selftest.py): `app/selftest.py`

### Other components

- **Factory user**
- **Windows printer**

## Connections

- Factory user → Application entry: launches (evidence: `README.md`)
- Application entry → User data paths: locates data (evidence: `main.py`)
- Application entry → SQLite storage: opens storage (evidence: `main.py`)
- Application entry → Main workflow window: starts workflow (evidence: `main.py`)
- Application entry → Application styles: loads styles (evidence: `main.py`)
- Factory user → Main workflow window: selects instructions (evidence: `README.md`)
- Main workflow window → SQLite storage: reads and saves (evidence: `app/ui/main_window.py`)
- Main workflow window → Instruction editor: opens editor (evidence: `app/ui/main_window.py`)
- Main workflow window → Template dialog: manages templates (evidence: `app/ui/main_window.py`)
- Main workflow window → Visual layout editor: opens editor (evidence: `app/ui/main_window.py`)
- Main workflow window → Automatic pagination: builds document (evidence: `app/ui/main_window.py`)
- Main workflow window → Preview widgets: updates preview (evidence: `app/ui/main_window.py`)
- Main workflow window → Printer and PDF output: requests printing (evidence: `app/ui/main_window.py`)
- Instruction editor → Instruction records: edits records (evidence: `app/ui/instruction_dialog.py`)
- Instruction editor → Preview widgets: shows preview (evidence: `app/ui/instruction_dialog.py`)
- Visual layout editor → Document renderer: draws elements (evidence: `app/ui/layout_editor.py`)
- Visual layout editor → Instruction records: edits document (evidence: `app/ui/layout_editor.py`)
- Visual layout editor → Automatic pagination: uses layout (evidence: `app/ui/layout_editor.py`)
- Preview widgets → Document renderer: renders preview (evidence: `app/ui/widgets.py`)
- Automatic pagination → Instruction records: creates document (evidence: `app/layout.py`)
- Document renderer → Packing symbols: draws symbols (evidence: `app/renderer.py`)
- Printer and PDF output → Document renderer: paints pages (evidence: `app/printing.py`)
- Printer and PDF output → Windows printer: sends print job (evidence: `README.md`)
- SQLite storage → Instruction records: stores records (evidence: `app/database.py`)
- SQLite storage → Packing symbols: seeds defaults (evidence: `app/database.py`)
- Application entry → Printer diagnostics: runs diagnostics (evidence: `main.py`)
- Printer diagnostics → Printer and PDF output: checks printers (evidence: `app/selftest.py`)
