# snownico0722/papertodo architecture

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

- Interactive diagram: https://gitdiagram.com/snownico0722/papertodo
- Repository: https://github.com/snownico0722/papertodo

## Overview

#### Purpose and Runtime

PaperTodo is a Windows x64 desktop sticky-note application: independent borderless WPF windows represent todo lists or Markdown-like notes, with no primary application window. It targets .NET 10/WPF and runs persistently through the system tray. Application startup is defined by `App.xaml` and `App.xaml.cs`; project packaging/runtime dependencies are defined in `PaperTodo.csproj`.

#### Application Control Plane

`AppController.cs` is the application-level coordinator for note lifecycle, tray-driven actions, persistence, and global behavior. Its partials separate high-level concerns: settings in `AppController.Settings.cs`, tray/menu integration in `AppController.Tray.cs`, and keyboard command handling in `AppController.Shortcuts.cs`. `StartupCommand.cs` parses command-line intents such as show/hide/toggle/create/exit, while `SingleInstanceHelper.cs` forwards subsequent launches to the already-running process.

#### Persistent State and Asset Storage

The primary model/state boundary is `Models.cs` plus `StateStore.cs`: note content, window geometry, settings, and UI state are saved to `data.json`, with backup/recovery behavior. Note images are deliberately outside JSON: `NoteImageStore.cs` resolves image references used in Markdown content and persists binaries through `LmdbImageDatabase.cs`. The latter wraps the packaged native LMDB library via `LmdbNative.cs`; native source/build/distribution assets live under `native/lmdb/`.

#### Note and Todo Window Surface

`PaperWindow.cs` is the core independent-paper window, divided into lifecycle/native-window concerns and type-specific presentation. `PaperWindow.Note.cs` hosts text/Markdown editing behavior, while `PaperWindow.Todo.cs` implements item-oriented todo interactions. `PaperWindow.Lifecycle.cs` governs showing, hiding, restoring, and disposal; `PaperWindow.Native.cs` handles Windows-level window behavior. `TodoTextBox.cs` and `MarkdownTextBox.cs` are the specialized editing controls behind each paper mode.

#### Markdown and Embedded Images

Markdown is intentionally a lightweight editor/rendering layer rather than a full document system. `MarkdownTextBox.cs` provides editor-facing formatting/highlighting behavior; `MarkdownFencedCodeScanner.cs` identifies fenced code regions, and `MarkdownImageReferences.cs` parses internal image references. This layer connects note text to `NoteImageStore.cs`, keeping images transactionally stored in LMDB while preserving references in note content.

#### Capsule Mode and Edge Docking

Collapsed papers become capsules governed by a distinct state/presentation pipeline. `EdgeCapsuleModel.cs` represents capsule state, `EdgeCapsuleReducer.cs` applies state transitions, and `EdgeCapsuleTransitionPolicy.cs` determines permitted behavior. `EdgeCapsuleQueueCoordinator.cs` manages per-screen edge queues; `EdgeCapsuleTargetPlanner.cs` and `EdgeCapsuleLayoutService.cs` compute docking targets and layout. Rendering and animation are separated through `EdgeCapsuleHost.cs`, `EdgeCapsulePresenter.cs`, and `EdgeCapsuleFrameScheduler.cs`.

#### Windows and System Integration

`AppController.Tray.cs` provides the sole global user entry point through the notification-area icon. `GlobalHotkeys.cs` supports application shortcuts, and `FullscreenForegroundWindowDetector.cs` enables the fullscreen visibility/always-on-top policy. Window placement and monitor-aware geometry use `ScreenGeometry.cs`, `WindowWorkAreaHelper.cs`, and `WindowNative.cs`. Theme, system appearance, and localized strings are represented by `Theme.cs`, `SystemSettingsHelper.cs`, and `Resources/Strings*.resx`.

#### External Execution and Distribution

Notes can be handed to Windows-associated external editors and can act as PowerShell-backed script capsules; this behavior is integrated through the application/window command path rather than a server or web boundary. Release automation is in `.github/workflows/release.yml`, producing signed Windows single-file executables. Native image persistence is built with CMake from `native/lmdb/CMakeLists.txt`; key managed dependencies are WPF, AvalonEdit, and Hardcodet.NotifyIcon.Wpf.

