# skeletonkey/joplin_alfred_workflow architecture

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

- Interactive diagram: https://gitdiagram.com/skeletonkey/joplin_alfred_workflow
- Repository: https://github.com/skeletonkey/joplin_alfred_workflow

## Overview

##### Main Components
- Alfred User Interface: Represented by the Alfred Workflow which captures commands (e.g., “jn”, “js”, “jt”) from the user.
- Perl Script Executor: This set includes create_note.pl, find_folder.pl, search_notes.pl – each responsible for handling a different functionality.
- Perl Modules: The code under perl_modules (e.g., Joplin.pm, JSON.pm, and modules under Jundy) provides reusable functionality. They encapsulate the underlying logic (JSON parsing, interacting with Curl, formatting commands for Alfred).
- External Joplin API: The workflow communicates with Joplin via its API; the user must enable the Web Clipper in Joplin to allow this.
- External Tools: You have dependencies such as Curl and Perl 5 with the JSON module.

##### Relationships and Interactions
- User Interaction Flow: The user inputs a command in Alfred, which is intercepted by the Alfred Workflow.
- Command Processing: Based on the command (create note, search for notes, search for titles), Alfred triggers the corresponding Perl script.
- Script Execution: The Perl scripts call functions within the custom Perl modules. They use Curl to send HTTP requests to Joplin’s API endpoint, including authentication through the provided token from Joplin’s settings.
- Data Flow: The API response (JSON) is parsed by the Perl modules and formatted by the scripts to display results or confirm creation within Alfred.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The workflow separates user interface handling (Alfred) from business logic (Perl scripts and modules). Each script is specialized for a particular command.
- Modularization: Reusable Perl modules encapsulate common functionality (JSON processing, HTTP requests for Alfred workflow filtering), making the system easier to extend or maintain.
- Dependency Injection: Although not explicitly structured as injection, the reliance on external modules (like Curl’s usage and JSON capability provided in perl_modules) outlines a loosely coupled architecture.

##### Relevant Technologies and Their Roles
- Alfred Workflow: The integration point with the user, handling input and output via Alfred’s interface.
- Perl 5: Script language executing core functionalities.
- Curl: Utility for sending HTTP requests to the Joplin API.
- Joplin API: The endpoint for creating and searching notes, which requires specific configurations (i.e., enabling the Web Clipper and using the provided port and token).
- JSON Module: Used for encoding/decoding data during API transactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface Layer"
        UI["Alfred User Interface (User Commands: jn, js, jt)"]:::frontend
    end

    subgraph "Perl Script Executor Layer"
        CN["Create Note Handler (create_note.pl)"]:::script
        FF["Find Folder Handler (find_folder.pl)"]:::script
        SN["Search Notes/Title Words Handler (search_notes.pl)"]:::script
    end

    subgraph "Perl Modules Layer"
        JP["Joplin API Integration Module (Joplin.pm)"]:::module
        JSONP["JSON Processing Module (JSON.pm)"]:::module
        subgraph "Alfred Workflow Utility Modules"
            FU1["Filtering Utility (Filter.pm)"]:::module
            FU2["HTTP Utility (HTTP.pm)"]:::module
        end
    end

    subgraph "External Dependencies"
        CURL["Curl Tool"]:::external
        JOPLINAPI["Joplin API (Web Clipper Enabled)"]:::external
        PERL["Perl 5 with JSON Support"]:::external
    end

    %% Connections from User Interface to Scripts
    UI -->|"triggers"| CN
    UI -->|"triggers"| FF
    UI -->|"triggers"| SN

    %% Connections from Scripts to Modules
    CN -->|"calls"| JP
    CN -->|"calls"| JSONP
    FF -->|"calls"| JP
    FF -->|"calls"| JSONP
    SN -->|"calls"| JP
    SN -->|"calls"| JSONP

    %% Connections within Modules
    JP -->|"uses"| FU2
    JP -->|"formats"| FU1

    %% Connections to External Dependencies
    JP -->|"sendsHTTPreq"| CURL
    CURL -->|"communicatesWith"| JOPLINAPI
    JOPLINAPI -->|"returnsResponseTo"| JP
    JSONP -->|"parsesJSON"| PERL

    %% Return data flow back to Scripts (implicit)
    JP -- "returnsData" --> CN
    JP -- "returnsData" --> FF
    JP -- "returnsData" --> SN

    %% Click events for component mapping
    click UI "https://github.com/skeletonkey/joplin_alfred_workflow/blob/main/info.plist"
    click CN "https://github.com/skeletonkey/joplin_alfred_workflow/blob/main/create_note.pl"
    click FF "https://github.com/skeletonkey/joplin_alfred_workflow/blob/main/find_folder.pl"
    click SN "https://github.com/skeletonkey/joplin_alfred_workflow/blob/main/search_notes.pl"
    click JSONP "https://github.com/skeletonkey/joplin_alfred_workflow/blob/main/perl_modules/JSON.pm"
    click JP "https://github.com/skeletonkey/joplin_alfred_workflow/blob/main/perl_modules/Joplin.pm"
    click FU1 "https://github.com/skeletonkey/joplin_alfred_workflow/blob/main/perl_modules/Jundy/AlfredWorkflow/Filter.pm"
    click FU2 "https://github.com/skeletonkey/joplin_alfred_workflow/blob/main/perl_modules/Jundy/AlfredWorkflow/HTTP.pm"

    %% Styles
    classDef frontend fill:#f6d186,stroke:#333,stroke-width:1px;
    classDef script fill:#c6e2ff,stroke:#333,stroke-width:1px;
    classDef module fill:#d3f9d8,stroke:#333,stroke-width:1px;
    classDef external fill:#f9d0c4,stroke:#333,stroke-width:1px;
```
