Skip to content

Architecture


Interactive Architecture Diagram

πŸ“± Mobile App Android & iOS Kotlin / SwiftUI Ed25519 + E2EE ☁️ Cloudflare Zero Trust Tunnel wss:// TLS βš™οΈ Gateway antimatter-core πŸ” Ed25519 Crypto πŸ›‘ Token Auth πŸ“‘ IPC Router :8765 🎯 AG Adapter Antigravity IDE TypeScript Β· .vsix 🐍 AG2 Adapter Antigravity 2.0 Python daemon πŸ€– CC Adapter Claude Code Node.js Β· SDK E2EE IPC ws://127.0.0.1:8765

Hover over any node to learn what it does.


The Independent Adapter Model

Instead of baking security, networking, and tunneling logic into every agent integration, Antimatter cleanly separates the system into two independent layers:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Independent Adapters β”‚
β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ AG Adapter β”‚ β”‚ AG2 Adapter β”‚ β”‚ CC Adapter β”‚ β”‚
β”‚ β”‚ (TypeScript) β”‚ β”‚ (Python) β”‚ β”‚ (Node.js) β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β”‚ β”‚ β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ IPC ws://127.0.0.1:8765 β”‚
β–Ό β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ antimatter-core Gateway β”‚
β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ Security & Infrastructure Layer β”‚ β”‚
β”‚ β”‚ β”œβ”€ Ed25519 Keypair (OS Keychain) β”‚ β”‚
β”‚ β”‚ β”œβ”€ 256-bit Bearer Token (OS Keychain) β”‚ β”‚
β”‚ β”‚ β”œβ”€ Cloudflare Tunnel Manager β”‚ β”‚
β”‚ β”‚ └─ IPC Router (ws://127.0.0.1:8765) β”‚ β”‚
β”‚ └─────────────────────────────────────────────────────── β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ Cloudflare Tunnel (wss://)
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Mobile App (Client) β”‚
β”‚ β”‚
β”‚ Android (Kotlin/Compose) iOS (SwiftUI/Swift) β”‚
β”‚ β”œβ”€ BridgeWebSocket (OkHttp) β”œβ”€ BridgeWebSocket (URLSessionβ”‚
β”‚ β”œβ”€ Ed25519 verify β”œβ”€ Ed25519 verify (CryptoKit) β”‚
β”‚ β”œβ”€ E2EE decrypt β”œβ”€ E2EE decrypt β”‚
β”‚ └─ Feature Screens └─ Feature Screens β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Layer 1: The Gateway (core/)

The Gateway is the brain of the operation. It runs as a background process and handles everything complex so adapters don’t have to:

Cloudflare Tunnel

The Gateway spawns cloudflared to expose a secure wss:// endpoint β€” no firewall rules, no port forwarding, no static IP required. TryCloudflare generates a free random URL; a custom domain via Cloudflare Zero Trust provides the strongest security.

Ed25519 Cryptography

On first run, the Gateway generates:

  • A persistent Ed25519 keypair β€” private key stored in OS keychain
  • A 256-bit random bearer token β€” stored in OS keychain

During QR pairing, the public key and token are encoded into the QR code. On every WebSocket connection, the mobile client presents the token and then verifies the Gateway’s identity via an AUTH_CHALLENGE / AUTH_RESPONSE handshake. This prevents Man-in-the-Middle attacks even on compromised networks.

IPC Router

The Gateway hosts a local WebSocket server at ws://127.0.0.1:8765. Adapters connect here and register with a name. When the mobile app sends a message targeting "ag", the Gateway forwards it to the correct adapter connection.


Layer 2: Adapters (adapters/)

Adapters are lightweight, stateless IPC clients. Because they don’t handle security or tunneling, they can be:

  • Written in any language
  • Contain AI-specific β€œhacks” (e.g., file watching, SDK integration)
  • Easily swapped or added without touching the Gateway

Registration Protocol

When an adapter boots, it connects to ws://127.0.0.1:8765 and sends:

Adapter registration message
{
"type": "REGISTER_ADAPTER",
"name": "ag"
}

The Gateway registers this connection. Any message from the mobile app targeting "ag" is forwarded to this socket.


Layer 3: Message Routing

The MessageRouter inside the Gateway dispatches each inbound JSON frame:

Message TypeTargetAction
AUTH_CHALLENGEGatewaySign nonce β†’ AUTH_RESPONSE
GET_AVAILABLE_AGENTSGatewayReply with list of connected adapters
GET_FILES, READ_FILETarget AdapterForward to adapter’s IPC socket
SEND_MESSAGETarget AdapterInject prompt into the AI agent
PTY_START, PTY_INPUT, PTY_RESIZEGateway PTYSpawn/control remote terminal
PINGGatewayReply PONG to keep tunnel alive

Layer 4: Mobile Client

Android

Built with Kotlin and Jetpack Compose, following a multi-module MVVM architecture:

LayerTechnologyPurpose
NetworkingOkHttp + BridgeWebSocket.ktWebSocket client, Ed25519 auth, E2EE
BackgroundBridgeService (Foreground Service)Keeps socket alive when backgrounded
PersistenceRoom + DataStoreOffline trajectory/artifact caching
UIJetpack Compose + Material 3Declarative UI, dynamic theming
TerminalTermux terminal-emulator + terminal-viewNative PTY with ANSI rendering
MarkdownCustom MarkdownText composableSyntax-highlighted AI responses

iOS

Built with SwiftUI and Swift 6, targeting iOS 16+:

LayerTechnologyPurpose
NetworkingURLSession WebSocket + async/awaitWebSocket client, Ed25519 auth
CryptoCryptoKitEd25519 verification, E2EE decryption
TerminalSwiftTermNative PTY terminal with ANSI rendering
UISwiftUIDeclarative UI, Dark Mode support
PersistenceCoreData / SwiftDataLocal conversation caching

End-to-End Encryption (E2EE)

Beyond TLS (provided by Cloudflare) and token authentication, Antimatter implements true E2EE using a Diffie-Hellman key exchange:

  1. During pairing, phone and Gateway exchange ephemeral DH public keys.
  2. Both sides derive the same 256-bit shared secret.
  3. All WebSocket payloads are AES-GCM encrypted on the sender before leaving the device.
  4. Decryption happens only on the receiving device β€” Cloudflare and any intermediaries only see ciphertext.

This provides zero-knowledge routing β€” even if the Cloudflare tunnel is compromised, the attacker cannot read the plaintext.


Next Steps


Saif Mukhtar

Saif Mukhtar

Creator & Lead Developer of Antimatter Β· Android, iOS & Python engineer