Development
This guide covers setting up your development environment, running the application, and testing changes.Prerequisites
Before you begin, ensure you have the following installed:Rust Toolchain
Rust Toolchain
Node.js and npm
Node.js and npm
Tauri CLI
Tauri CLI
Install the Tauri CLI globally:Or use it via npx (already available as a devDependency):
Android Development (Optional)
Android Development (Optional)
For Android builds, you need:The project includes
- Android Studio
- Android SDK
- Android NDK
.cargo/config.toml with pre-configured NDK toolchains for:armv7-linux-androideabiaarch64-linux-androidx86_64-linux-androidi686-linux-android
Development Commands
Desktop Development
Start the development server with hot reload:- Starts the Vite development server
- Compiles the Tauri Rust backend
- Launches the desktop application window
- Enables hot reload for both frontend and backend changes
Android Development
Run on an Android emulator or connected device:Core Library Testing
Run unit tests for the Rust P2P core:Build Commands
Desktop Production Build
Build an optimized production binary:- Windows:
.msiinstaller insrc-tauri/target/release/bundle/msi/ - macOS:
.appbundle and.dmginsrc-tauri/target/release/bundle/dmg/ - Linux:
.debor.AppImageinsrc-tauri/target/release/bundle/
Android Production Build
Build an APK or AAB:src-tauri/gen/android/app/build/outputs/.
Workspace Build
Build the entire Rust workspace (both k2-core and k2-app-tauri):Testing Strategy
Unit Tests
Thek2-core crate includes unit tests in src/lib_tests.rs. Run them with:
Integration Testing
For end-to-end testing of Tauri commands, you can use Tauri’s built-in testing utilities:Manual Testing Checklist
- Node initialization (
init_node) - Profile creation and image upload
- Adding and pinging contacts
- Sending and receiving chat messages
- Sharing and downloading files
- Joining topics and broadcasting offers
- AI intent classification
- Folder sync setup and synchronization
Environment Configuration
Frontend Environment Variables
Create a.env file in k2-app-tauri/:
Runtime Environment Variables
The Rust backend respects these environment variables:| Variable | Purpose |
|---|---|
K2_DATA_DIR | Override the default data directory for isolated or guest mode |
APPDATA | Windows app data path (used for identity storage) |
Android Environment
For Android development, set these in your shell or.env file at the project root:
Project Scripts
package.json Scripts
| Script | Command | Description |
|---|---|---|
dev | vite | Start Vite dev server (frontend only) |
build | tsc && vite build | Build production frontend assets |
preview | vite preview | Preview production build |
tauri | tauri | Tauri CLI proxy |
Cargo Features
Thek2-core crate supports optional features:
| Feature | Description | Default |
|---|---|---|
content-discovery | Enable iroh-content-discovery for tracker-based peer finding | Enabled |
credential-store | Enable OS secure store via Amulet (Windows only) | Enabled |
Debugging
Enable Rust Logging
Set theRUST_LOG environment variable before running:
Frontend Debugging
The Tauri window includes Chrome DevTools. Right-click and select “Inspect” or pressCtrl+Shift+I (Windows/Linux) or Cmd+Option+I (macOS).
Common Issues
Android NDK not found
Android NDK not found
Ensure
ANDROID_NDK_HOME is set correctly and the NDK version matches .cargo/config.toml.Port already in use
Port already in use
Vite dev server defaults to port 5173. If occupied, it will auto-increment. Check the console output for the actual port.
Rust compilation errors
Rust compilation errors
Run
cargo clean in both k2-core/ and k2-app-tauri/src-tauri/, then rebuild.Code Style
- Rust: Follow standard Rust formatting (
cargo fmt) and linting (cargo clippy) - TypeScript/JavaScript: The project uses standard Vite/React conventions
- Commits: Use conventional commits for changelog generation