# viplovek/flameshot architecture

> Architecture diagram of the GitHub repository viplovek/flameshot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/viplovek/flameshot
- Repository: https://github.com/viplovek/flameshot

## Overview

##### Project type and purpose
- Flameshot is a cross-platform, Qt-based desktop screenshot tool with both graphical (GUI) and command-line (CLI) interfaces. It provides in-app screenshot editing, global and local hotkeys, D-Bus integration for Linux desktops, and image uploads (e.g., Imgur).

##### File structure
- Top-level “src” directory subdivides into:
- cli → command-line parser and commands
- config → configuration GUI, file parsing and resolution
- core → capture request handling, daemon, D-Bus adapter, global shortcuts
- widgets → Qt widget implementations for capture UI, panels, dialogs
- utils → file I/O, screenshot saving, upload requests, notifications
- CI/CD manifests in “.github/workflows” and build scripts (CMakeLists.txt).

##### Main architectural components
a. User Interface Layer (GUI)
- Interactive capture widget and sidebar panels under src/widgets and src/config
- Configuration window, about/info dialogs
b. Core Engine
- CaptureRequest API in src/core
- flameshotdaemon runs in background, registers D-Bus service
- GlobalShortcutFilter uses QHotkey for hotkey listening
c. CLI Layer
- src/cli parses commands (gui, full, screen, config) and invokes core engine
d. Tools Plugin Layer
- ToolFactory dynamically instantiates tools
e. Utility Services
- src/utils handles config file read/write, filesystem paths, HTTP upload requests, notifications
f. External Services
- Imgur REST API via utils/request and tools/imgupload
- D-Bus for inter-process communication on Linux
- Clipboard, file system, notifications via Qt platform abstractions

##### Relationships and flows
- GUI widgets send user actions to Core Engine (capture, annotate, save, upload).
- Core Engine emits events to Utils (save image, send HTTP requests, push system notifications).
- CLI invokes Core Engine directly or via D-Bus adapter.
- Tools plugin layer subscribes to user events from UI and mutates the capture image.
- Core Engine registers itself as a SingleApplication instance to enforce one instance.
- Packaging/static data and translations are loaded at runtime via Qt resource system (graphics.qrc).

