Architecture Overview
mahpastes is built using Wails, a framework for building desktop applications with Go backends and web frontends.
High-Level Architecture
┌─────────────────────────────────────────────────────────────┐
│ Desktop App (Wails) │
├───────────────────────── ────────────────────────────────────┤
│ ┌─────────────────────┐ ┌─────────────────────────────┐ │
│ │ Frontend │ │ Backend │ │
│ │ (HTML/CSS/JS) │◄──►│ (Go) │ │
│ │ │ │ │ │
│ │ • Vanilla JS │ │ • Wails v2 │ │
│ │ • Tailwind CSS │ │ • SQLite │ │
│ │ • No framework │ │ • Clipboard integration │ │
│ └─────────────────────┘ │ • File system watcher │ │
│ │ • REST API server │ │
│ │ • Tag HTTP servers │ │
│ └─────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│ │
▼ ▼
┌────────────────┐ ┌──────────────────┐
│ SQLite DB │ │ HTTP listeners │
│ clips.db │ │ (REST API, Tag │
└────────────────┘ │ serve servers) │
└──────────────────┘
Technology Stack
Backend (Go)
| Component | Technology | Purpose |
|---|---|---|
| Framework | Wails v2 | Desktop app framework |
| Database | SQLite 3 | Local data storage |
| Clipboard | golang.design/x/clipboard | Cross-platform clipboard |
| File Watch | fsnotify | Filesystem events |
| Plugins | gopher-lua | Lua scripting sandbox |
| CLI | cobra | mp CLI command framework |
| EXIF | goexif | Image metadata extraction |
| COM (Windows) | go-ole | OLE drag-and-drop interop |
Frontend (Web)
| Component | Technology | Purpose |
|---|---|---|
| Markup | HTML5 | Structure |
| Styling | Tailwind CSS | Utility-first CSS |
| Logic | Vanilla JavaScript | No framework overhead |
| Font | IBM Plex Mono | Consistent typography |
Component Overview
Backend Components
main.go Entry point, Wails setup
app.go Core application logic, API methods
database.go SQLite setup, schema, migrations
watcher.go Folder watching, file import
backup.go ZIP backup and restore
clipboard_service.go Clipboard copy service (Wails-bound)
clipboard_darwin.go macOS clipboard via NSPasteboard (CGo)
clipboard_windows.go Windows clipboard via PowerShell
clipboard_other.go Unsupported platform stub
transfer_service.go Drag-out preparation and native drag
transfer_handler.go HTTP handler for transfer file serving (DownloadURL)
transfer_types.go Transfer system type definitions
app_transfer_helpers.go Bridge between App and TempClipStore
temp_clip_store.go Leased temp file management
native_drag_darwin.go macOS native drag via CGo
native_drag_windows.go Windows native drag via COM OLE DoDragDrop
native_drag_other.go Unsupported platform stub
open_darwin.go Open file with default app (macOS)
open_windows.go Open file with default app (Windows)
open_other.go Unsupported platform stub
plugin_service.go Plugin frontend API (Wails-bound)
plugins.go Plugin install/uninstall helpers
serve_manager.go Tag serve HTTP server lifecycle and routing
serve_json_api.go JSON API handler for served tags (/_api prefix)
serve_file_upload.go File upload handler for served tags (/_api/_upload)
serve_service.go Tag serve Wails service (start/stop/status)
api_manager.go REST API HTTP server, route registration, key management
api_service.go REST API Wails service (start/stop/keys)
markdown_service.go Desktop Markdown reference/image/cache Wails service
internal/app/markdown_* Markdown classification, references, image validation, secure fetching, cache
tag_hierarchy.go Tag tree helpers (parent, root, ancestor, descendant checks)
plugin/ Lua plugin system
├── manager.go Plugin lifecycle, event dispatch
├── manifest.go Manifest parsing, validation
├── sandbox.go Sandboxed Lua execution
├── scheduler.go Scheduled/recurring plugin tasks
├── fetch.go Plugin fetching and downloading
├── semver.go Semantic versioning helpers
├── update_checker.go Plugin update checking
├── permission_diff.go Permission diff logic for plugin updates
├── fonts/ Bundled fonts for image overlay
└── api_*.go Lua APIs (clips, tags, storage, http, fs, utils, task, toast, image, modal, metadata)
Frontend Components
frontend/
├── index.html Main UI structure
├── js/
│ ├── app.js Core application logic
│ ├── ui.js Card rendering, gallery management
│ ├── editor/ Modular image editor
│ │ ├── editor-core.js Core editor canvas logic
│ │ ├── tool-anonymize.js Anonymize/blur tool
│ │ ├── tool-arrow.js Arrow drawing tool
│ │ ├── tool-brush.js Brush/freehand tool
│ │ ├── tool-crop.js Crop tool
│ │ ├── tool-eyedropper.js Color picker tool
│ │ ├── tool-select.js Selection tool
│ │ ├── tool-shapes.js Shape drawing tool
│ │ ├── tool-text.js Text overlay tool
│ │ ├── tool-transform.js Transform/resize tool
│ │ └── tool-zoom.js Zoom/pan tool
│ ├── modals.js All modal/lightbox/editor logic
│ ├── tags.js Tag management UI
│ ├── settings.js Settings modal
│ ├── plugins.js Plugin management UI
│ ├── plugin-icons.js Plugin icon rendering
│ ├── task-queue.js Plugin task progress UI
│ ├── watch.js Watch folders UI
│ ├── transfer.js Drag-out transfer state management
│ ├── transfer-strategies.js Platform-specific drag data adapters
│ ├── markdown-renderer.js Shared sanitized GFM renderer
│ ├── editor/markdown-preview.js Markdown clip link/image policy and preview lifecycle
│ ├── modal-renderer.js Plugin result modal rendering
│ ├── metadata.js Clip metadata UI
│ ├── sort.js Gallery sorting controls
│ ├── tooltips.js Tooltip management
│ ├── shortcuts.js Keyboard shortcut registration and context handling