Architecture: Desktop Application
Relevant source files
The following files were used as context for generating this wiki page:The OpenCode desktop application is built using the Tauri framework, which enables the creation of cross-platform desktop applications using web technologies for the frontend and a Rust-based backend. This architecture provides native performance and a secure environment by leveraging the operating system's web renderer.
Based on the source files, the desktop application is currently in a foundational, placeholder stage, with the core structure in place for future development. The web console explicitly states that the desktop app is "coming soon" and that the team is "actively working on a desktop app".
Sources: packages/console/app/src/routes/index.tsx:92, packages/console/app/src/routes/index.tsx:245, packages/tauri/src-tauri/tauri.conf.json
High-Level Architecture
The application follows a standard Tauri architecture, separating the user interface (frontend) from the core logic (backend).
- Frontend: A React-based single-page application responsible for rendering the user interface within a Tauri-managed WebView.
- Backend: A Rust binary that manages the application window, handles system interactions, and exposes an API to the frontend.
- Tauri API: The bridge that facilitates secure communication between the frontend (JavaScript/TypeScript) and the backend (Rust).
The following diagram illustrates the main components and their interactions.
This diagram shows the relationship between the React frontend, the Rust backend, and the underlying OS through the Tauri framework.
Sources: packages/desktop/src/index.tsx, packages/tauri/src-tauri/src/main.rs, packages/tauri/src-tauri/tauri.conf.json
Backend (Rust Core)
The backend is implemented in Rust and serves as the entry point for the desktop application. Its primary responsibility is to initialize and run the Tauri application.
Sources: packages/tauri/src-tauri/src/main.rs
Startup Process
The main function in packages/tauri/src-tauri/src/main.rs is the application's entry point. It uses the tauri::Builder to construct and launch the application with the configuration defined in tauri.conf.json.
// packages/tauri/src-tauri/src/main.rs:4-8
fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
The startup flow is minimal, reflecting the application's early stage of development.
This flowchart shows the sequence of events when the Rust backend starts.
Sources: packages/tauri/src-tauri/src/main.rs:4-8
Currently, the backend does not define any custom commands or state management; it only serves to launch the frontend in a window.
Frontend (Web View)
The frontend is a React application, as indicated by the use of React and ReactDOM in packages/desktop/src/index.tsx. It is responsible for the entire user interface.
// packages/desktop/src/index.tsx:1-7
import React from "react"
import ReactDOM from "react-dom/client"
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<div>Hello from the desktop app!</div>
</React.StrictMode>,
)
At present, the UI is a simple placeholder, displaying a "Hello from the desktop app!" message. This code runs inside a secure WebView managed by the Rust backend.
Sources: packages/desktop/src/index.tsx
Configuration and Security
The application's behavior, appearance, and security policies are defined in tauri.conf.json.
Sources: packages/tauri/src-tauri/tauri.conf.json
Key Configuration
The following table summarizes important settings from the configuration file.
| Key Path | Value | Description |
|---|---|---|
package.productName | "opencode" | The display name of the application. |
package.version | "0.0.0" | The initial version number. |
build.devPath | "http://localhost:1420" | The URL for the frontend development server, enabling hot-reloading. |
build.distDir | "../dist" | The relative path to the production-ready frontend assets. |
tauri.windows[0].title | "opencode" | The default title for the main application window. |
tauri.bundle.identifier | "com.tauri.dev" | A placeholder unique application identifier for packaging. |
Sources: packages/tauri/src-tauri/tauri.conf.json
API Allowlist
Tauri enforces a strict security model by requiring explicit permission for the frontend to access native OS features. The allowlist configuration is currently very restrictive, only enabling a single API.
// packages/tauri/src-tauri/tauri.conf.json:17-21
"allowlist": {
"all": false,
"shell": {
"all": false,
"open": true
}
}
This configuration means:
- By default, no APIs are enabled (
"all": false). - The only permitted action is
shell.open, which allows the frontend to open external URLs or files in the user's default browser or application. All other shell commands are disabled.
Sources: packages/tauri/src-tauri/tauri.conf.json:17-21
Development and Build Process
The project is set up for a typical Tauri development workflow that separates the frontend and backend.
- Development: A local dev server (e.g., Vite) serves the frontend on
http://localhost:1420. The Tauri app loads this URL, allowing for hot-reloading of the UI. - Production Build: The frontend code is built into static assets and placed in the
../distdirectory. The Rust backend is compiled, and the Tauri bundler packages the Rust binary and the static frontend assets together into a single, distributable application file for the target OS.
The following diagram outlines the build process.
This diagram shows how the frontend and backend are compiled and bundled into a final application.
Sources: packages/tauri/src-tauri/tauri.conf.json:12-15, CONTRIBUTING.md
Summary
The OpenCode desktop application uses a modern and secure architecture based on Tauri, Rust, and React. While currently in a placeholder state, the foundational structure is in place. This setup allows for the development of a high-performance, cross-platform application with a clean separation between the UI and core logic, ensuring both security and a native feel. Future development will involve implementing the full UI in React and adding custom commands in the Rust backend to handle application logic.