##### Architectural patterns and technologies
- Layered architecture: UI → Core → Utils → External
- Plugin/factory pattern for annotation tools
- Observer pattern: Qt signals/slots for event propagation
- Qt5 framework, C++17, CMake build system
- CI/CD pipelines for cross-platform packaging

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% GUI Layer
    subgraph "GUI Layer"
        Widgets["Widgets"]:::ui
        Config["Config UIs"]:::ui
    end

    %% CLI Layer
    subgraph "CLI Layer"
        CLI["CLI Commands"]:::cli
        CLParser["CommandLineParser"]:::cli
        CLArg["CommandArgument"]:::cli
        CLOption["CommandOption"]:::cli
        CLI --> CLParser
        CLI --> CLArg
        CLI --> CLOption
    end

    %% Core Engine
    subgraph "Core Engine"
        CR["CaptureRequest"]:::core
        Daemon["FlameshotDaemon"]:::core
        DBus["DBus Adapter"]:::core
        Shortcut["GlobalShortcutFilter"]:::core
        MainCore["Flameshot"]:::core
    end

    %% Tools Plugin Framework
    subgraph "Tools Plugin Framework"
        TF["ToolFactory"]:::plugin
        AT["Abstract Tools"]:::plugin
        subgraph "Individual Tools"
            Arrow["ArrowTool"]:::plugin
            ImgurTool["ImgurUploaderTool"]:::plugin
        end
    end

    %% Utility Services
    subgraph "Utility Services"
        Req["HTTP Request"]:::util
        Saver["ScreenshotSaver"]:::util
        Notif["SystemNotification"]:::util
        ConfigH["ConfigHandler"]:::util
        Path["PathInfo"]:::util
    end

    %% External Services
    subgraph "External Services"
        ImgurAPI["Imgur REST API"]:::external
        DBusSys["D-Bus System Bus"]:::external
        FS["File System"]:::external
        Clipboard["Clipboard"]:::external
        Notifications["Platform Notifications"]:::external
    end

    %% External Libraries
    subgraph "External Libraries"
        QHotkey["QHotkey"]:::external
        SingleApp["SingleApplication"]:::external
        ColorWidgets["Qt-Color-Widgets"]:::external
        Qt5["Qt5 Framework"]:::external
    end

    %% Relationships
    Widgets -->|"signal/slot"| MainCore
    Config -->|"signal/slot"| MainCore
    CLI -->|"D-Bus call"| DBus
    CLParser -->|"invoke"| MainCore
    DBus -->|"register service"| DBusSys
    MainCore -->|"capture request"| CR
    MainCore -->|"manage daemon"| Daemon
    MainCore -->|"listen hotkey"| Shortcut
    MainCore -->|"instantiate tools"| TF
    TF -->|"create"| Arrow
    TF -->|"create"| ImgurTool
    MainCore -->|"file I/O"| Saver
    Saver -->|"write"| FS
    MainCore -->|"HTTP POST"| Req
    Req -->|"POST"| ImgurAPI
    MainCore -->|"notification"| Notif
    Notif -->|"push"| Notifications
    MainCore -->|"config read/write"| ConfigH
    ConfigH -->|"path info"| Path
    Shortcut -->|"uses"| QHotkey
    MainCore -->|"single instance"| SingleApp
    Widgets -->|"uses"| ColorWidgets
    Widgets -->|"uses"| Qt5
    MainCore -->|"uses"| Qt5

    %% Click Events
    click Widgets "https://github.com/viplovek/flameshot/tree/master/src/widgets/"
    click Config "https://github.com/viplovek/flameshot/tree/master/src/config/"
    click CLParser "https://github.com/viplovek/flameshot/blob/master/src/cli/commandlineparser.cpp"
    click CLArg "https://github.com/viplovek/flameshot/blob/master/src/cli/commandargument.cpp"
    click CLOption "https://github.com/viplovek/flameshot/blob/master/src/cli/commandoption.cpp"
    click CR "https://github.com/viplovek/flameshot/blob/master/src/core/capturerequest.cpp"
    click Daemon "https://github.com/viplovek/flameshot/blob/master/src/core/flameshotdaemon.cpp"
    click DBus "https://github.com/viplovek/flameshot/blob/master/src/core/flameshotdbusadapter.cpp"
    click Shortcut "https://github.com/viplovek/flameshot/blob/master/src/core/globalshortcutfilter.cpp"
    click MainCore "https://github.com/viplovek/flameshot/blob/master/src/core/flameshot.cpp"
    click TF "https://github.com/viplovek/flameshot/blob/master/src/tools/toolfactory.cpp"
    click AT "https://github.com/viplovek/flameshot/blob/master/src/tools/abstracttool.cpp"
    click Arrow "https://github.com/viplovek/flameshot/blob/master/src/tools/arrow/arrowtool.cpp"
    click ImgurTool "https://github.com/viplovek/flameshot/blob/master/src/tools/imgupload/storages/imgur/imguruploader.cpp"
    click Req "https://github.com/viplovek/flameshot/blob/master/src/utils/request.cpp"
    click Saver "https://github.com/viplovek/flameshot/blob/master/src/utils/screenshotsaver.cpp"
    click Notif "https://github.com/viplovek/flameshot/blob/master/src/utils/systemnotification.cpp"
    click ConfigH "https://github.com/viplovek/flameshot/blob/master/src/utils/confighandler.cpp"
    click Path "https://github.com/viplovek/flameshot/blob/master/src/utils/pathinfo.cpp"
    click QHotkey "https://github.com/viplovek/flameshot/tree/master/external/QHotkey/"
    click SingleApp "https://github.com/viplovek/flameshot/tree/master/external/singleapplication/"
    click ColorWidgets "https://github.com/viplovek/flameshot/tree/master/external/Qt-Color-Widgets/"

    %% Styles
    classDef ui fill:#add8e6,stroke:#333,stroke-width:1px
    classDef core fill:#98fb98,stroke:#333,stroke-width:1px
    classDef util fill:#ffdead,stroke:#333,stroke-width:1px
    classDef plugin fill:#ffe4b5,stroke:#333,stroke-width:1px
    classDef external fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef cli fill:#e0ffff,stroke:#333,stroke-width:1px
```
