How wireapp/wire-apps-jvm-sdk works
Project Type & Purpose
• This is a Kotlin/JVM SDK (wire-apps-jvm-sdk) that third-party applications use to connect to the Wire backend as if they were regular Wire clients.
A. Bot Application
• Your custom bot code (e.g., implementing WireEventsHandler)
• Calls into the SDK to initialize, send messages, and receive callbacks.
B. Wire JVM SDK
1. Configuration Module
• Reads environment variables or properties (e.g., APP_TOKEN, user credentials, environment).
2. Networking Module (BackendClient)
• BackendClientImpl or BackendClientDemo
• Sends authenticated HTTP/gRPC calls to the Wire Application API.
3. Crypto Module (CryptoClient, CoreCryptoClient)
• Encrypts outbound messages and decrypts inbound messages.
• Manages key storage on the filesystem.
4. Persistence Module (SQLDelight + SQLite)
• Stores application state: conversations, teams, messages, keys.
5. Service & Router Module (WireApplicationManager, EventsRouter)
• Maintains long-polling or streaming connections.
• Routes incoming events to your WireEventsHandler.
C. Wire Backend Services (external)
• Wire Application API endpoints (authentication, messaging, event stream).
D. Local Storage
• Filesystem directory (e.g., storage/apps.db, key files).
Relationships & Data Flows
• Initialization Flow
1. Bot App → SDK Configuration: supply credentials/API token.
2. SDK Networking → Wire Backend: authenticate and open event stream.
3. SDK Crypto & Persistence: store keys and initial state.
• Event Handling Flow
1. Wire Backend → SDK Service: pushes encrypted events (messages, invites).
2. SDK Crypto: decrypts events.
3. SDK Persistence: persists event data.
4. SDK EventsRouter → Bot App: invokes your event handler callbacks.
• Outbound Message Flow
1. Bot App → SDK Service API: call sendMessage().
2. SDK Crypto: encrypt message payload.
3. SDK Networking → Wire Backend: HTTP/gRPC call to post message.
4. SDK Persistence: save sent message in local store.
Architectural Patterns & Principles
• Modular separation: configuration, networking, crypto, persistence, routing.
• Dependency injection via Koin (isolated context).
• Layered event-driven approach: network layer emits events → router layer dispatches → application code handles.
• Pluggable BackendClient (demo vs. production).
• Local first: use SQLite for offline resilience.