How ahqsoftorg/ahqai works
Purpose and topology
ahq-ai is a multi-runtime AI/chat system centered on a Rust server that hosts or controls llama.cpp inference, a Tauri-based cross-platform client, and supporting administration, runtime, speech, and installation utilities. The top-level entry points are:
• server/src/main.rs
• client/src/main.tsx
• client/src-tauri/src/main.rs
• ahqai-admin/src/main.rs
Server bootstrap and API composition
The server executable initializes application services and composes distinct API domains: HTTP transport, authentication, chat, admin, FFI, and llama operations. server/src/server/mod.rs is the principal server boundary; server/src/server/apiset.rs likely binds enabled API sets/routes.
• server/src/main.rs
• server/src/server/mod.rs
• server/src/server/http/mod.rs
Control flow is client request/connection → HTTP/auth boundary → chat or management API → model/runtime or persistence backend → streamed or regular response.
Authentication, identity, and persistence abstraction
Authentication is separated from request handlers and supports pluggable backing stores. Password/key handling is implemented locally, while authentication servers support in-memory Moka, MongoDB, and TiKV; cache implementations include Moka and Redis. This is the principal external-service boundary for user/session state.
• server/src/auth/mod.rs
• server/src/auth/authserver/mongodb/mod.rs
• server/src/auth/cache/redis/mod.rs
Shared database/error contracts reside in server/src/structs/db.rs and server/src/structs/error.rs, insulating API and UI layers from concrete storage providers.
Llama inference and native-runtime boundary
The server’s llama subsystem owns model-facing requests and inference structures, while an FFI module forms the native integration boundary. Server-side UI includes model and lifecycle management, suggesting configuration-driven loading and operational control of local models.
• server/src/server/llama/mod.rs
• server/src/server/ffi/mod.rs
• server/src/ui/llama/manager.rs
getllamacpp is a separate Rust acquisition/build utility for llama.cpp, so model runtime provisioning is intentionally outside ordinary request handling:
• getllamacpp/src/main.rs
• getllamacpp/src/download/mod.rs
• getllamacpp/src/compile/mod.rs
Client application and server protocol
The client is a React/TypeScript application built with Vite. It presents splash, server setup, chat, sidebar, and settings views; server communication is centralized rather than embedded in components. Chat and WebSocket code are the key protocol consumers.
• client/src/main.tsx
• client/src/App/App/Chat/index.tsx
• client/src/App/server/ws/index.ts
The UI maintains local server and chat records through a store/database layer, then uses REST, WebSocket, keyboard, and key modules to interact with configured servers.
• client/src/App/store/index.ts
• client/src/App/store/db/chats.ts
• client/src/App/server/rest.ts
Desktop/mobile host and secure plugin layer
Tauri packages the web client for desktop and mobile. The Rust host owns native startup, SQL migrations/storage, capabilities, and platform packaging. A separate plugin exposes desktop/mobile commands and integrity checks to guest JavaScript, creating a deliberate privileged boundary.
• client/src-tauri/src/lib.rs
• client/src-tauri/src/sql.rs
• client/src-plugin/src/lib.rs
Platform-specific implementations are present for Android and Apple:
• client/src-plugin/android/src/main/java/AhqAi.kt
• client/src-plugin/ios/Sources/AhqAi.swift
• client/src-plugin/src/commands.rs
Operational tools, runtimes, and delivery
ahqai-admin is a separate Rust administration client/API surface for general, user, and copy operations. ahqrt provides reusable Rust runtime primitives, including futures, memory/container types, and C bindings; sherpa wraps native speech-recognition functionality. CI separately builds server, client, Apple client, documentation pages, and Rust linting.
• ahqai-admin/src/api/mod.rs
• ahqrt/src/lib.rs
• sherpa/sherpac/src/lib.rs
Relevant delivery infrastructure:
• .github/workflows/server.yml
• .github/workflows/client.yml
• .github/workflows/client-apple.yml
Components 23
Server
Rust API, identity, and inference host.
- Server bootstrap
server/src/main.rs - Server composition · Composes enabled API domains and application services.
server/src/server/mod.rs - HTTP transport
server/src/server/http/mod.rs - Authentication · Separates password/key handling from API handlers.
server/src/auth/mod.rs - Mongo auth store
server/src/auth/authserver/mongodb/mod.rs - Redis cache
server/src/auth/cache/redis/mod.rs - Database contracts · Storage and error contracts isolate concrete providers.
server/src/structs/db.rs - Llama operations · Owns model-facing requests and inference structures.
server/src/server/llama/mod.rs - Native FFI
server/src/server/ffi/mod.rs - Model manager UI · Controls model configuration and lifecycle.
server/src/ui/llama/manager.rs - Admin client · Provides general, user, and copy operations.
ahqai-admin/src/api/mod.rs
Client
React UI and Tauri host.
- React client
client/src/main.tsx - Chat view
client/src/App/App/Chat/index.tsx - Server protocol · Centralizes configured-server communication.
client/src/App/server/ws/index.ts - Client store · Maintains server and chat records.
client/src/App/store/index.ts - Tauri host · Owns native startup, storage, migrations, and packaging.
client/src-tauri/src/lib.rs - Tauri SQL storage
client/src-tauri/src/sql.rs - Secure plugin · Exposes native commands and integrity checks to guest JavaScript.
client/src-plugin/src/lib.rs
Native tooling
Provisioning and reusable native runtimes.
- llama.cpp provisioner · Downloads and compiles the inference runtime outside request handling.
getllamacpp/src/main.rs - ahqrt · Provides reusable futures, memory/container types, and C bindings.
ahqrt/src/lib.rs - Sherpa speech runtime
sherpa/sherpac/src/lib.rs - Server CI
.github/workflows/server.yml - Client CI
.github/workflows/client.yml
Connections 22
- Server bootstrap → Server composition: initializes
- Server composition → HTTP transport: serves
- HTTP transport → Authentication: authenticates
- Authentication → Mongo auth store: pluggable identity store
- Authentication → Redis cache: cache backend
- Authentication → Database contracts: uses contracts
- Server composition → Llama operations: routes inference
- Llama operations → Native FFI: invokes native runtime
- Model manager UI → Llama operations: manages models
- React client → Chat view: renders
- Chat view → Server protocol: sends chat
- React client → Client store: persists local records
- Server protocol → HTTP transport: REST/WebSocket requests
- Tauri host → React client: packages guest UI
- Tauri host → Tauri SQL storage: owns
- React client → Secure plugin: calls privileged commands
- Admin client → Server composition: management operations
- llama.cpp provisioner → Native FFI: provisions llama.cpp
- ahqrt → Native FFI: native primitives
- Sherpa speech runtime → Native FFI: speech capability
- Server CI → Server bootstrap: builds
- Client CI → Tauri host: builds