Architecture Overview
Project AIRI is built as a modern, modular monorepo designed to power AI-driven virtual characters across multiple platforms. This guide provides a comprehensive overview of the system architecture, technology stack, and component interactions.System Architecture
AIRI follows a layered architecture that separates concerns between presentation (Stage), business logic (Core), and runtime services (Server).Monorepo Structure
The project is organized as a pnpm workspace monorepo with clear separation of concerns:Directory Layout
Workspace Organization
- Apps
- Packages
- Services
- Plugins
Application-level packages that users interact with directly:
- stage-web: Browser-based web application (Vue 3 + Vite)
- stage-tamagotchi: Desktop application (Electron + Vue 3)
- stage-pocket: Mobile application (Capacitor + Vue 3)
- server: Backend API server
- component-calling: Component system examples
Technology Stack
Frontend Technologies
| Technology | Purpose | Used In |
|---|---|---|
| Vue 3 | UI framework | All Stage apps |
| TypeScript | Type safety | Entire codebase |
| Vite | Build tool | All apps |
| Pinia | State management | Stage apps |
| VueUse | Vue composables | All Vue code |
| UnoCSS | Utility-first CSS | All frontends |
| Reka UI | Headless UI components | UI primitives |
| Three.js | 3D graphics | VRM/3D rendering |
| Vitest | Unit testing | All packages |
Backend & Runtime Technologies
| Technology | Purpose | Used In |
|---|---|---|
| Node.js | Runtime environment | All servers |
| Electron | Desktop app framework | stage-tamagotchi |
| Capacitor | Mobile app framework | stage-pocket |
| H3 | HTTP server | server-runtime |
| CrossWS | WebSocket library | server-runtime |
| DuckDB WASM | In-browser database | Web/Desktop |
| Drizzle ORM | Database ORM | All database code |
Development Tools
| Tool | Purpose |
|---|---|
| pnpm | Package manager & workspaces |
| ESLint | Linting & formatting |
| Turbo | Monorepo build orchestration |
| tsdown | TypeScript bundler |
| nano-staged | Git hooks |
Key Libraries
AI & ML
AI & ML
- @xsai/generate-text: Text generation abstraction
- @xsai/stream-text: Streaming text generation
- @xsai/generate-speech: Speech synthesis
- @xsai/stream-transcription: Streaming speech recognition
- @huggingface/transformers: Transformers.js for in-browser ML
- onnxruntime-web: ONNX model inference in browser
Communication & IPC
Communication & IPC
- @moeru/eventa: Type-safe IPC/RPC framework
- injeca: Dependency injection for services
- crossws: WebSocket server/client
- superjson: JSON serialization with type preservation
Graphics & Animation
Graphics & Animation
- @tresjs/core: Three.js Vue integration
- @tresjs/cientos: Three.js helper components
- animejs: Animation library
- @vueuse/motion: Vue animation composables
Validation & Schema
Validation & Schema
- valibot: Schema validation
- zod: Alternative schema validation
- xstate: State machine library
Frontend Architecture
Stage Applications
The “Stage” represents the presentation layer where AIRI appears to users. All Stage applications share a common architecture:Component Hierarchy
Stage UI Package (packages/stage-ui/)
The heart of the Stage system, containing:
Directory Structure:
- Character state management
- Provider configurations (OpenAI, Claude, etc.)
- Audio input/output handling
- Speech recognition (VAD)
- UI business logic
- Animation controllers
UI Primitives (packages/ui/)
Standardized UI primitives built on reka-ui:
- Form components (Input, Textarea, Select, etc.)
- Layout components (Card, Dialog, Sheet, etc.)
- Feedback components (Toast, Alert, etc.)
- Minimal business logic - pure presentation
Styling System
AIRI uses UnoCSS (not Tailwind) for styling. Prefer UnoCSS over Tailwind CSS throughout the codebase.
- Main config:
uno.config.tsat root - Custom shortcuts and rules defined in config
- Theme customization via UnoCSS presets
Routing
- Stage Web
- Stage Tamagotchi
Router configuration in Pages directory:
vite.config.ts:apps/stage-web/src/pages/
Devtools: apps/stage-web/src/pages/devtools/Backend Architecture
Server Runtime (packages/server-runtime/)
The server runtime provides a WebSocket-based communication layer for connecting various AIRI components.
Architecture
Key Concepts
Peers: Connected WebSocket clients (UI, plugins, services) Modules: Named components that announce themselves Events: Messages with metadata, routing info, and data Routing: Event forwarding with destination filteringEvent Types
Running the Server
Server SDK (packages/server-sdk/)
Client SDK for connecting to the server runtime:
Data Flow
User Interaction Flow
Plugin Communication Flow
IPC & Communication
Eventa Framework
AIRI uses@moeru/eventa for type-safe, framework-agnostic IPC/RPC:
- Electron main ↔️ renderer:
apps/stage-tamagotchi/src/shared - Plugin ↔️ host:
packages/plugin-sdk - Service ↔️ service: Custom contracts
Dependency Injection
AIRI usesinjeca for dependency injection:
apps/stage-tamagotchi/src/main/index.ts for composition patterns.
Database & Persistence
DuckDB WASM
In-browser database for web and desktop:Storage Solutions
| Storage | Use Case | Packages |
|---|---|---|
| DuckDB WASM | Structured data (messages, analytics) | @proj-airi/duckdb-wasm |
| LocalForage | Key-value storage | localforage |
| IndexedDB | Large binary data | idb-keyval |
| PostgreSQL | Production services (Telegram bot) | drizzle-orm |
Internationalization
Centralized translations inpackages/i18n/:
- Add keys to
packages/i18n/locales/ - Never scatter i18n across apps/packages
- Contribute to Crowdin for translations
Performance Considerations
Web Performance
Web Workers
VAD and heavy computations run in Web Workers to avoid blocking the main thread.
Code Splitting
Dynamic imports and route-based splitting reduce initial bundle size.
WebGPU
GPU acceleration for ML inference and 3D rendering where available.
WASM
DuckDB and ONNX Runtime use WebAssembly for near-native performance.
Desktop Performance
The Electron app (stage-tamagotchi) can use:
- Native CUDA (NVIDIA)
- Metal (Apple)
- Native file system access
- Native audio/video APIs
Mobile Performance
Capacitor (stage-pocket) bridges to native APIs:
- Native camera/microphone
- Push notifications
- Background tasks
- File system access
Build System
Turbo Orchestration
The monorepo uses Turbo for efficient builds:Package Bundling
Packages usetsdown for bundling:
Testing Strategy
Unit Tests (Vitest)
Testing Patterns
- Mock IPC/services with
vi.fn()/vi.mock() - Don’t rely on real Electron runtime
- Keep tests targeted for speed
- Use Vitest browser env where possible
Configuration Files
Key Configuration Locations
| File | Purpose |
|---|---|
package.json | Root workspace config |
pnpm-workspace.yaml | Workspace definition |
tsconfig.json | Base TypeScript config |
uno.config.ts | UnoCSS configuration |
eslint.config.js | ESLint rules |
vitest.config.ts | Vitest configuration |
turbo.json | Turbo pipeline config |
Environment Variables
Common environment variables:Next Steps
Plugin Development
Learn how to create plugins for AIRI
Contributing Guide
Set up your development environment
API Reference
Explore the API documentation
Examples
Check out example implementations
