This guide provides detailed information for developers working on the CodeFlow Desktop application.
- Environment Setup
- Project Structure
- Development Workflow
- Architecture
- API Reference
- Testing
- Performance
- Security
-
Clone the repository and navigate to the desktop app:
cd codeflow-desktop -
Install all dependencies:
# Node.js dependencies npm install # Python sidecar dependencies pip install -r sidecar/requirements.txt # Verify Rust installation rustc --version cargo --version
-
Set up environment variables (optional): Create a
.envfile in thecodeflow-desktopdirectory:VITE_WEBSOCKET_URL=ws://localhost:8765 VITE_API_BASE_URL=http://localhost:8000
Install recommended extensions:
{
"recommendations": [
"tauri-apps.tauri-vscode",
"rust-lang.rust-analyzer",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"bradlc.vscode-tailwindcss",
"formulahendry.auto-rename-tag"
]
}Add to .vscode/settings.json:
{
"rust-analyzer.linkedProjects": ["src-tauri/Cargo.toml"],
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
}src/
├── App.tsx # Root component with routing
├── main.tsx # Application entry point
├── pages/ # Page components
│ ├── Dashboard.tsx # Main dashboard view
│ ├── Configuration.tsx # Settings and config editor
│ ├── PlatformAnalytics.tsx # Platform detection results
│ └── Logs.tsx # Real-time log viewer
├── components/ # Reusable UI components
│ └── ui/ # shadcn/ui components
│ ├── button.tsx
│ ├── card.tsx
│ └── badge.tsx
├── assets/ # Static assets
└── schema.json # JSON schema for configuration
src-tauri/
├── src/
│ ├── main.rs # Tauri app initialization
│ └── lib.rs # Core library with IPC handlers
├── tauri.conf.json # Tauri configuration
├── Cargo.toml # Rust dependencies
└── capabilities/ # Tauri permissions
└── default.json
sidecar/
├── main.py # Sidecar entry point
├── websocket_handler.py # WebSocket server for live updates
├── generate_schema.py # Schema generation utility
└── requirements.txt # Python dependencies
# Full stack development (recommended)
npm run tauri dev
# Frontend only (for UI work)
npm run dev-
Frontend Changes (React/TypeScript)
- Edit files in
src/ - Changes auto-reload via HMR
- Check browser DevTools for errors
- Edit files in
-
Backend Changes (Rust)
- Edit files in
src-tauri/src/ - Application restarts automatically
- Check terminal for compilation errors
- Edit files in
-
Sidecar Changes (Python)
- Edit files in
sidecar/ - Requires manual restart of
npm run tauri dev
- Edit files in
TypeScript/React:
- Use functional components with hooks
- Follow React best practices
- Use TypeScript strict mode
- Format with Prettier
Rust:
- Follow Rust style guidelines (rustfmt)
- Use clippy for linting:
cargo clippy - Write idiomatic Rust code
Python:
- Follow PEP 8 style guide
- Use type hints
- Format with Black (if available)
┌─────────────────�
│ React Frontend │
│ (TypeScript) │
└────────┬────────┘
│ IPC
├──────────�
│ │
┌────▼────� ┌─▼─────────�
│ Tauri │ │ WebSocket │
│ (Rust) │ │ (Python) │
└────┬────┘ └─┬─────────┘
│ │
└─────┬───┘
│
┌─────▼──────�
│ CodeFlow │
│ Engine │
└────────────┘
The Rust backend exposes commands that can be called from the frontend:
Defining a command (Rust):
#[tauri::command]
fn my_custom_command(arg: String) -> Result<String, String> {
// Implementation
Ok(format!("Processed: {}", arg))
}Calling from frontend (TypeScript):
import { invoke } from '@tauri-apps/api/core';
const result = await invoke<string>('my_custom_command', {
arg: 'test'
});The application uses React hooks for state management:
// Local state
const [data, setData] = useState<Data>([]);
// Effect for side effects
useEffect(() => {
// Load data
invoke('get_data').then(setData);
}, []);The Python sidecar provides real-time updates via WebSocket:
Server (Python):
# sidecar/websocket_handler.py
async def handle_client(websocket):
await websocket.send(json.dumps({
'type': 'log',
'data': 'Log message'
}))Client (TypeScript):
const ws = new WebSocket('ws://localhost:8765');
ws.onmessage = (event) => {
const message = JSON.parse(event.data);
// Handle message
};Commands exposed by the Rust backend:
// Example commands (add actual commands here)
#[tauri::command]
fn get_config() -> Result<Config, String>
#[tauri::command]
fn save_config(config: Config) -> Result<(), String>
#[tauri::command]
fn run_detection(path: String) -> Result<DetectionResult, String>Message types from Python sidecar:
type WebSocketMessage =
| { type: 'log', level: string, message: string }
| { type: 'status', status: string }
| { type: 'progress', current: number, total: number }
| { type: 'result', data: any };# Run tests (if configured)
npm test
# Type checking
npm run build # TypeScript will error if types are wrongcd src-tauri
# Run unit tests
cargo test
# Run with output
cargo test -- --nocapture
# Test specific module
cargo test module_namecd sidecar
# Run tests (if configured)
pytest
# With coverage
pytest --cov=.-
Build and test the app:
npm run tauri build
-
Test the installer:
- Navigate to
src-tauri/target/release/bundle/ - Install and run the application
- Verify all features work
- Navigate to
- Use
React.memo()for expensive components - Implement virtualization for long lists
- Lazy load routes:
const Dashboard = lazy(() => import('./pages/Dashboard'));
- Use async Rust where appropriate
- Implement connection pooling
- Cache expensive computations
# Optimize Rust binary
cargo build --release
# Optimize frontend bundle
npm run build -- --minify-
Content Security Policy (CSP)
- Configured in
tauri.conf.json - Restrict external resources
- Configured in
-
Capability System
- Define permissions in
capabilities/default.json - Principle of least privilege
- Define permissions in
-
IPC Security
- Validate all inputs from frontend
- Use type-safe communication
- Never expose sensitive data in IPC commands
- Sanitize user inputs
- Use HTTPS for external APIs
- Keep dependencies updated:
npm audit cargo audit
-
Browser DevTools
- Open:
Ctrl+Shift+I(Windows/Linux) orCmd+Option+I(macOS) - Use React DevTools extension
- Open:
-
Console Logging
console.log('Debug info:', data);
-
Print Debugging
println!("Debug: {:?}", value); dbg!(&value);
-
Enable Backtrace
RUST_BACKTRACE=1 npm run tauri dev
-
Use VS Code Debugger
- Configure
launch.jsonfor Rust debugging - Set breakpoints in VS Code
- Configure
-
Print Debugging
print(f"Debug: {value}")
-
Logging
import logging logging.debug("Debug message")
- Create component in
src/pages/NewPage.tsx - Add route in
src/App.tsx:<Route path="/new-page" element={<NewPage />} />
- Add navigation link
-
Add function in
src-tauri/src/lib.rs:#[tauri::command] fn my_command() -> Result<String, String> { Ok("Success".to_string()) }
-
Register in
src-tauri/src/main.rs:.invoke_handler(tauri::generate_handler![my_command])
-
Call from frontend:
import { invoke } from '@tauri-apps/api/core'; const result = await invoke('my_command');
# Node.js dependencies
npm update
# Check for outdated packages
npm outdated
# Rust dependencies
cd src-tauri
cargo update
# Python dependencies
pip install --upgrade -r sidecar/requirements.txt