How asamk/signal-cli works
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.