How amalshaji/dbcooper works
Purpose and Runtime
DBcooper is a native desktop database client for PostgreSQL, SQLite, Redis, and ClickHouse. It runs a React/TypeScript renderer in a Tauri v2 shell, with Rust owning privileged operations, local persistence, database connectivity, SSH tunneling, and AI-provider integration. Primary entry points are src/main.tsx, src/App.tsx, src-tauri/src/main.rs, and src-tauri/src/lib.rs.
Desktop Boundary and Command Surface
The renderer invokes Tauri commands rather than accessing databases or local secrets directly. Rust command modules expose connection lifecycle, schema/data operations, query execution, settings, pools, PostgreSQL-specific operations, and AI actions:
• src-tauri/src/commands/mod.rs
• src-tauri/src/commands/database.rs
• src-tauri/src/commands/queries.rs
• src-tauri/src/commands/ai.rs
The frontend-side invocation boundary is centralized in src/lib/tauri.ts.
Connection and Local State Management
Saved connections, settings, SSH tunnel configuration, database type metadata, query history, and AI-provider settings are persisted in an application-local SQLite database. The schema evolves through ordered SQL migrations:
• src-tauri/migrations/001_initial.sql
• src-tauri/migrations/003_ssh_tunnel.sql
• src-tauri/migrations/006_ai_provider.sql
Rust models and persistence access are organized under src-tauri/src/db/models.rs and src-tauri/src/db/mod.rs. This local store is distinct from user-connected databases.
Multi-Database Adapter Layer
A common database layer dispatches operations to engine-specific adapters for PostgreSQL, SQLite, Redis, and ClickHouse. Query generation/execution has a further per-engine split, allowing differences in SQL dialects and Redis semantics to remain behind Rust interfaces:
• src-tauri/src/database/mod.rs
• src-tauri/src/database/postgres.rs
• src-tauri/src/database/redis.rs
• src-tauri/src/database/queries/mod.rs
Connection pools are managed centrally in src-tauri/src/database/pool_manager.rs; SSH access is handled separately by src-tauri/src/ssh_tunnel.rs, forming the network boundary before database connections are opened.
Renderer Application and Database Workspace
The React app is organized around connections, connection-detail workspaces, settings, and tabs. src/pages/Connections.tsx is the connection-management view, while src/pages/ConnectionDetails.tsx hosts the active database exploration/query workflow. src/App.tsx coordinates application-level routing/layout.
Within a connected workspace, object/schema exploration feeds table data views, filtering, row editing/insertion, Redis-key views, and query results:
• src/components/connection-details/ObjectExplorer.tsx
• src/components/DataTable.tsx
• src/components/SqlEditor.tsx
• src/components/QueryResultSheet.tsx
Query Safety, Editing, and Result Flow
Users select database objects, inspect schema, compose SQL, and execute through Tauri commands. Frontend logic supports SQL parsing, safety checks, filtering, and type-aware field inputs before mutations are sent to Rust:
• src/lib/sqlSafety.ts
• src/lib/sqlParser.ts
• src/components/RowEditSheet.tsx
• src/components/connection-details/TableFilterBar.tsx
The backend executes against the selected adapter/pool and returns results for renderer presentation. This keeps credentials, networking, and raw database drivers outside the browser-like renderer.
AI SQL Generation and Delivery
AI generation combines user instructions, current editor SQL, and selected table/column metadata. The frontend manages draft/session/selection state and previews generated SQL before execution:
• src/hooks/useAIGeneration.ts
• src/lib/aiGenerationSession.ts
• src/components/SqlAIPreview.tsx
Rust constructs prompts and routes requests to either OpenAI-compatible endpoints or local CLI-backed providers (Claude Code, Codex CLI, opencode):
• src-tauri/src/ai/prompts.rs
• src-tauri/src/ai/providers/openai.rs
• src-tauri/src/ai/providers/harness.rs
Production builds target macOS Apple Silicon via Tauri configuration in src-tauri/tauri.conf.json; GitHub Actions publish signed updater artifacts through .github/workflows/publish.yml.
Main entry points: ConnectionDetails.tsx Connection workspace · tauri.ts Tauri invocation bridge · mod.rs Database command surface · App.tsx App shell
Components 23
React renderer
Browser-like UI with no direct database or secret access.
- Renderer entry
src/main.tsx - App shell
src/App.tsx - Connections view
src/pages/Connections.tsx - Connection workspace · Hosts exploration, editing, and query work for an active connection.
src/pages/ConnectionDetails.tsx - Object explorer
src/components/connection-details/ObjectExplorer.tsx - SQL editor & results
src/components/SqlEditor.tsx - Table data & editing · Includes filtering and row mutation inputs.
src/components/DataTable.tsx - SQL safety & parsing
src/lib/sqlSafety.ts - Tauri invocation bridge
src/lib/tauri.ts
Tauri / Rust backend
Privileged desktop operations and database runtime.
- Tauri application
src-tauri/src/lib.rs - Database command surface · Connection lifecycle, schema/data, query, settings, and pool operations.
src-tauri/src/commands/mod.rs - Application-local SQLite · Stores saved connections, settings, history, tunnels, and AI settings.
src-tauri/src/db/mod.rs - SQLite migrations
src-tauri/migrations/001_initial.sql - Connection pool manager
src-tauri/src/database/pool_manager.rs - SSH tunnel
src-tauri/src/ssh_tunnel.rs - Database adapter layer · Routes common operations to PostgreSQL, SQLite, Redis, and ClickHouse adapters.
src-tauri/src/database/mod.rs - Per-engine query execution · Contains dialect-specific SQL and Redis query semantics.
src-tauri/src/database/queries/mod.rs
AI generation
SQL generation flow across renderer and Rust providers.
- AI SQL session & preview · Combines instruction, editor SQL, and selected schema before execution.
src/hooks/useAIGeneration.ts - AI commands
src-tauri/src/commands/ai.rs - Prompt builder
src-tauri/src/ai/prompts.rs - AI provider routing · Routes to OpenAI-compatible endpoints or local Claude Code, Codex, and opencode CLIs.
src-tauri/src/ai/providers/harness.rs
Other components
- Connected databases · User-selected remote or local database targets.
- AI endpoints & local CLIs
Connections 24
- Renderer entry → App shell: mounts
- App shell → Connections view: shows
- App shell → Connection workspace: opens
- Connection workspace → Object explorer: browses objects
- Connection workspace → SQL editor & results: composes queries
- Connection workspace → Table data & editing: inspects and edits
- SQL editor & results → SQL safety & parsing: validates SQL
- Connections view → Tauri invocation bridge: manages connections
- Connection workspace → Tauri invocation bridge: loads data and mutates
- Tauri invocation bridge → Database command surface: invokes
- Tauri application → Database command surface: registers
- Database command surface → Application-local SQLite: reads and writes state
- SQLite migrations → Application-local SQLite: evolves schema
- Database command surface → Connection pool manager: acquires pools
- Connection pool manager → Database adapter layer: provides connections
- Database adapter layer → Per-engine query execution: dispatches operations
- SSH tunnel → Connection pool manager: secures network path
- Database adapter layer → Connected databases: connects and executes
- AI SQL session & preview → Tauri invocation bridge: requests generation
- Tauri invocation bridge → AI commands: invokes AI actions
- AI commands → Prompt builder: builds contextual prompt
- Prompt builder → AI provider routing: routes request
- AI provider routing → AI endpoints & local CLIs: generates SQL
- AI SQL session & preview → SQL editor & results: previews generated SQL