# asamk/signal-cli architecture

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

- Interactive diagram: https://gitdiagram.com/asamk/signal-cli
- Repository: https://github.com/asamk/signal-cli

## Overview

##### Main Components
- Core Application (CLI and Daemon): Represented primarily by the source code under src/main (the Main.java, App.java, and various command implementations in src/main/commands). This layer is the entry point for user commands.
- Business Logic Library: The lib directory contains the core logic for handling Signal-related operations (managers, API models, actions, helpers, storage, etc.). It encapsulates the core service logic such as handling registration, message sending, receiving, group management, etc.
- Communication Interfaces:
– JSON-RPC Interface: Part of the CLI daemon functionality and exposed through commands coupled with the server components. The Rust client under the client directory is an example consumer of this interface.
– D-BUS Interface: Implemented by components found under src/main/dbus.
– HTTP Interface: As seen in src/main/http, which likely handles server-sent events and HTTP communication.
- External and Native Dependencies: Note the reliance on a patched libsignal-service-java (extracted from Signal-Android) and native libraries (bundled under data for different OSes) as well as GraalVM for native binary generation.
- Build & Deployment Infrastructure: Gradle scripts (build.gradle.kts, settings.gradle.kts, gradle wrapper files) and CI configuration (inside .github/workflows) should be acknowledged as part of the system’s engineering ecosystem.

##### Relationships and Interactions
- The CLI (entry point in src/main/java/org/asamk/signal) directs user commands to command handlers (in src/main/commands) which then invoke methods on underlying managers from the business logic found in the lib module.
- The business logic component interacts with storage components (as seen in directories lib/src/main/java/org/asamk/signal/manager/storage/…) to manage keys, accounts, contacts, sessions, and message caching.
- Communication interfaces (JSON-RPC, D-BUS, HTTP) are layered on top of the core business logic—they accept external calls, parse them, and then dispatch the calls to the appropriate manager or helper.
- The Rust client acts as a consumer of the JSON-RPC interface, showing a client-server relationship between the Java daemon/server and this lightweight Rust client.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Distinct packages for CLI commands, business logic (managers, API), storage, networking, and interfaces (dbus, http, jsonrpc) ensure that responsibilities are split.
- Command Pattern: The commands under src/main/commands encapsulate operations (e.g., SendCommand, RegisterCommand) and dispatch these to business logic services.
- Plugin/Extensibility Approach: The buildSrc directory contains custom Gradle plugins (such as ExcludeFileFromJar and CheckLibVersionsPlugin), illustrating an architecture that allows customization during the build.
- Layered Architecture: The separation between UI (CLI), service layer (managers in the lib), and persistence (storage packages) is a natural outcome of the directory organization.

##### Relevant Technologies and Frameworks
- Java (primary implementation) with Gradle as the build tool.
- Rust for the minimal JSON-RPC client.
- GraalVM as an experimental technology for compiling a native binary.
- Native libraries (libsignal) provided for encryption and underlying protocol operations.
- Standard protocols/interfaces (JSON-RPC, D-BUS) and HTTP.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI/Daemon Layer
    subgraph "CLI/Daemon Layer"
        A["Main Entry (Main.java)"]:::cli
        B["Application Entry (App.java)"]:::cli
        C["Command Handlers (commands)"]:::cli
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        D["Business Logic Library"]:::business
    end

    %% Communication Interfaces
    subgraph "Communication Interfaces"
        E["JSON-RPC Adapter"]:::comms
        F["D-Bus Interface"]:::comms
        G["HTTP Interface"]:::comms
        H["Rust JSON-RPC Client"]:::comms
    end

    %% External Dependencies
    subgraph "External Dependencies"
        I["Native Libraries"]:::external
        J["GraalVM Config"]:::external
    end

    %% Build & Deployment Infrastructure
    subgraph "Build & Deployment Infrastructure"
        K["Gradle & CI Scripts"]:::build
    end

    %% Connections: CLI/Daemon to Business Logic
    A -->|"triggers"| D
    B -->|"triggers"| D
    C -->|"dispatches command to"| D

    %% Communication Interfaces to Business Logic
    E -->|"forwards calls"| D
    F -->|"forwards calls"| D
    G -->|"forwards calls"| D

    %% Rust client interacting via JSON-RPC
    H -->|"calls"| E

    %% Business Logic uses External Dependencies
    D -->|"uses"| I
    D -->|"uses"| J

    %% Build Infrastructure providing builds
    K -.->|"builds"| D

    %% Click Events
    click A "https://github.com/asamk/signal-cli/blob/master/src/main/java/org/asamk/signal/Main.java"
    click B "https://github.com/asamk/signal-cli/blob/master/src/main/java/org/asamk/signal/App.java"
    click C "https://github.com/asamk/signal-cli/tree/master/src/main/java/org/asamk/signal/commands"
    click D "https://github.com/asamk/signal-cli/tree/master/lib/src/main/java/org/asamk/signal/manager"
    click E "https://github.com/asamk/signal-cli/tree/master/src/main/java/org/asamk/signal/jsonrpc"
    click F "https://github.com/asamk/signal-cli/tree/master/src/main/java/org/asamk/signal/dbus"
    click G "https://github.com/asamk/signal-cli/tree/master/src/main/java/org/asamk/signal/http"
    click H "https://github.com/asamk/signal-cli/tree/master/client/src"
    click K "https://github.com/asamk/signal-cli/blob/master/build.gradle.kts"
    click I "https://github.com/asamk/signal-cli/tree/master/data"
    click J "https://github.com/asamk/signal-cli/tree/master/graalvm-config-dir"

    %% Styles
    classDef cli fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef business fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef comms fill:#f4a460,stroke:#000,stroke-width:2px;
    classDef external fill:#ffcccb,stroke:#000,stroke-width:2px;
    classDef build fill:#dda0dd,stroke:#000,stroke-width:2px;
```
