# chinthanasathyajithcs/qpaste architecture

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

- Interactive diagram: https://gitdiagram.com/chinthanasathyajithcs/qpaste
- Repository: https://github.com/chinthanasathyajithcs/qpaste

## Overview

#### Purpose and Entry Point
QPaste is a Windows-resident clipboard utility that turns copied text into a bounded FIFO paste queue. It runs as a PyQt6 system-tray application, intercepting copy/paste-related events while avoiding foreground-window disruption. The process starts at `src/main.py`; packaging targets a Windows executable via `qpaste.spec`.

#### Application Composition
The entry point assembles the core services, UI surfaces, lifecycle handling, and event loop:
- `src/main.py`
- `src/core/state.py`
- `src/core/single_instance.py`

A Win32 named mutex rejects a second process before competing listeners or hotkeys can start. Application state centralizes whether Queue Mode is active and coordinates user-driven actions such as toggle and clear.

#### Clipboard Queue Domain
The queue is the primary in-memory domain model: thread-safe, FIFO, and capped at 25 items. Copy operations append text; eligible paste operations consume the oldest item. Empty queues deliberately fall back to normal Windows paste behavior.
- `src/core/clipboard_queue.py`
- `src/core/state.py`

The queue is ephemeral by design; auto-clear and explicit clear remove retained clipboard content rather than persisting it.

#### Native Event and Clipboard Boundary
`src/core/listener.py` bridges the app to Windows keyboard hooks and clipboard APIs. It observes `Ctrl+C`, captures clipboard text after copy, and on `Ctrl+V` supplies the queue head when Queue Mode is enabled. This layer owns clipboard contention handling, including retries for temporary clipboard locks, and must separate QPaste-originated clipboard writes from newly copied user content.
- `src/core/listener.py`
- `src/core/clipboard_queue.py`

This is the principal concurrency/native-API boundary: hook callbacks and clipboard notifications feed shared queue/state safely.

#### User Interaction Surfaces
The application is controlled primarily through tray actions and global shortcuts, with two transient PyQt6 interfaces:
- `src/ui/toast.py` presents a focusless status/count overlay.
- `src/ui/inspector.py` provides queue inspection, individual removal, full clearing, settings, and startup controls.
- `src/main.py` owns tray-oriented application execution.

UI actions invoke core state/queue operations; queue and mode changes are reflected back through toast and inspector views rather than requiring a main window.

#### Settings, Expiry, and Windows Startup
Persistent user preferences—including auto-clear duration and startup selection—are managed separately from the transient queue:
- `src/core/config.py`
- `src/core/startup.py`
- `src/core/clipboard_queue.py`

Auto-clear purges queued items after the configured interval (30 seconds to one hour). Windows boot launch is implemented through Registry integration, making `startup.py` a platform-specific infrastructure boundary.

#### Runtime and Distribution
The supported runtime is Python 3.11+ on Windows 10/11, using PyQt6 for the GUI and Win32 facilities for mutexes, keyboard/clipboard integration, and Registry startup. Dependencies are declared in `src/requirements.txt`. Distribution has two routes:
- PyInstaller portable executable: `qpaste.spec`
- Inno Setup installer: `installer/qpaste_setup.iss`

Main entry points: [`src/main.py`](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/main.py) (Application Entry), [`src/core/state.py`](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/state.py) (Application State), [`src/core/clipboard_queue.py`](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/clipboard_queue.py) (Clipboard Queue), [`src/core/listener.py`](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/listener.py) (Native Listener)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Windows Runtime"]
  node_main["Application Entry<br/>PyQt6 bootstrap<br/>[main.py]"]
  node_single_instance{{"Single Instance<br/>Win32 mutex<br/>[single_instance.py]"}}
  node_listener{{"Native Listener<br/>keyboard and clipboard bridge<br/>[listener.py]"}}
  node_startup{{"Windows Startup<br/>Registry integration<br/>[startup.py]"}}
  node_windows_clipboard[("Windows Clipboard<br/>native API")]
  node_windows_hooks{{"Windows Keyboard Hooks<br/>native API"}}
end

subgraph group_core["Core Domain"]
  node_state["Application State<br/>mode coordinator<br/>[state.py]"]
  node_queue["Clipboard Queue<br/>bounded FIFO model<br/>[clipboard_queue.py]"]
  node_config["Preferences<br/>persistent settings<br/>[config.py]"]
end

subgraph group_ui["User Surfaces"]
  node_tray["Tray Controls<br/>PyQt6 tray UI<br/>[main.py]"]
  node_toast["Status Toast<br/>focusless overlay<br/>[toast.py]"]
  node_inspector["Queue Inspector<br/>PyQt6 dialog<br/>[inspector.py]"]
end

subgraph group_distribution["Distribution"]
  node_requirements["Runtime Dependencies<br/>Python requirements<br/>[requirements.txt]"]
  node_pyinstaller["Portable Executable<br/>PyInstaller build<br/>[qpaste.spec]"]
  node_installer["Windows Installer<br/>Inno Setup package<br/>[qpaste_setup.iss]"]
end

