|
| 1 | +# Wave Terminal - High Level Architecture Overview |
| 2 | + |
| 3 | +## Project Description |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +## Top-Level Directory Structure |
| 8 | + |
| 9 | +``` |
| 10 | +waveterm/ |
| 11 | +├── emain/ # Electron main process code |
| 12 | +├── frontend/ # React application (renderer process) |
| 13 | +├── cmd/ # Go command-line applications |
| 14 | +├── pkg/ # Go packages/modules |
| 15 | +├── db/ # Database migrations |
| 16 | +├── docs/ # Documentation (Docusaurus) |
| 17 | +├── build/ # Build configuration and assets |
| 18 | +├── assets/ # Application assets (icons, images) |
| 19 | +├── public/ # Static public assets |
| 20 | +├── tests/ # Test files |
| 21 | +├── .github/ # GitHub workflows and configuration |
| 22 | +└── Configuration files (package.json, tsconfig.json, etc.) |
| 23 | +``` |
| 24 | + |
| 25 | +## Architecture Components |
| 26 | + |
| 27 | +### 1. Electron Main Process (`emain/`) |
| 28 | + |
| 29 | +The Electron main process handles the native desktop application layer: |
| 30 | + |
| 31 | +**Key Files:** |
| 32 | + |
| 33 | +- [`emain.ts`](emain/emain.ts) - Main entry point, application lifecycle management |
| 34 | +- [`emain-window.ts`](emain/emain-window.ts) - Window management (`WaveBrowserWindow` class) |
| 35 | +- [`emain-tabview.ts`](emain/emain-tabview.ts) - Tab view management (`WaveTabView` class) |
| 36 | +- [`emain-wavesrv.ts`](emain/emain-wavesrv.ts) - Go backend server integration |
| 37 | +- [`emain-wsh.ts`](emain/emain-wsh.ts) - WSH (Wave Shell) client integration |
| 38 | +- [`emain-ipc.ts`](emain/emain-ipc.ts) - IPC handlers for frontend ↔ main process communication |
| 39 | +- [`emain-menu.ts`](emain/emain-menu.ts) - Application menu system |
| 40 | +- [`updater.ts`](emain/updater.ts) - Auto-update functionality |
| 41 | +- [`preload.ts`](emain/preload.ts) - Preload script for renderer security |
| 42 | +- [`preload-webview.ts`](emain/preload-webview.ts) - Webview preload script |
| 43 | + |
| 44 | +### 2. Frontend React Application (`frontend/`) |
| 45 | + |
| 46 | +The React application runs in the Electron renderer process: |
| 47 | + |
| 48 | +**Structure:** |
| 49 | + |
| 50 | +``` |
| 51 | +frontend/ |
| 52 | +├── app/ # Main application code |
| 53 | +│ ├── app.tsx # Root App component |
| 54 | +│ ├── aipanel/ # AI panel UI |
| 55 | +│ ├── block/ # Block-based UI components |
| 56 | +│ ├── element/ # Reusable UI elements |
| 57 | +│ ├── hook/ # Custom React hooks |
| 58 | +│ ├── modals/ # Modal components |
| 59 | +│ ├── store/ # State management (Jotai) |
| 60 | +│ ├── tab/ # Tab components |
| 61 | +│ ├── view/ # Different view types |
| 62 | +│ │ ├── codeeditor/ # Code editor (Monaco) |
| 63 | +│ │ ├── preview/ # File preview |
| 64 | +│ │ ├── sysinfo/ # System info view |
| 65 | +│ │ ├── term/ # Terminal view |
| 66 | +│ │ ├── tsunami/ # Tsunami builder view |
| 67 | +│ │ ├── vdom/ # Virtual DOM view |
| 68 | +│ │ ├── waveai/ # AI chat integration |
| 69 | +│ │ ├── waveconfig/ # Config editor view |
| 70 | +│ │ └── webview/ # Web view |
| 71 | +│ └── workspace/ # Workspace management |
| 72 | +├── builder/ # Builder app entry |
| 73 | +├── layout/ # Layout system |
| 74 | +├── preview/ # Standalone preview renderer |
| 75 | +├── types/ # TypeScript type definitions |
| 76 | +└── util/ # Utility functions |
| 77 | +``` |
| 78 | + |
| 79 | +**Key Technologies:** |
| 80 | + |
| 81 | +- Electron (desktop application shell) |
| 82 | +- React 19 with TypeScript |
| 83 | +- Jotai for state management |
| 84 | +- Monaco Editor for code editing |
| 85 | +- XTerm.js for terminal emulation |
| 86 | +- Tailwind CSS v4 for styling |
| 87 | +- SCSS for additional styling (deprecated, new components should use Tailwind) |
| 88 | +- Vite / electron-vite for bundling |
| 89 | +- Task (Taskfile.yml) for build and code generation commands |
| 90 | + |
| 91 | +### 3. Go Backend Server (`cmd/server/`) |
| 92 | + |
| 93 | +The Go backend server handles all heavy lifting operations: |
| 94 | + |
| 95 | +**Entry Point:** [`main-server.go`](cmd/server/main-server.go) |
| 96 | + |
| 97 | +### 4. Go Packages (`pkg/`) |
| 98 | + |
| 99 | +The Go codebase is organized into modular packages: |
| 100 | + |
| 101 | +**Key Packages:** |
| 102 | + |
| 103 | +- `wstore/` - Database and storage layer |
| 104 | +- `wconfig/` - Configuration management |
| 105 | +- `wcore/` - Core business logic |
| 106 | +- `wshrpc/` - RPC communication system |
| 107 | +- `wshutil/` - WSH (Wave Shell) utilities |
| 108 | +- `blockcontroller/` - Block execution management |
| 109 | +- `remote/` - Remote connection handling |
| 110 | +- `filestore/` - File storage system |
| 111 | +- `web/` - Web server and WebSocket handling |
| 112 | +- `telemetry/` - Usage analytics and telemetry |
| 113 | +- `waveobj/` - Core data objects |
| 114 | +- `service/` - Service layer |
| 115 | +- `wps/` - Wave PubSub event system |
| 116 | +- `waveai/` - AI functionality |
| 117 | +- `shellexec/` - Shell execution |
| 118 | +- `util/` - Common utilities |
| 119 | + |
| 120 | +### 5. Command Line Tools (`cmd/`) |
| 121 | + |
| 122 | +Key Go command-line utilities: |
| 123 | + |
| 124 | +- `wsh/` - Wave Shell command-line tool |
| 125 | +- `server/` - Main backend server |
| 126 | +- `generatego/` - Code generation |
| 127 | +- `generateschema/` - Schema generation |
| 128 | +- `generatets/` - TypeScript generation |
| 129 | + |
| 130 | +## Communication Architecture |
| 131 | + |
| 132 | +The core communication system is built around the **WSH RPC (Wave Shell RPC)** system, which provides a unified interface for all inter-process communication: frontend ↔ Go backend, Electron main process ↔ backend, and backend ↔ remote systems (SSH, WSL). |
| 133 | + |
| 134 | +### WSH RPC System (`pkg/wshrpc/`) |
| 135 | + |
| 136 | +The WSH RPC system is the backbone of Wave Terminal's communication architecture: |
| 137 | + |
| 138 | +**Key Components:** |
| 139 | + |
| 140 | +- [`wshrpctypes.go`](pkg/wshrpc/wshrpctypes.go) - Core RPC interface and type definitions (source of truth for all RPC commands) |
| 141 | +- [`wshserver/`](pkg/wshrpc/wshserver/) - Server-side RPC implementation |
| 142 | +- [`wshremote/`](pkg/wshrpc/wshremote/) - Remote connection handling |
| 143 | +- [`wshclient.go`](pkg/wshrpc/wshclient.go) - Go client for making RPC calls |
| 144 | +- [`frontend/app/store/wshclientapi.ts`](frontend/app/store/wshclientapi.ts) - Generated TypeScript RPC client |
| 145 | + |
| 146 | +**Routing:** Callers address RPC calls using _routes_ (e.g. a block ID, connection name, or `"waveapp"`) rather than caring about the underlying transport. The RPC layer resolves the route to the correct transport (WebSocket, Unix socket, SSH tunnel, stdio) automatically. This means the same RPC interface works whether the target is local or a remote SSH connection. |
| 147 | + |
| 148 | +## Development Notes |
| 149 | + |
| 150 | +- **Build commands** - Use `task` (Taskfile.yml) for all build, generate, and packaging commands |
| 151 | +- **Code generation** - Run `task generate` after modifying Go types in `pkg/wshrpc/wshrpctypes.go`, `pkg/wconfig/settingsconfig.go`, or `pkg/waveobj/wtypemeta.go` |
| 152 | +- **Testing** - Vitest for frontend unit tests; standard `go test` for Go packages |
| 153 | +- **Database migrations** - SQL migration files in `db/migrations-wstore/` and `db/migrations-filestore/` |
| 154 | +- **Documentation** - Docusaurus site in `docs/` |
0 commit comments