Main entry points: [`PaperWindow.cs`](https://github.com/snownico0722/papertodo/blob/main/PaperWindow.cs) (Paper window), [`AppController.cs`](https://github.com/snownico0722/papertodo/blob/main/AppController.cs) (App controller), [`App.xaml`](https://github.com/snownico0722/papertodo/blob/main/App.xaml) (WPF startup), [`EdgeCapsuleTargetPlanner.cs`](https://github.com/snownico0722/papertodo/blob/main/EdgeCapsuleTargetPlanner.cs) (Capsule target & layout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Application Runtime"]
  node_app{{"WPF startup<br/>[App.xaml]"}}
  node_project["Project package<br/>[PaperTodo.csproj]"]
  node_controller["App controller<br/>lifecycle coordinator<br/>[AppController.cs]"]
  node_commands["Launch commands<br/>command routing<br/>[StartupCommand.cs]"]
  node_tray["Tray &amp; shortcuts<br/>global input"]
end

subgraph group_state["State &amp; Images"]
  node_state_store[("State store<br/>JSON persistence<br/>[StateStore.cs]")]
  node_models["Application models<br/>state models<br/>[Models.cs]"]
  node_image_store["Note image store<br/>image persistence<br/>[NoteImageStore.cs]"]
  node_lmdb[("LMDB image database<br/>native storage wrapper")]
end

subgraph group_windows["Paper Windows"]
  node_paper_window["Paper window<br/>WPF window<br/>[PaperWindow.cs]"]
  node_note_editor["Markdown note editor<br/>editor control<br/>[MarkdownTextBox.cs]"]
  node_todo_editor["Todo editor<br/>editor control<br/>[TodoTextBox.cs]"]
  node_markdown_refs["Markdown image references<br/>Markdown parser"]
end

subgraph group_capsules["Capsule Docking"]
  node_capsule_state["Capsule state machine<br/>state transitions"]
  node_capsule_layout["Capsule target &amp; layout<br/>docking layout"]
  node_capsule_render["Capsule rendering<br/>presentation host<br/>[EdgeCapsuleHost.cs]"]
end

subgraph group_platform["Windows &amp; Distribution"]
  node_windows_integration["Windows integration<br/>native window services<br/>[WindowNative.cs]"]
  node_native_lmdb["Native LMDB build<br/>native dependency<br/>[CMakeLists.txt]"]
  node_release["Release pipeline<br/>GitHub Actions workflow<br/>[release.yml]"]
end

node_project -->|"packages"| node_app
node_app -->|"starts"| node_controller
node_app -->|"receives launch intent"| node_commands
node_commands -->|"routes intent"| node_controller
node_tray -->|"user actions"| node_controller
node_controller -->|"loads and saves"| node_state_store
node_state_store -->|"serializes"| node_models
node_controller -->|"creates and manages"| node_paper_window
node_paper_window -->|"hosts note mode"| node_note_editor
node_paper_window -->|"hosts todo mode"| node_todo_editor
node_note_editor -->|"parses images"| node_markdown_refs
node_markdown_refs -->|"resolves references"| node_image_store
node_image_store -->|"stores binaries"| node_lmdb
node_lmdb -->|"calls native library"| node_native_lmdb
node_paper_window -->|"collapses and restores"| node_capsule_state
node_capsule_state -->|"requests placement"| node_capsule_layout
node_capsule_layout -->|"positions capsules"| node_capsule_render
node_paper_window -->|"uses native behavior"| node_windows_integration
node_windows_integration -->|"provides screen geometry"| node_capsule_layout
node_release -->|"builds and signs"| node_project
node_release -->|"packages"| node_native_lmdb

click node_app "https://github.com/snownico0722/papertodo/blob/main/App.xaml"
click node_project "https://github.com/snownico0722/papertodo/blob/main/PaperTodo.csproj"
click node_controller "https://github.com/snownico0722/papertodo/blob/main/AppController.cs"
click node_commands "https://github.com/snownico0722/papertodo/blob/main/StartupCommand.cs"
click node_tray "https://github.com/snownico0722/papertodo/blob/main/AppController.Tray.cs"
click node_state_store "https://github.com/snownico0722/papertodo/blob/main/StateStore.cs"
click node_models "https://github.com/snownico0722/papertodo/blob/main/Models.cs"
click node_image_store "https://github.com/snownico0722/papertodo/blob/main/NoteImageStore.cs"
click node_lmdb "https://github.com/snownico0722/papertodo/blob/main/LmdbImageDatabase.cs"
click node_paper_window "https://github.com/snownico0722/papertodo/blob/main/PaperWindow.cs"
click node_note_editor "https://github.com/snownico0722/papertodo/blob/main/MarkdownTextBox.cs"
click node_todo_editor "https://github.com/snownico0722/papertodo/blob/main/TodoTextBox.cs"
click node_markdown_refs "https://github.com/snownico0722/papertodo/blob/main/MarkdownImageReferences.cs"
click node_capsule_state "https://github.com/snownico0722/papertodo/blob/main/EdgeCapsuleReducer.cs"
click node_capsule_layout "https://github.com/snownico0722/papertodo/blob/main/EdgeCapsuleTargetPlanner.cs"
click node_capsule_render "https://github.com/snownico0722/papertodo/blob/main/EdgeCapsuleHost.cs"
click node_windows_integration "https://github.com/snownico0722/papertodo/blob/main/WindowNative.cs"
click node_native_lmdb "https://github.com/snownico0722/papertodo/blob/main/native/lmdb/CMakeLists.txt"
click node_release "https://github.com/snownico0722/papertodo/blob/main/.github/workflows/release.yml"

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,node_project,node_controller,node_commands,node_tray toneBlue
class node_state_store,node_models,node_image_store,node_lmdb toneAmber
class node_paper_window,node_note_editor,node_todo_editor,node_markdown_refs toneMint
class node_capsule_state,node_capsule_layout,node_capsule_render toneRose
class node_windows_integration,node_native_lmdb,node_release toneIndigo
```

## Components

### Application Runtime

- [WPF startup](https://github.com/snownico0722/papertodo/blob/main/App.xaml): application · Starts the tray-resident, windowless application. · `App.xaml`
- [Project package](https://github.com/snownico0722/papertodo/blob/main/PaperTodo.csproj): project · Defines .NET/WPF packaging and managed dependencies. · `PaperTodo.csproj`
- [App controller](https://github.com/snownico0722/papertodo/blob/main/AppController.cs): lifecycle coordinator · Coordinates notes, persistence, tray actions, and global behavior. · `AppController.cs`
- [Launch commands](https://github.com/snownico0722/papertodo/blob/main/StartupCommand.cs): command routing · Parses launch intents and forwards later launches to the active process. · `StartupCommand.cs`
- [Tray & shortcuts](https://github.com/snownico0722/papertodo/blob/main/AppController.Tray.cs): global input · Provides the primary user entry point and application hotkeys. · `AppController.Tray.cs`

### State & Images

- [State store](https://github.com/snownico0722/papertodo/blob/main/StateStore.cs): JSON persistence · Persists notes, geometry, settings, and UI state with recovery. · `StateStore.cs`
- [Application models](https://github.com/snownico0722/papertodo/blob/main/Models.cs): state models · `Models.cs`
- [Note image store](https://github.com/snownico0722/papertodo/blob/main/NoteImageStore.cs): image persistence · Resolves Markdown image references separately from note JSON. · `NoteImageStore.cs`
- [LMDB image database](https://github.com/snownico0722/papertodo/blob/main/LmdbImageDatabase.cs): native storage wrapper · Stores image binaries through the packaged LMDB library. · `LmdbImageDatabase.cs`

### Paper Windows

- [Paper window](https://github.com/snownico0722/papertodo/blob/main/PaperWindow.cs): WPF window · Independent borderless paper surface and lifecycle host. · `PaperWindow.cs`
- [Markdown note editor](https://github.com/snownico0722/papertodo/blob/main/MarkdownTextBox.cs): editor control · Edits and highlights lightweight Markdown notes. · `MarkdownTextBox.cs`
- [Todo editor](https://github.com/snownico0722/papertodo/blob/main/TodoTextBox.cs): editor control · Supports item-oriented todo interactions. · `TodoTextBox.cs`
- [Markdown image references](https://github.com/snownico0722/papertodo/blob/main/MarkdownImageReferences.cs): Markdown parser · Parses embedded internal image references. · `MarkdownImageReferences.cs`

### Capsule Docking

- [Capsule state machine](https://github.com/snownico0722/papertodo/blob/main/EdgeCapsuleReducer.cs): state transitions · Models collapsed papers and applies allowed capsule transitions. · `EdgeCapsuleReducer.cs`
- [Capsule target & layout](https://github.com/snownico0722/papertodo/blob/main/EdgeCapsuleTargetPlanner.cs): docking layout · Plans per-screen edge targets and capsule placement. · `EdgeCapsuleTargetPlanner.cs`
- [Capsule rendering](https://github.com/snownico0722/papertodo/blob/main/EdgeCapsuleHost.cs): presentation host · Hosts, presents, and schedules capsule animation frames. · `EdgeCapsuleHost.cs`

### Windows & Distribution

- [Windows integration](https://github.com/snownico0722/papertodo/blob/main/WindowNative.cs): native window services · Handles placement, monitor geometry, native behavior, and fullscreen policy. · `WindowNative.cs`
- [Native LMDB build](https://github.com/snownico0722/papertodo/blob/main/native/lmdb/CMakeLists.txt): native dependency · CMake-built packaged native image-storage library. · `native/lmdb/CMakeLists.txt`
- [Release pipeline](https://github.com/snownico0722/papertodo/blob/main/.github/workflows/release.yml): GitHub Actions workflow · Builds signed Windows single-file executables. · `.github/workflows/release.yml`

## Connections

- Project package → WPF startup: packages
- WPF startup → App controller: starts
- WPF startup → Launch commands: receives launch intent
- Launch commands → App controller: routes intent
- Tray & shortcuts → App controller: user actions
- App controller → State store: loads and saves
- State store → Application models: serializes
- App controller → Paper window: creates and manages
- Paper window → Markdown note editor: hosts note mode
- Paper window → Todo editor: hosts todo mode
- Markdown note editor → Markdown image references: parses images
- Markdown image references → Note image store: resolves references
- Note image store → LMDB image database: stores binaries
- LMDB image database → Native LMDB build: calls native library
- Paper window → Capsule state machine: collapses and restores
- Capsule state machine → Capsule target & layout: requests placement
- Capsule target & layout → Capsule rendering: positions capsules
- Paper window → Windows integration: uses native behavior
- Windows integration → Capsule target & layout: provides screen geometry
- Release pipeline → Project package: builds and signs
- Release pipeline → Native LMDB build: packages
