BitFun is an AI agent-driven programming environment built with Rust and TypeScript, using multi-platform architecture (Desktop/CLI/Server) sharing a common core library.
- src/crates/events - Event definitions (platform-agnostic)
- src/crates/core - Core business logic (95%+ code reuse)
agentic/- Agent system (session, tools, execution)service/- Workspace, Config, FileSystem, Terminal, Gitinfrastructure/- AI client, storage, logging, events
- src/crates/transport - Transport adapters (CLI, Tauri, WebSocket)
- src/crates/api-layer - Platform-agnostic handlers
- src/apps/desktop - Tauri 2.0 desktop app
- src/apps/cli - Terminal UI(WIP)
- src/apps/server - Web server (Axum + WebSocket)(WIP)
- src/web-ui - React frontend
infrastructure/- Theme, I18n, Config, State management, API adapterscomponent-library/- Shared UI componentstools/- Feature modules (editor, git, terminal, mermaid...)flow_chat/- Chat UIlocales/- Translation files (en-US, zh-CN)
- Dependency Injection - Services receive dependencies via constructors
- EventEmitter Pattern - Use
Arc<dyn EventEmitter>notAppHandle - TransportAdapter Pattern - Abstract communication across platforms
- Platform Agnostic Core - No platform-specific dependencies in core
- Backend: Rust 2021, Tokio, Tauri 2.0, Axum
- Frontend: React 18, TypeScript, Vite, Zustand
# Desktop
npm run desktop:dev # Dev mode
# E2E
npm run e2e:testRules: English only, no emojis, structured data, avoid verbose logging
- Frontend:
src/web-ui/LOGGING.md- UsecreateLogger('ModuleName') - Backend:
src/crates/LOGGING.md- Uselog::{info, debug, ...}macros
Never use platform-specific APIs in core code:
- ❌
use tauri::AppHandle - ✅
use bitfun_events::EventEmitter
Naming: Commands snake_case, Rust snake_case, TypeScript camelCase
Always use structured request format:
#[tauri::command]
pub async fn your_command(
state: State<'_, AppState>,
request: YourRequest,
) -> Result<YourResponse, String>await api.invoke('your_command', { request: { ... } });When developing frontend features, reuse existing infrastructure:
- Theme:
infrastructure/theme/- useTheme, useThemeToggle - I18n:
infrastructure/i18n/+locales/- useI18n, t() - Components:
component-library/- shared UI components - State: Zustand stores in each module
SessionManager → Session → DialogTurn → ModelRound
ConversationCoordinator- Orchestrates turnsExecutionEngine- Multi-round loopToolPipeline- Tool execution with concurrency
Location: .bitfun/sessions/{session_id}/
Register in agentic/tools/registry.rs:
- Implement
Tooltrait - Define input/output types
- Handle streaming if applicable
In agentic/agents/:
- Create agent file
- Define prompt in
prompts/ - Register in
registry.rs