node_main -->|"acquires before startup"| node_single_instance
node_main -->|"initializes"| node_state
node_main -->|"starts"| node_listener
node_main -->|"runs"| node_tray
node_main -->|"owns"| node_toast
node_main -->|"opens"| node_inspector
node_listener -->|"observes Ctrl+C / Ctrl+V"| node_windows_hooks
node_listener -->|"reads and writes"| node_windows_clipboard
node_listener -->|"checks Queue Mode"| node_state
node_listener -->|"appends copies / consumes paste head"| node_queue
node_state -->|"toggles and clears"| node_queue
node_config -->|"configures auto-clear"| node_queue
node_config -->|"controls enabled state"| node_startup
node_startup -.->|"launches at Windows boot"| node_main
node_tray -->|"invokes actions"| node_state
node_inspector -->|"invokes mode and clear actions"| node_state
node_inspector -->|"inspects and removes items"| node_queue
node_inspector -->|"edits preferences"| node_config
node_state -->|"publishes mode changes"| node_toast
node_queue -->|"publishes count changes"| node_toast
node_queue -->|"publishes queue changes"| node_inspector
node_requirements -.->|"provides runtime dependencies"| node_main
node_pyinstaller -->|"packages"| node_main
node_installer -->|"installs executable"| node_pyinstaller

click node_main "https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/main.py"
click node_single_instance "https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/single_instance.py"
click node_listener "https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/listener.py"
click node_state "https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/state.py"
click node_queue "https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/clipboard_queue.py"
click node_config "https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/config.py"
click node_startup "https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/startup.py"
click node_tray "https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/main.py"
click node_toast "https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/ui/toast.py"
click node_inspector "https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/ui/inspector.py"
click node_requirements "https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/requirements.txt"
click node_pyinstaller "https://github.com/chinthanasathyajithcs/qpaste/blob/main/qpaste.spec"
click node_installer "https://github.com/chinthanasathyajithcs/qpaste/blob/main/installer/qpaste_setup.iss"

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_main,node_single_instance,node_listener,node_startup,node_windows_clipboard,node_windows_hooks toneBlue
class node_state,node_queue,node_config toneAmber
class node_tray,node_toast,node_inspector toneMint
class node_requirements,node_pyinstaller,node_installer toneRose
```

## Components

### Windows Runtime

- [Application Entry](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/main.py): PyQt6 bootstrap · Assembles services, tray execution, and lifecycle. · `src/main.py`
- [Single Instance](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/single_instance.py): Win32 mutex · Rejects competing QPaste processes. · `src/core/single_instance.py`
- [Native Listener](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/listener.py): keyboard and clipboard bridge · Handles hooks, clipboard contention, and QPaste-originated writes. · `src/core/listener.py`
- [Windows Startup](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/startup.py): Registry integration · Registers optional boot launch. · `src/core/startup.py`
- **Windows Clipboard**: native API
- **Windows Keyboard Hooks**: native API

### Core Domain

- [Application State](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/state.py): mode coordinator · Coordinates Queue Mode and user actions. · `src/core/state.py`
- [Clipboard Queue](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/clipboard_queue.py): bounded FIFO model · Thread-safe ephemeral queue capped at 25 items. · `src/core/clipboard_queue.py`
- [Preferences](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/core/config.py): persistent settings · Stores auto-clear duration and startup selection. · `src/core/config.py`

### User Surfaces

- [Tray Controls](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/main.py): PyQt6 tray UI · Primary controls and global shortcut access. · `src/main.py`
- [Status Toast](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/ui/toast.py): focusless overlay · Shows mode and queue count. · `src/ui/toast.py`
- [Queue Inspector](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/ui/inspector.py): PyQt6 dialog · Inspects and manages queue, settings, and startup. · `src/ui/inspector.py`

### Distribution

- [Runtime Dependencies](https://github.com/chinthanasathyajithcs/qpaste/blob/main/src/requirements.txt): Python requirements · `src/requirements.txt`
- [Portable Executable](https://github.com/chinthanasathyajithcs/qpaste/blob/main/qpaste.spec): PyInstaller build · `qpaste.spec`
- [Windows Installer](https://github.com/chinthanasathyajithcs/qpaste/blob/main/installer/qpaste_setup.iss): Inno Setup package · `installer/qpaste_setup.iss`

## Connections

- Application Entry → Single Instance: acquires before startup
- Application Entry → Application State: initializes
- Application Entry → Native Listener: starts
- Application Entry → Tray Controls: runs
- Application Entry → Status Toast: owns
- Application Entry → Queue Inspector: opens
- Native Listener → Windows Keyboard Hooks: observes Ctrl+C / Ctrl+V
- Native Listener → Windows Clipboard: reads and writes
- Native Listener → Application State: checks Queue Mode
- Native Listener → Clipboard Queue: appends copies / consumes paste head
- Application State → Clipboard Queue: toggles and clears
- Preferences → Clipboard Queue: configures auto-clear
- Preferences → Windows Startup: controls enabled state
- Windows Startup → Application Entry: launches at Windows boot
- Tray Controls → Application State: invokes actions
- Queue Inspector → Application State: invokes mode and clear actions
- Queue Inspector → Clipboard Queue: inspects and removes items
- Queue Inspector → Preferences: edits preferences
- Application State → Status Toast: publishes mode changes
- Clipboard Queue → Status Toast: publishes count changes
- Clipboard Queue → Queue Inspector: publishes queue changes
- Runtime Dependencies → Application Entry: provides runtime dependencies
- Portable Executable → Application Entry: packages
- Windows Installer → Portable Executable: installs executable
