How kwaroran/risuai works
Project Type and Purpose
• RisuAI is a full‑stack, cross‑platform AI chat client and web app.
• It targets three environments with a shared Svelte/TypeScript front end:
– Desktop (Tauri/Rust + optional Python subprocess)
– Mobile (Capacitor/Android)
– Web (static hosting + optional local Node.js server and cloud functions)
Top‑Level Components
A. Frontend (Svelte + TypeScript)
– src/ (App.svelte, LiteMain.svelte, UI, ChatScreens, Settings, SideBars, Playground, etc.)
– Uses web workers (public/assets/*.wasm + .js) for translation and tokenizer.
– Bundled via Vite (vite.config.ts) and styled with Tailwind (tailwind.config.js).
B. Host Adapters / Backends
1. Desktop Adapter (Tauri)
– src‑tauri/src/main.rs (Rust core)
– src‑tauri/src‑python (Python subprocess for advanced tasks)
– Communicates with the front end via IPC (Tauri APIs).
– Reads/writes via local FS (using chosen storage module).
2. Mobile Adapter (Capacitor / Android)
– android/app/src/main/java/.../MainActivity.java
– android/app/src/main/java/.../StreamedPlugin.java (native plugin for streaming LLM responses)
– Bridges Svelte code to Android native capabilities.
3. Web Adapter
– Static hosting of index.html + public/ (assets, sw.js, manifest.json)
– Optional local Node.js server (server/node/server.cjs) for proxying LLM requests, SSL termination, drive backups.
– Cloud Functions (functions/drive.js, functions/proxy*.js) to run on serverless platforms.
C. External Services
– LLM Providers: OpenAI, Claude, Ooba, OpenRouter, Cohere, etc. (configured via environment or UI)
– Google Drive (drive backup integration via functions/drive.js)
– TTS services (configurable per provider)
D. Storage Layer
– IndexedDB/OPFS (web) – src/ts/storage/opfsStorage.ts
– localStorage (browser fallback) – autoStorage.ts
– mobileStorage.ts (Capacitor plugin)
– nodeStorage.ts (Node.js FS)
– accountStorage.ts (user credentials)
Data Flow & Interactions
1. User interacts with UI (Svelte components)
2. UI invokes API layer (calls Tauri IPC, Capacitor plugin, or fetch to Node server/functions)
3. Adapter layer handles:
– Routing requests to LLM endpoints (via HTTP or TCP)
– Running translator and tokenizer workers in‑browser or via Python subprocess
– Persisting chats, settings, files via appropriate storage module
– Emitting streaming tokens to UI (via IPC or Capacitor streams)
4. External LLM responds; responses flow back through the same adapter to the UI for rendering.
5. Optional cloud functions manage secure token proxying and drive backups.
Architectural Patterns & Key Principles
– Shared‑UI, multi‑adapter architecture (“write once, run anywhere”)
– Adapter pattern for environment‑specific implementations
– Micro‑service‑like decomposition for cloud functions vs. monolithic Node server
– Use of web workers/WebAssembly for performance‑critical tasks (translation, tokenization)
– Modular front‑end: Svelte component library (ChatScreens, UI, Settings, Playground)
– Pluggable provider interfaces (see plugins.md)