Rust Backend Design
Relevant source files
The following files were used as context for generating this wiki page:
Keynobi's backend is a high-performance Rust core built on the Tauri 2.0 framework. It leverages the Tokio async runtime to manage concurrent operations such as Gradle build streaming, real-time logcat processing, and Model Context Protocol (MCP) server communications. The design prioritizes memory efficiency, safe state management through strict Mutex discipline, and seamless integration with the SolidJS frontend.
Sources: AGENTS.md:6-10, README.md:Architecture Overview
Core Architecture and State Management
The backend is organized into services that manage business logic independently of the UI, and commands that expose this logic to the frontend via Tauri's IPC. Global state is managed using thread-safe wrappers (typically Arc<Mutex<T>>) and is registered in the Tauri builder to be accessible across commands.
State Discipline
A critical design rule in the Keynobi backend is Mutex discipline: state is locked, cloned if needed, and the lock is dropped immediately before any await point to prevent deadlocks across async boundaries.
Build System Orchestration
The Build System is responsible for executing Gradle tasks, parsing output in real-time, and maintaining a persistent history of build results.
Build Execution Flow
When a build is triggered, the build_runner service spawns a child process for the Gradle wrapper. It uses a SpawnOptions callback to process every line of output through a regex-based parser.
| Component | Description |
|---|---|
BuildState | Manages current status (Idle, Running, Success, Failed, Cancelled) and history. |
BuildLog | A ring-buffer (capped at 5,000 lines) of raw output. |
build_parser | Extracts errors, warnings, and durations from raw strings. |
ProcessManager | Handles child process lifecycle and SIGTERM signals. |
Sources: src-tauri/src/services/build_runner.rs:77-110, src-tauri/src/commands/build.rs:60-150
Build Completion Sequence
Logcat Processing Pipeline
The backend implements a sophisticated pipeline for handling high-frequency Android logcat data without overloading the frontend or memory.
Data Flow and Enrichment
The LogPipeline processes raw log lines through a series of specialized processors.
- PackageResolver: Maps PIDs to package names using ActivityManager events.
- CrashAnalyzer: Detects FATAL EXCEPTION and ANR signals, grouping stack trace lines into distinct groups.
- JsonExtractor: Heuristically detects and parses JSON bodies within logs.
- CategoryClassifier: Groups logs into Network, Lifecycle, Performance, etc., based on tags.
Model Context Protocol (MCP) Server
Keynobi includes a built-in MCP server, allowing AI agents (like Claude Code) to interact directly with the Android environment.
Deployment Modes
- GUI Mode: Started from within the app, sharing state with the active window.
- Headless Mode: Launched via
--mcpCLI flag, initializing its own state from project settings.
Available Tools
The MCP server exposes various tools for build management, device control, and project inspection.
| Tool Name | Purpose |
|---|---|
run_gradle_task | Executes builds and returns structured errors. |
get_logcat_entries | Queries the ring buffer with advanced filters. |
list_devices | Returns connected ADB devices and emulator status. |
screenshot | Captures and returns a base64 encoded PNG from a device. |
get_project_info | Provides path and Gradle root details. |
Sources: src-tauri/src/services/mcp_server.rs:163-560
File System and Project Management
The backend manages a registry of recent projects and performs automatic detection of Gradle roots.
- ID Generation: Projects are identified by a deterministic hex ID generated from their absolute path.
- Gradle Root Detection: The
fs_managerlooks forgradleworsettings.gradleto identify the workspace root. - Atomic Persistence: Project settings and build logs are saved using a "write-to-temp then rename" strategy to prevent corruption.
Sources: src-tauri/src/commands/file_system.rs:17-60, README.md:Architecture Overview
Summary
The Rust backend of Keynobi provides a robust, multi-threaded foundation for Android development. By combining high-speed log processing, structured build orchestration, and an AI-accessible MCP interface, it bridges the gap between traditional development tools and modern AI-driven workflows. Its reliance on type-safe models (via ts-rs) and async process management ensures stability and performance even under heavy loads.
Sources: README.md, src-tauri/Cargo.toml