12 KiB
Wave Terminal - High Level Architecture Overview
Project Description
Wave Terminal is an open-source AI-native terminal built for seamless workflows. It's an Electron application that serves as a command line terminal host (it hosts CLI applications rather than running inside a CLI). The application combines a React frontend with a Go backend server to provide a modern terminal experience with advanced features.
Top-Level Directory Structure
waveterm/
├── emain/ # Electron main process code
├── frontend/ # React application (renderer process)
├── cmd/ # Go command-line applications
├── pkg/ # Go packages/modules
├── db/ # Database migrations
├── docs/ # Documentation (Docusaurus)
├── build/ # Build configuration and assets
├── assets/ # Application assets (icons, images)
├── public/ # Static public assets
├── tests/ # Test files
├── .github/ # GitHub workflows and configuration
└── Configuration files (package.json, tsconfig.json, etc.)
Architecture Components
1. Electron Main Process (emain/)
The Electron main process handles the native desktop application layer:
Key Files:
emain.ts- Main entry point, application lifecycle managementemain-window.ts- Window management (WaveBrowserWindowclass)emain-tabview.ts- Tab view management (WaveTabViewclass)emain-wavesrv.ts- Go backend server integrationemain-wsh.ts- WSH (Wave Shell) client integrationmenu.ts- Application menu systemupdater.ts- Auto-update functionalitypreload.ts- Preload script for renderer securitypreload-webview.ts- Webview preload script
Responsibilities:
- Window and tab management
- Native OS integration
- Auto-updater
- Menu system
- Security (preload scripts)
- Communication with Go backend
2. Frontend React Application (frontend/)
The React application runs in the Electron renderer process:
Structure:
frontend/
├── app/ # Main application code
│ ├── app.tsx # Root App component
│ ├── block/ # Block-based UI components
│ ├── element/ # Reusable UI elements
│ ├── hook/ # Custom React hooks
│ ├── modals/ # Modal components
│ ├── store/ # State management (Jotai)
│ ├── view/ # Different view types
│ │ ├── chat/ # Chat interface
│ │ ├── codeeditor/ # Code editor (Monaco)
│ │ ├── term/ # Terminal view
│ │ ├── webview/ # Web view
│ │ └── waveai/ # AI integration
│ └── workspace/ # Workspace management
├── layout/ # Layout system
├── types/ # TypeScript type definitions
└── util/ # Utility functions
Key Technologies:
- React 18 with TypeScript
- Jotai for state management
- Monaco Editor for code editing
- XTerm.js for terminal emulation
- Tailwind CSS for styling
- SCSS for additional styling
3. Go Backend Server (cmd/server/)
The Go backend server handles all heavy lifting operations:
Entry Point: main-server.go
Key Responsibilities:
- Database operations
- SSH connections
- File system operations
- Networking
- Telemetry
- Configuration management
- WebSocket communication
- RPC services
4. Go Packages (pkg/)
The Go codebase is organized into modular packages:
Core Packages:
wstore/- Database and storage layerwconfig/- Configuration managementwcore/- Core business logicwshrpc/- RPC communication systemwshutil/- WSH (Wave Shell) utilitiesblockcontroller/- Block execution managementremote/- Remote connection handlingfilestore/- File storage systemweb/- Web server and WebSocket handlingtelemetry/- Usage analytics and telemetrywaveobj/- Core data objectsservice/- Service layerutil/- Common utilities
Additional Packages:
authkey/- Authenticationeventbus/- Event systemwcloud/- Cloud integrationwaveai/- AI functionalitypanichandler/- Error handlingshellexec/- Shell execution
5. Command Line Tools (cmd/)
Additional Go command-line utilities:
wsh/- Wave Shell command-line toolserver/- Main backend servergeneratego/- Code generationgenerateschema/- Schema generationgeneratets/- TypeScript generationpackfiles/- File packaging utility
6. Database Layer (db/)
Database migrations for two main stores:
migrations-wstore/- Main application databasemigrations-filestore/- File storage database
Communication Architecture
The core communication system is built around the WSH RPC (Wave Shell RPC) system, which provides a unified interface for all inter-process communication.
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Electron │ │ React │ │ Go Backend │
│ Main Process │◄──►│ Frontend │◄──►│ Server │
│ (emain/) │ │ (frontend/) │ │ (cmd/server/) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
│ WSH RPC │ WSH RPC │
▼ ▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Native OS │ │ Web APIs │ │ System APIs │
│ Integration │ │ DOM/Canvas │ │ SSH/Network │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
│ WSH RPC
▼
┌─────────────────────┐
│ Remote Systems │
│ (SSH, WSL, etc.) │
└─────────────────────┘
WSH RPC System (pkg/wshrpc/)
The WSH RPC system is the backbone of Wave Terminal's communication architecture:
Key Components:
wshrpctypes.go- Core RPC interface and type definitionswshserver/- Server-side RPC implementationwshremote/- Remote connection handlingwshclient.go- Client-side RPC implementation
Transport Flexibility:
- WebSockets - Primary transport for frontend ↔ backend communication
- Unix Domain Sockets - Local process communication
- Terminal/Stdio - Communication over terminal connections
- SSH Tunneling - Remote system communication
RPC Interface:
The WshRpcInterface defines 100+ commands including:
- File operations (
FileRead,FileWrite,FileCopy, etc.) - Block management (
CreateBlock,DeleteBlock,ControllerInput) - Remote operations (
RemoteStreamFile,RemoteFileInfo, etc.) - Connection management (
ConnStatus,ConnConnect,ConnDisconnect) - AI integration (
AiSendMessage,StreamWaveAi) - Event system (
EventPublish,EventSub,EventRecv)
Communication Flow:
- Frontend → Backend: React components call WSH RPC methods via WebSocket
- Electron → Backend: Main process uses WSH RPC for system integration
- Backend → Remote: Go server uses WSH RPC over SSH/terminal for remote operations
- WSH Binary: Command-line tool communicates with backend via same RPC system
This unified RPC system allows the wsh binary to work both locally and remotely, providing the same interface whether running on the local machine or on a remote server via SSH.
Type-Safe Code Generation
Wave Terminal uses an innovative code generation system to maintain type safety between Go and TypeScript:
Generation Process:
- Go Definitions - All RPC types and interfaces are defined in Go (
wshrpctypes.go) - TypeScript Generation -
cmd/generatets/main-generatets.goautomatically generates TypeScript bindings - Build Integration - The
generatetask inTaskfile.ymlruns code generation as part of the build process
Generated Files:
frontend/types/gotypes.d.ts- TypeScript type definitions from Go structsfrontend/app/store/services.ts- Service layer bindingsfrontend/app/store/wshclientapi.ts- RPC client API methods
Benefits:
- Type Safety - Compile-time type checking between frontend and backend
- Single Source of Truth - Go types are the authoritative definition
- Automatic Sync - Changes to Go types automatically propagate to TypeScript
- IDE Support - Full IntelliSense and autocomplete for RPC calls
This approach ensures that the frontend and backend stay in sync, preventing runtime errors from type mismatches and providing excellent developer experience with full type safety across the entire stack.
Build System
Configuration Files:
package.json- Node.js dependencies and scriptselectron.vite.config.ts- Vite build configurationtsconfig.json- TypeScript configurationelectron-builder.config.cjs- Electron packaging
Build Targets:
- Main Process - TypeScript → JavaScript (Node.js)
- Preload Scripts - TypeScript → CommonJS
- Renderer - React/TypeScript → ES6 bundle
- Go Backend - Go → Native binary
Key Features
- Terminal Emulation - XTerm.js-based terminal with modern features
- Block-based UI - Modular block system for different content types
- AI Integration - Built-in AI assistance and chat
- Code Editor - Monaco Editor integration
- Remote Connections - SSH and WSL support
- File Management - Integrated file browser and operations
- Workspace Management - Multi-workspace support
- Auto-updates - Electron-based update system
- Cross-platform - macOS, Linux, Windows support
Development Workflow
- Frontend Development - React components with hot reload
- Backend Development - Go server with live reload
- Electron Integration - Main process development
- Database Migrations - SQL migration system
- Testing - Vitest for frontend, Go testing for backend
- Documentation - Docusaurus-based docs site
This architecture provides a robust foundation for a modern terminal application, combining the best of web technologies (React, TypeScript) with native performance (Go, Electron) and system integration capabilities.