# etcetra7n/cleopatra architecture

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

- Interactive diagram: https://gitdiagram.com/etcetra7n/cleopatra
- Repository: https://github.com/etcetra7n/cleopatra

## Overview

At the same time, there’s a “worker” component (with Node.js scripts in worker/prod and worker/dev) hosted externally (mentioned to be hosted on Cloudflare in the README) that supplies jobs and collects results. In addition, the presence of the .HASHER directory and files such as bcrypt.cpp, blowfish.cpp, and related headers/assets suggests that security (likely for password hashing or integrity checks) is embedded into part of the project, further supported by the inclusion of rapidjson (for JSON handling) and libcurl (for HTTP communication) among other dependencies.

##### Main Components
- Client-Side Daemon: Represent the Cleopatra Daemon running on the user’s PC. Indicate its submodules:
- Command Executor: (runner.cpp) which processes and executes jobs.
- Communication Module: (using libcurl and rapidjson) that interacts with the remote APIs.
- Logger/Utility Modules: (logger.cpp, send_results.cpp) handling execution output and logging.
- Security/Hasher Component: Modules inside the .HASHER directory handling bcrypt, blowfish, etc.
- Worker Server: Represent the remote Cleopatra Worker, likely run with Node.js (as seen in worker/prod and worker/dev), which hosts two RESTful API endpoints:
- /api/fetch-daemon-job to supply jobs.
- /api/send-results-to-worker to collect the execution results.

- External Libraries/Frameworks: Show the use of rapidjson for JSON parsing, libcurl for HTTP requests, and other security libraries (bcrypt) integrated into the daemon.

##### Relationships and Data Flow
- The Worker Server sends a job request (through the fetch API) to the client daemon.
- The Daemon processes and executes the received command locally.
- The results (output and exit code) are then returned from the Daemon to the Worker Server via the send-results API.

##### Architectural Patterns and Design Principles
- Client–Server Pattern: Clearly separate the client (daemon) and server (worker) components.
- Modular Design: Emphasize the separation of concerns in daemon modules (communication, logging, job execution, security).
- Secure Communication: Note the integration of security libraries (bcrypt, blowfish) and protocols (protocols folder for password change checklist) in ensuring data integrity and secure authentication.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Cleopatra Daemon Subgraph
    subgraph "Cleopatra Daemon"
        DA1("Daemon Main (main.cpp)"):::daemon
        DA2("Command Executor (runner.cpp)"):::daemon
        DA3("HTTP Communication Module"):::daemon
        subgraph "Utility Modules"
            DA4("Logger (logger.cpp)"):::daemon
            DA5("Send Results (send_results.cpp)"):::daemon
        end
        DA6("Security/Hasher Component (.HASHER)"):::daemon
    end

    %% Remote Worker Server Subgraph
    subgraph "Remote Worker Server"
        WS1("Production Worker (prod)"):::worker
        WS2("Development Worker (dev)"):::worker
        subgraph "API Endpoints"
            WS3("Fetch Daemon Job (/api/fetch-daemon-job)"):::api
            WS4("Send Results (/api/send-results-to-worker)"):::api
        end
    end

    %% External Dependencies
    E1("rapidjson"):::extern
    E2("libcurl"):::extern
    P1("PASSWORD_CHANGE.checklist"):::extern

    %% Build and Deployment Tools Subgraph
    subgraph "Build & Deployment Tools"
        B1("CMakeLists.txt"):::build
        B2("make_build_RELEASE.bat"):::build
        B3("ninja_build_RELEASE.bat"):::build
        B4("release/"):::build
        B5("dist/"):::build
        B6("setup/"):::build
    end

    %% Relationships within Cleopatra Daemon
    DA3 -->|"fetch-command"| DA2
    DA2 -->|"pass-output"| DA5

    %% Communication between Daemon and Worker Server APIs
    DA3 -->|"fetch-job(2min)"| WS3
    DA5 -->|"send-results"| WS4

    %% External Dependencies used by Communication Module
    E1 -->|"json-parsing"| DA3
    E2 -->|"HTTP-requests"| DA3

    %% Security Component check with protocol
    DA6 -->|"security-check"| P1

    %% Build Tools influence on Daemon build
    B1 -->|"build"| DA1

    %% Styling Classes
    classDef daemon fill:#add8e6,stroke:#333,stroke-width:1px;
    classDef worker fill:#90ee90,stroke:#333,stroke-width:1px;
    classDef api fill:#fffacd,stroke:#333,stroke-width:1px;
    classDef extern fill:#ffc0cb,stroke:#333,stroke-width:1px;
    classDef build fill:#d3d3d3,stroke:#333,stroke-width:1px;

    %% Click Events
    click DA1 "https://github.com/etcetra7n/cleopatra/blob/main/daemon/main.cpp"
    click DA2 "https://github.com/etcetra7n/cleopatra/blob/main/daemon/runner.cpp"
    click DA3 "https://github.com/etcetra7n/cleopatra/tree/main/daemon/"
    click DA4 "https://github.com/etcetra7n/cleopatra/blob/main/daemon/logger.cpp"
    click DA5 "https://github.com/etcetra7n/cleopatra/blob/main/daemon/send_results.cpp"
    click DA6 "https://github.com/etcetra7n/cleopatra/tree/main/.HASHER/"
    click WS1 "https://github.com/etcetra7n/cleopatra/blob/main/worker/prod/index.js"
    click WS2 "https://github.com/etcetra7n/cleopatra/blob/main/worker/dev/index.js"
    click WS3 "https://github.com/etcetra7n/cleopatra/tree/main/worker/prod/"
    click WS4 "https://github.com/etcetra7n/cleopatra/tree/main/worker/dev/"
    click P1 "https://github.com/etcetra7n/cleopatra/blob/main/.protocols/PASSWORD_CHANGE.checklist"
    click E1 "https://github.com/etcetra7n/cleopatra/tree/main/include/rapidjson/"
    click E2 "https://github.com/etcetra7n/cleopatra/blob/main/libs/libcurl.a"
    click B1 "https://github.com/etcetra7n/cleopatra/blob/main/CMakeLists.txt"
    click B2 "https://github.com/etcetra7n/cleopatra/blob/main/make_build_RELEASE.bat"
    click B3 "https://github.com/etcetra7n/cleopatra/blob/main/ninja_build_RELEASE.bat"
    click B4 "https://github.com/etcetra7n/cleopatra/tree/main/release/"
    click B5 "https://github.com/etcetra7n/cleopatra/tree/main/dist/"
    click B6 "https://github.com/etcetra7n/cleopatra/tree/main/setup/"
```
