How moxin-org/moly works
Project type and purpose
• Moly is a full‑stack, multi‑platform desktop application (built in Rust) that serves as an AI LLM client.
• It uses the Makepad UI toolkit for rendering the user interface, Robius to manage multi‑platform WASM execution, and communicates with LLM backends via WebAssembly (WASM) modules and/or an external MoFa server.
File structure
• Root
• Cargo.toml / workspace — defines multiple Rust crates.
• .github/workflows — CI build and release pipelines.
• build.sh, packaging/ — scripts and configuration for packaging into .app, .dmg, .deb, AppImage, .exe, etc.
• src/ — the front‑end desktop client built with Makepad. Contains:
• main.rs, app.rs — application entry and initialization.
• chat/, landing/, my_models/, settings/, shared/ — UI modules for different screens and shared components.
• data/ — local storage modules (chats, downloads, preferences) abstracting file system and remote model download.
• moly-protocol/ — shared data types and RPC/message schemas (chat messages, model descriptors, OpenAI protocol compliance).
• moly-backend/ — orchestrator crate that loads and executes backend WASM modules via WasmEdge:
• backend_impls/ — implementations for api_server.wasm and chat_ui.wasm.
• store/ — local model store: downloads, metadata, remote fetch.
• wasm/ — precompiled WASM binaries (chat_ui.wasm, llama-api-server.wasm).
• moly-fake-backend/ — a fake MoFa‑compatible HTTP server (for local development without a real MoFa server).
• moly-mofa/ — integration utilities to communicate with a real MoFa server via HTTP/dora.
• moly-runner/ — CLI helper to install WasmEdge, set environment, and forward any cargo command.
• packaging/ — initial template for build‑and‑packaging commands.
Extract insights from the README
• Describes multi‑platform building (macOS, Linux, Windows) via WasmEdge and cargo-packager.
• Explains how to connect to a MoFa server or use a fake backend.
• Emphasizes modular architecture: front‑end, protocol, back‑end WASM modules, external services.
Main components
a. Frontend (Makepad UI)
• src/main.rs → app.rs → UI modules (chat screen, landing page, settings).
• Local Data Layer (data/*): file system, preferences, cached models.
• Uses moly-protocol types to marshal/unmarshal requests and responses.
b. Wasm runtime (WasmEdge)
• Hosted by moly-backend crate.
• Loads two primary WASM modules:
• chat_ui.wasm — processes UI‑side logic in a sandbox.
• llama-api-server.wasm — communicates with local LLM libraries compiled to WASM (e.g., Llama).
c. Backend orchestrator (moly-backend)
• Exposes a local API server (via Robius) for the front‑end to call into WASM modules.
• Implements storage interfaces: download_models, metadata, remote communication.
d. External services
• Real MoFa server (HTTP/gRPC) via moly-mofa crate.
• Fake MoFa backend (HTTP) for testing (moly-fake-backend).
• Optional external LLM endpoints (OpenAI) driven by moly-protocol/open_ai.rs.
e. Packaging & CLI Tools
• moly-runner: CLI wrapper to ensure WasmEdge is installed and environment is configured.
• packaging scripts: cargo-packager configurations generating native installers.
f. CI/CD
• GitHub Actions workflows for continuous integration, build artifacts, and releases.
Relationships and interactions
• User interacts with Makepad UI → triggers actions (e.g., “new chat”, “download model”).
• UI layer calls into moly-backend’s local API (over in‑process RPC via Robius).
• moly-backend dispatches calls to:
• WASM modules (for UI rendering logic or LLM inference).
• Store module (downloads, reads/writes metadata).
• moly-mofa or fake-backend HTTP client (for agent interactions).
• WASM modules run in WasmEdge sandbox, returning results back to the orchestrator.
• Orchestrator returns results back to the UI via the Robius bridge.
• Packaging pipeline packages the final binary plus WASM files and resources into platform‑specific installers.
Architectural patterns and design principles
• Modular multi‑crate Rust workspace (separation of concerns).
• WASM-based plugin architecture (sandboxing LLM code).
• Clear separation between UI, protocol, backend orchestration, and storage.
• Use of a shared protocol crate to enforce strong typing across boundaries.
• Dependency injection of fake vs. real backends for testing and development.
Detail
• Every essential crate as its own component or subcomponent.
• Both real and fake backend paths.
• CI/CD and packaging as higher‑level external flows if space permits.
• Naming matches directory names (e.g., “moly-protocol”, “moly-backend”, “moly-runner”).