Files
openhuman/docs/ARCHITECTURE.md
T
c2ff8b693b feat/openclaw (#128)
* feat: add initial project structure and documentation

- Introduced the GNU General Public License (GPL) v3 in LICENSE file.
- Added MCP configuration in .claude/mcp.json for server integration.
- Created architecture documentation in docs/ARCHITECTURE.md outlining the platform's design and components.
- Defined MVP specifications in docs/MVP.md for the Telegram-based Agent Assistant.
- Established API reference for team management in docs/teams-api-reference.md.
- Set up basic HTML structure in public/index.html and added logo image in public/logo.png.

* feat: add initial project documentation and HTML structure

- Introduced CODE_OF_CONDUCT.md to establish community guidelines and standards for behavior.
- Created CONTRIBUTING.md to outline contribution process, development setup, and project conventions.
- Added SECURITY.md to define the security policy, supported versions, and reporting procedures for vulnerabilities.
- Established basic HTML structure in index.html for the application interface.

* chore: remove hello-python skill files

- Deleted skill.json and skill.py files for the Hello Python example runtime skill, as they are no longer needed in the project.

* feat: port tinyhuman agent runtime from ZeroClaw into Tauri backend

Port daemon supervisor, health registry, security (policy, secrets, audit,
pairing), agent traits, and config modules from ZeroClaw (MIT) into a new
tinyhuman/ module under src-tauri/src/. The daemon auto-starts on desktop
and shuts down gracefully on app exit via CancellationToken.

- health: global HealthRegistry with component tracking and JSON snapshots
- security/policy: SecurityPolicy with command validation, risk levels, rate limiting
- security/secrets: ChaCha20-Poly1305 SecretStore with legacy XOR migration
- security/audit: AuditLogger with JSON-line events and log rotation
- security/pairing: PairingGuard with brute-force protection and SHA-256 hashing
- security/traits: Sandbox trait + NoopSandbox
- config: minimal DaemonConfig with autonomy, reliability, secrets, audit sub-configs
- daemon: supervisor with health state writer emitting Tauri events
- agent/traits: Provider, Tool, Memory, Observer, RuntimeAdapter traits + Noop impls
- commands/tinyhuman: Tauri commands for health, security policy, encrypt/decrypt
- 185 inline unit tests across all modules
- README updated with custom inference/tunneling/memory positioning

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: update README to reflect AlphaHuman Mk1 branding and enhanced description

- Changed project title to "AlphaHuman Mk1" for clarity.
- Revised project description to emphasize user-friendly AI capabilities and the use of the Neocortex Mk1 model.
- Removed outdated sections on custom inference, tunneling, and memory, streamlining the content for better readability.

* update readme

* Port zeroclaw runtime into tinyhuman

* Replace CLI mentions with UI language

* Split gateway module into smaller units

* Split channels and config schema modules

* Fix tinyhuman build, tests, and tunnel integration

* feat(tinyhuman): add missing modules and ui-friendly services

* refactor: rename tinyhuman to alphahuman

* chore: remove bottom text from Welcome component

* feat(settings): add tauri command console

* feat(daemon): enhance daemon mode handling and integrate rustls with ring feature

* feat(settings): implement comprehensive configuration management in TauriCommandsPanel

* refactor(TauriCommandsPanel): streamline error handling and enhance async function usage

* feat(settings): add skill management functionality to TauriCommandsPanel

* style(TauriCommandsPanel): update input styles for improved readability and user experience

* feat(settings): add Skills and Agent Chat panels with navigation and integration management

* feat(settings): implement browser access management in SkillsPanel and enhance AgentChatPanel with local storage functionality

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 13:03:15 +04:00

18 KiB

AlphaHuman Architecture

AI-powered super assistant for crypto communities, built on Rust.

AlphaHuman is a cross-platform communication and automation platform purpose-built for the cryptocurrency ecosystem. A single React + Rust codebase compiles to native apps across six platforms — Windows, macOS, Linux, Android, iOS, and Web — with a sandboxed JavaScript skills engine, persistent Rust-native WebSocket infrastructure, and an AI tool protocol that lets language models invoke any connected service in real time.


Platform Reach

One codebase, six platforms, architecture-aware distribution:

                        AlphaHuman
                            |
            +---------------+---------------+
            |               |               |
         Desktop          Mobile           Web
        /   |   \        /     \            |
  Windows macOS Linux  Android  iOS      Browser
  x64    x64   x64    ARM     ARM64     Any
  ARM64  ARM64  ARM64

Tauri v2 compiles the Rust core into native binaries per platform, embedding the React frontend as a lightweight WebView. Desktop builds produce .dmg, .msi, .AppImage, and .deb installers. Mobile builds produce .apk and .ipa packages. The web target runs the React frontend directly with a JavaScript Socket.io client replacing the Rust networking layer.


High-Level Architecture

+------------------------------------------------------------------+
|                        React Frontend                            |
|  Redux Toolkit  |  Socket.io Client  |  MCP Transport  |  UI    |
+------------------------------------------------------------------+
                          |  Tauri IPC Bridge  |
+------------------------------------------------------------------+
|                        Rust Core Engine                           |
|                                                                  |
|  +------------------+  +------------------+  +-----------------+ |
|  |  QuickJS Skills  |  |  Socket Manager  |  |  AI Encryption  | |
|  |  Runtime Engine   |  |  (Persistent WS) |  |  & Memory Store | |
|  +------------------+  +------------------+  +-----------------+ |
|                                                                  |
|  +------------------+  +------------------+  +-----------------+ |
|  |  Skill Registry  |  |  Cron Scheduler  |  |  Session & Auth | |
|  |  & Bridge APIs   |  |  (5s tick loop)  |  |  Management     | |
|  +------------------+  +------------------+  +-----------------+ |
|                                                                  |
|  +------------------+  +------------------+  +-----------------+ |
|  |  TDLib Telegram  |  |  SQLite Storage  |  |  OS Keychain    | |
|  |  Client (Desktop)|  |  (rusqlite)      |  |  Integration    | |
|  +------------------+  +------------------+  +-----------------+ |
+------------------------------------------------------------------+
                          |
              +-----------+-----------+
              |                       |
     Backend Services          External APIs
     (Socket.io Server)        (Telegram, etc.)

The frontend communicates with the Rust core through Tauri's IPC bridge — 47+ registered commands covering auth, socket management, AI encryption, skill lifecycle, and platform operations. The Rust core owns all persistent connections, cryptographic operations, and sandboxed skill execution.


Rust-Powered Performance

AlphaHuman chose Tauri + Rust over Electron for fundamental performance and security reasons:

Metric AlphaHuman (Tauri + Rust) Typical Electron App
Binary size ~30 MB ~150 MB+
Memory per skill context ~1-2 MB (QuickJS) ~150 MB+ (Chromium renderer)
Cold startup Sub-500ms 2-5 seconds
Garbage collection pauses None (Rust ownership model) V8 GC pauses
Memory safety Compile-time guaranteed Runtime exceptions
TLS implementation rustls (no OpenSSL dependency) Chromium's BoringSSL

Why this matters for a crypto platform: Traders and analysts run AlphaHuman alongside resource-intensive tools — charting software, multiple browser tabs, trading terminals. A 30 MB footprint with sub-500ms startup means the app feels native and stays out of the way. Zero GC pauses means real-time price feeds and alerts are never delayed by memory management.

The Tokio async runtime drives all I/O — WebSocket connections, HTTP requests, file operations, and inter-skill communication — as non-blocking tasks on a thread pool. Thousands of concurrent operations (skill executions, cron jobs, socket events) share a small fixed set of OS threads.


Real-Time Socket Infrastructure

AlphaHuman implements a dual-socket architecture: a Rust-native WebSocket client on desktop and a JavaScript Socket.io client on web. The Rust implementation survives app backgrounding, operates independently of the WebView, and handles TLS via rustls.

Desktop Mode:                          Web Mode:

+-------------+                        +-------------+
|  React UI   |                        |  React UI   |
+------+------+                        +------+------+
       | Tauri IPC                            | Direct
+------+------+                        +------+------+
|  Rust Socket |                        |  JS Socket  |
|  Manager     |                        |  .io Client |
+------+------+                        +------+------+
       | tokio-tungstenite                    | Socket.io
       | + rustls TLS                         | (websocket/polling)
+------+------+                        +------+------+
|   Backend   |                        |   Backend   |
+-------------+                        +-------------+

Rust Socket Manager implements Engine.IO v4 + Socket.IO v4 framing over raw WebSocket:

  • Handshake: WebSocket connect, Engine.IO OPEN (extracts sid, pingInterval, pingTimeout), Socket.IO CONNECT with JWT auth, CONNECT ACK
  • Keep-alive: Responds to Engine.IO PING with PONG; timeout threshold = pingInterval + pingTimeout + 5s (default: 50 seconds)
  • Reconnection: Exponential backoff from 1 second to 30 seconds max. Resets to 1s after a successful connection is lost; keeps growing if connection was never established
  • CORS bypass: The Rust reqwest HTTP client makes external API calls directly — no browser CORS restrictions apply

The socket connection is shared across all skills. When events arrive, the socket manager routes them to the appropriate skill via async message channels. This eliminates per-skill connection overhead entirely.

tool:sync protocol: On every socket connect and skill lifecycle change, the client emits a tool:sync event containing the full list of available tools with their connection status. This keeps the backend AI system aware of all capabilities in real time.


Skills Runtime Engine

AlphaHuman's defining capability is its sandboxed JavaScript execution engine running inside the Rust process. Skills are lightweight automation scripts that extend the platform with custom tools, integrations, and scheduled tasks.

+---------------------------------------------------------------+
|                     RuntimeEngine                             |
|                                                               |
|  +-------------------+  +-------------------+                 |
|  | SkillRegistry     |  | CronScheduler     |                |
|  | (HashMap + MPSC)  |  | (5s tick loop)    |                |
|  +--------+----------+  +--------+----------+                |
|           |                      |                            |
|  +--------v----------+  +--------v----------+  +----------+  |
|  | QuickJS Instance  |  | QuickJS Instance  |  |  Bridge  |  |
|  | Skill A           |  | Skill B           |  |   APIs   |  |
|  | 64 MB memory cap  |  | 64 MB memory cap  |  +----+-----+  |
|  | 512 KB stack      |  | 512 KB stack      |       |        |
|  +-------------------+  +-------------------+       |        |
|                                                      |        |
|  +---------------------------------------------------v-----+ |
|  |  net  |  db  |  store  |  cron  |  log  |  tauri  |     | |
|  |  HTTP    SQLite  KV       Schedule  Log    Platform|     | |
|  +------------------------------------------------------+   | |
+---------------------------------------------------------------+

QuickJS Runtime (rquickjs): Each skill gets its own QuickJS AsyncRuntime and AsyncContext — fully isolated memory spaces with no cross-skill access.

Parameter Value
Default memory limit per skill 64 MB
Stack size 512 KB
Initialization timeout 10 seconds
Graceful stop timeout 5 seconds
Message channel buffer 64 messages

Message-passing architecture: Skills communicate with the core engine through async MPSC channels — no shared mutable state. The registry routes tool calls, server events, cron triggers, and lifecycle commands to the correct skill instance via its channel sender.

Bridge APIs expose platform capabilities to skill JavaScript code:

Bridge Capability
net HTTP fetch via reqwest (30s default timeout, all methods)
db SQLite database per skill via rusqlite
store Key-value persistence
cron Schedule registration (6-field cron expressions)
log Structured logging routed through Rust log crate
tauri Platform detection, notifications, whitelisted env vars

Skill discovery uses a manifest system. Each skill declares its metadata in a JSON manifest:

Field Purpose
id Unique identifier
name Human-readable display name
runtime Execution engine (quickjs)
entry Entry point file (default: index.js)
memory_limit_mb Per-skill memory cap (default: 64)
platforms Supported platforms (default: all)
setup OAuth and configuration wizard definition
auto_start Start on app launch

Skills are synced from a GitHub repository and discovered at runtime. Platform filtering ensures skills only run where they're supported.

Cron scheduler: A 5-second tick loop checks all registered schedules against UTC time, using the cron crate for expression parsing. When a schedule fires, the scheduler sends a CronTrigger message to the skill's channel, invoking the skill's onCronTrigger() handler.


AI & Tool Protocol (MCP)

AlphaHuman implements the Model Context Protocol — a JSON-RPC 2.0 layer over Socket.io that lets AI models discover and invoke tools exposed by skills.

User Prompt
    |
    v
AI Model (Backend)
    |
    |  1. mcp:listTools  -->  Frontend/Rust aggregates all skill tools
    |  <-- tool catalog
    |
    |  2. Decides which tool to call
    |
    |  3. mcp:toolCall { skillId__toolName, arguments }
    |         |
    |         v
    |     Socket Manager routes to Skill Registry
    |         |
    |         v
    |     QuickJS Skill Instance executes tool
    |         |
    |         v
    |     Bridge API call (HTTP, DB, etc.)
    |         |
    |  <-- mcp:toolCallResponse { result }
    |
    v
AI Response to User

Transport: 30-second timeout per request, mcp: event prefix, request IDs tracked in a pending response map. Tool names are namespaced as skillId__toolName for unambiguous routing.

Tool sync: The tool:sync event broadcasts the complete tool inventory — skill ID, name, connection status, and tool list — on every socket connect and skill state change. The backend AI system always has an up-to-date view of available capabilities.

AI Memory System:

Feature Implementation
Encryption at rest AES-256-GCM with Argon2id key derivation
Chunking 512 tokens per chunk, 64-token overlap
Search Hybrid: 70% vector similarity + 30% FTS5 full-text
Embeddings OpenAI text-embedding-3-small
Knowledge graph Neo4j via REST API for entity relationships
Sessions JSONL transcripts with compaction and tool compression

Memory encryption keys derive from user credentials via Argon2id, ensuring memory files are unreadable without authentication. The hybrid search combines semantic understanding (vector similarity) with keyword precision (SQLite FTS5) for reliable recall.


Security Architecture

+-------------------------------------------------------------------+
|                      Security Layers                              |
|                                                                   |
|  +------------------+  +------------------+  +------------------+ |
|  |  OS Keychain     |  |  AES-256-GCM     |  |  Sandboxed       | |
|  |  (macOS/Win/Lin) |  |  Memory Encrypt  |  |  QuickJS per     | |
|  |  for credentials |  |  + Argon2id KDF  |  |  skill (64 MB)   | |
|  +------------------+  +------------------+  +------------------+ |
|                                                                   |
|  +------------------+  +------------------+  +------------------+ |
|  |  Single-Use      |  |  rustls TLS      |  |  No localStorage | |
|  |  Login Tokens    |  |  for all network |  |  for sensitive   | |
|  |  (5-min TTL)     |  |  connections     |  |  data            | |
|  +------------------+  +------------------+  +------------------+ |
+-------------------------------------------------------------------+
  • Credential storage: OS keychain integration via the keyring crate (macOS Keychain, Windows Credential Manager, Linux Secret Service) — desktop only
  • Memory encryption: AES-256-GCM with Argon2id key derivation. All AI memory is encrypted at rest
  • Skill sandboxing: Each QuickJS instance has enforced memory limits (64 MB default) and stack limits (512 KB). No cross-skill memory access
  • Auth handoff: Web-to-desktop authentication uses single-use login tokens with 5-minute TTL, exchanged via Rust HTTP client (bypasses CORS)
  • Network TLS: All WebSocket and HTTP connections use rustls — no dependency on platform OpenSSL
  • State management: Sensitive data lives in Redux (memory) and OS keychain (persistent). No localStorage for credentials or tokens

End-to-End Data Flow

A complete flow from user action to external service and back:

User types a command in the chat UI
          |
          v
React Frontend dispatches to AI provider
          |
          v
AI model receives prompt + tool catalog (via tool:sync)
          |
          v
AI decides to invoke a skill tool (e.g., send Telegram message)
          |
          v
mcp:toolCall event sent over Socket.io
          |
          v
Socket Manager (Rust) receives event, parses skillId__toolName
          |
          v
Skill Registry routes message to correct QuickJS instance via MPSC channel
          |
          v
QuickJS skill executes tool handler
          |
          v
Bridge API: net.rs makes HTTP request via reqwest (CORS-free, rustls TLS)
          |
          v
External service responds (e.g., Telegram API)
          |
          v
Result flows back: Bridge -> QuickJS -> Registry -> Socket -> MCP -> AI -> UI
          |
          v
User sees the result in the chat interface

Every layer is async and non-blocking. The Rust core processes thousands of concurrent skill executions, cron triggers, and socket events on a fixed Tokio thread pool.


Technology Stack

Layer Technology Why
Frontend React 19, TypeScript 5.8 Modern component model, type safety
State Redux Toolkit + Persist Predictable state with offline persistence
Build Vite 7 Sub-second HMR, optimized production builds
Styling Tailwind CSS Utility-first, consistent design system
Framework Tauri v2 Native cross-platform with minimal overhead
Language Rust (2021 edition) Memory safety, zero-cost abstractions
Async Tokio High-performance async I/O runtime
JS Engine QuickJS (rquickjs) Lightweight sandboxed JS execution (~1-2 MB per context)
Database SQLite (rusqlite) Embedded, zero-config, per-skill isolation
WebSocket tokio-tungstenite + rustls Persistent connections with native TLS
HTTP reqwest Async HTTP with rustls + native-tLS dual support
Encryption aes-gcm + argon2 AES-256-GCM encryption, Argon2id key derivation
Scheduling cron crate + custom scheduler Standard cron expressions, 5-second resolution
Telegram TDLib (tdlib-rs) Official Telegram client library, desktop only
Realtime Socket.io (client) Bidirectional event-based communication
AI MCP (JSON-RPC 2.0) Standardized tool protocol for LLM integration
Search OpenAI embeddings + SQLite FTS5 Hybrid semantic + keyword search
Graph Neo4j Entity relationship knowledge graph