# stefanhoelzl/codehydra architecture

> Architecture diagram of the GitHub repository stefanhoelzl/codehydra, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stefanhoelzl/codehydra
- Repository: https://github.com/stefanhoelzl/codehydra

## Overview

#### Purpose and Runtime
CodeHydra is a cross-platform Electron desktop IDE for running Claude Code or OpenCode concurrently in isolated Git worktrees. It embeds a VSCodium editor per workspace, monitors agent state, and exposes workspace/editor control through MCP. Electron/Vite and Svelte are the principal runtime stack: `src/main.ts`, `electron.vite.config.ts`, `src/renderer/main.ts`.

#### Process Entry and IPC Boundary
Electron main bootstraps application lifecycle, module wiring, and intent dispatch; preload exposes a constrained API to the renderer. Shared IPC/API contracts prevent renderer code from directly accessing Node/Electron services. Key paths: `src/main.ts`, `src/preload/index.ts`, `src/shared/api/interfaces.ts`.

#### Intent-Oriented Application Core
User, MCP, and lifecycle requests are modeled as intents dispatched through a common operation framework. Intents resolve projects/workspaces, enforce workspace identity/idempotency, then coordinate modules rather than owning platform details. Primary lifecycle paths include `src/intents/lib/dispatcher.ts`, `src/intents/open-workspace.ts`, `src/intents/delete-workspace.ts`.

#### Workspace and Project Lifecycle
A project is a local or cloned Git repository; a workspace is a branch-specific Git worktree. Creation, selection, switching, hibernation, metadata, and status are composed from modules and platform Git/filesystem boundaries. Worktrees remain on disk during hibernation. Key paths: `src/modules/git-worktree-workspace-module.ts`, `src/modules/local-project-module.ts`, `src/boundaries/platform/git-worktree-provider.ts`.

#### Agent Abstraction and Servers
The agent module selects a global or per-workspace provider and normalizes lifecycle/status behavior across Claude and OpenCode. Provider-specific wrappers/server managers launch and manage external agent processes; OpenCode has an SDK client, while Claude manages hooks/MCP configuration. Key paths: `src/modules/agent-module/agent-module.ts`, `src/modules/agent-module/claude/server-manager.ts`, `src/modules/agent-module/opencode/server-manager.ts`.

#### IDE Views and Renderer
Each active workspace maps to a managed VSCodium/IDE-server view, while Svelte renders workspace frames, sidebar, dialogs, notifications, and shortcut state. The renderer invokes the preload API and consumes domain events; it does not own workspace process management. Key paths: `src/modules/ide-server-module/ide-server-module.ts`, `src/renderer/lib/components/WorkspaceFrames.svelte`, `src/renderer/lib/api/index.ts`.

#### External Integration and Infrastructure
Platform boundaries isolate Electron shell APIs, process execution, filesystem, ports, networking, Git, persisted state, logging, and telemetry. MCP turns internal intents into agent-accessible tools; agents can invoke VS Code commands through the app. External systems include Git/GitHub, YouTrack, Claude Code, OpenCode, VSCodium, and PostHog. Key paths: `src/modules/mcp-module.ts`, `src/boundaries/platform/process.ts`, `src/boundaries/platform/posthog.ts`.

#### Distribution and Extensions
Electron Builder packages platform binaries and bundled agent/editor launchers. Companion VS Code extensions are separately built, notably a Markdown review editor with Svelte webview UI and OpenCode integration. Node and Python packages are thin launch/distribution surfaces. Key paths: `electron-builder.yaml`, `extensions/markdown-review-editor/src/extension/extension.ts`, `packages/npm/codehydra.js`.

Main entry points: [`src/intents/open-workspace.ts`](https://github.com/stefanhoelzl/codehydra/blob/main/src/intents/open-workspace.ts) (Workspace lifecycle intents), [`src/main.ts`](https://github.com/stefanhoelzl/codehydra/blob/main/src/main.ts) (Electron main), [`src/intents/lib/dispatcher.ts`](https://github.com/stefanhoelzl/codehydra/blob/main/src/intents/lib/dispatcher.ts) (Intent dispatcher), [`src/boundaries/platform/process.ts`](https://github.com/stefanhoelzl/codehydra/blob/main/src/boundaries/platform/process.ts) (Process boundary)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Electron Desktop"]
  node_electron_main["Electron main<br/>bootstrap<br/>[main.ts]"]
  node_preload["Preload API<br/>ipc bridge<br/>[index.ts]"]
  node_renderer["Svelte renderer<br/>ui runtime<br/>[main.ts]"]
  node_renderer_api["Renderer API client<br/>ipc client<br/>[index.ts]"]
  node_workspace_frames["Workspace frames<br/>Svelte component"]
end

subgraph group_core["Application Core"]
  node_contracts["Shared API contracts<br/>IPC contracts<br/>[interfaces.ts]"]
  node_intent_dispatcher{{"Intent dispatcher<br/>operation framework<br/>[dispatcher.ts]"}}
  node_workspace_intents["Workspace lifecycle intents<br/>intent handlers<br/>[open-workspace.ts]"]
  node_project_module["Project module<br/>project lifecycle"]
  node_worktree_module["Git worktree workspace module<br/>workspace lifecycle"]
  node_git_provider["Git worktree provider<br/>platform boundary"]
end

subgraph group_runtime["Workspace Runtimes"]
  node_agent_module["Agent module<br/>agent abstraction<br/>[agent-module.ts]"]
  node_claude_manager["Claude server manager<br/>agent provider<br/>[server-manager.ts]"]
  node_opencode_manager["OpenCode server manager<br/>agent provider<br/>[server-manager.ts]"]
  node_ide_module["IDE server module<br/>IDE view manager"]
end

subgraph group_external["External Integrations"]
  node_mcp_module{{"MCP module<br/>tool server<br/>[mcp-module.ts]"}}
  node_platform_process["Process boundary<br/>platform boundary<br/>[process.ts]"]
  node_telemetry["PostHog boundary<br/>telemetry boundary<br/>[posthog.ts]"]
  node_external_tools(("Git, agents &amp; VSCodium<br/>external systems"))
end

subgraph group_distribution["Distribution &amp; Extensions"]
  node_builder["Electron Builder<br/>packaging"]
  node_markdown_extension["Markdown review extension<br/>VS Code extension<br/>[extension.ts]"]
  node_npm_launcher["npm launcher<br/>distribution surface<br/>[codehydra.js]"]
end

node_electron_main -->|"creates IPC boundary"| node_preload
node_preload -->|"implements"| node_contracts
node_renderer -->|"uses"| node_renderer_api
node_renderer_api -->|"invokes"| node_preload
node_renderer -->|"renders"| node_workspace_frames
node_electron_main -->|"dispatches"| node_intent_dispatcher
node_contracts -.->|"contracts"| node_intent_dispatcher
node_intent_dispatcher -->|"routes"| node_workspace_intents
node_workspace_intents -->|"resolves project"| node_project_module
node_workspace_intents -->|"coordinates"| node_worktree_module
node_worktree_module -->|"uses"| node_git_provider
node_git_provider -->|"Git operations"| node_external_tools
node_workspace_intents -->|"starts and monitors"| node_agent_module
node_workspace_intents -->|"opens workspace view"| node_ide_module
node_agent_module -->|"selects"| node_claude_manager
node_agent_module -->|"selects"| node_opencode_manager
node_claude_manager -->|"launches via"| node_platform_process
node_opencode_manager -->|"launches via"| node_platform_process
node_ide_module -->|"launches via"| node_platform_process
node_platform_process -->|"runs"| node_external_tools
node_mcp_module -->|"turns tools into intents"| node_intent_dispatcher
node_mcp_module -->|"invokes editor commands"| node_ide_module
node_electron_main -.->|"reports through"| node_telemetry
node_builder -->|"packages"| node_electron_main
node_npm_launcher -.->|"distributes"| node_builder
node_markdown_extension -->|"integrates OpenCode"| node_external_tools

click node_electron_main "https://github.com/stefanhoelzl/codehydra/blob/main/src/main.ts"
click node_preload "https://github.com/stefanhoelzl/codehydra/blob/main/src/preload/index.ts"
click node_renderer "https://github.com/stefanhoelzl/codehydra/blob/main/src/renderer/main.ts"
click node_renderer_api "https://github.com/stefanhoelzl/codehydra/blob/main/src/renderer/lib/api/index.ts"
click node_workspace_frames "https://github.com/stefanhoelzl/codehydra/blob/main/src/renderer/lib/components/WorkspaceFrames.svelte"
click node_contracts "https://github.com/stefanhoelzl/codehydra/blob/main/src/shared/api/interfaces.ts"
click node_intent_dispatcher "https://github.com/stefanhoelzl/codehydra/blob/main/src/intents/lib/dispatcher.ts"
click node_workspace_intents "https://github.com/stefanhoelzl/codehydra/blob/main/src/intents/open-workspace.ts"
click node_project_module "https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/local-project-module.ts"
click node_worktree_module "https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/git-worktree-workspace-module.ts"
click node_git_provider "https://github.com/stefanhoelzl/codehydra/blob/main/src/boundaries/platform/git-worktree-provider.ts"
click node_agent_module "https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/agent-module/agent-module.ts"
click node_claude_manager "https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/agent-module/claude/server-manager.ts"
click node_opencode_manager "https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/agent-module/opencode/server-manager.ts"
click node_ide_module "https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/ide-server-module/ide-server-module.ts"
click node_mcp_module "https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/mcp-module.ts"
click node_platform_process "https://github.com/stefanhoelzl/codehydra/blob/main/src/boundaries/platform/process.ts"
click node_telemetry "https://github.com/stefanhoelzl/codehydra/blob/main/src/boundaries/platform/posthog.ts"
click node_builder "https://github.com/stefanhoelzl/codehydra/blob/main/electron-builder.yaml"
click node_markdown_extension "https://github.com/stefanhoelzl/codehydra/blob/main/extensions/markdown-review-editor/src/extension/extension.ts"
click node_npm_launcher "https://github.com/stefanhoelzl/codehydra/blob/main/packages/npm/codehydra.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_electron_main,node_preload,node_renderer,node_renderer_api,node_workspace_frames toneBlue
class node_contracts,node_intent_dispatcher,node_workspace_intents,node_project_module,node_worktree_module,node_git_provider toneAmber
class node_agent_module,node_claude_manager,node_opencode_manager,node_ide_module toneMint
class node_mcp_module,node_platform_process,node_telemetry,node_external_tools toneRose
class node_builder,node_markdown_extension,node_npm_launcher toneIndigo
```

## Components

### Electron Desktop

- [Electron main](https://github.com/stefanhoelzl/codehydra/blob/main/src/main.ts): bootstrap · Owns lifecycle, module wiring, and intent dispatch. · `src/main.ts`
- [Preload API](https://github.com/stefanhoelzl/codehydra/blob/main/src/preload/index.ts): ipc bridge · Exposes constrained renderer capabilities. · `src/preload/index.ts`
- [Svelte renderer](https://github.com/stefanhoelzl/codehydra/blob/main/src/renderer/main.ts): ui runtime · Renders workspace UI and consumes domain events. · `src/renderer/main.ts`
- [Renderer API client](https://github.com/stefanhoelzl/codehydra/blob/main/src/renderer/lib/api/index.ts): ipc client · `src/renderer/lib/api/index.ts`
- [Workspace frames](https://github.com/stefanhoelzl/codehydra/blob/main/src/renderer/lib/components/WorkspaceFrames.svelte): Svelte component · Hosts active IDE workspace views. · `src/renderer/lib/components/WorkspaceFrames.svelte`

### Application Core

- [Shared API contracts](https://github.com/stefanhoelzl/codehydra/blob/main/src/shared/api/interfaces.ts): IPC contracts · Defines the main-to-renderer API boundary. · `src/shared/api/interfaces.ts`
- [Intent dispatcher](https://github.com/stefanhoelzl/codehydra/blob/main/src/intents/lib/dispatcher.ts): operation framework · Routes lifecycle, user, and MCP requests. · `src/intents/lib/dispatcher.ts`
- [Workspace lifecycle intents](https://github.com/stefanhoelzl/codehydra/blob/main/src/intents/open-workspace.ts): intent handlers · Open and delete operations resolve workspace identity. · `src/intents/open-workspace.ts`
- [Project module](https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/local-project-module.ts): project lifecycle · Manages local and cloned Git repositories. · `src/modules/local-project-module.ts`
- [Git worktree workspace module](https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/git-worktree-workspace-module.ts): workspace lifecycle · Creates, switches, hibernates, and tracks workspaces. · `src/modules/git-worktree-workspace-module.ts`
- [Git worktree provider](https://github.com/stefanhoelzl/codehydra/blob/main/src/boundaries/platform/git-worktree-provider.ts): platform boundary · Performs Git worktree operations. · `src/boundaries/platform/git-worktree-provider.ts`

### Workspace Runtimes

- [Agent module](https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/agent-module/agent-module.ts): agent abstraction · Selects and normalizes global or workspace agents. · `src/modules/agent-module/agent-module.ts`
- [Claude server manager](https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/agent-module/claude/server-manager.ts): agent provider · Manages Claude hooks, MCP configuration, and processes. · `src/modules/agent-module/claude/server-manager.ts`
- [OpenCode server manager](https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/agent-module/opencode/server-manager.ts): agent provider · Manages OpenCode server and SDK client. · `src/modules/agent-module/opencode/server-manager.ts`
- [IDE server module](https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/ide-server-module/ide-server-module.ts): IDE view manager · Maps active workspaces to VSCodium views. · `src/modules/ide-server-module/ide-server-module.ts`

### External Integrations

- [MCP module](https://github.com/stefanhoelzl/codehydra/blob/main/src/modules/mcp-module.ts): tool server · Exposes intents and editor control to agents. · `src/modules/mcp-module.ts`
- [Process boundary](https://github.com/stefanhoelzl/codehydra/blob/main/src/boundaries/platform/process.ts): platform boundary · Launches external agent and editor processes. · `src/boundaries/platform/process.ts`
- [PostHog boundary](https://github.com/stefanhoelzl/codehydra/blob/main/src/boundaries/platform/posthog.ts): telemetry boundary · `src/boundaries/platform/posthog.ts`
- **Git, agents & VSCodium**: external systems · Git/GitHub, Claude Code, OpenCode, and VSCodium.

### Distribution & Extensions

- [Electron Builder](https://github.com/stefanhoelzl/codehydra/blob/main/electron-builder.yaml): packaging · Packages platform binaries and bundled launchers. · `electron-builder.yaml`
- [Markdown review extension](https://github.com/stefanhoelzl/codehydra/blob/main/extensions/markdown-review-editor/src/extension/extension.ts): VS Code extension · Companion extension with Svelte webview and OpenCode integration. · `extensions/markdown-review-editor/src/extension/extension.ts`
- [npm launcher](https://github.com/stefanhoelzl/codehydra/blob/main/packages/npm/codehydra.js): distribution surface · `packages/npm/codehydra.js`

## Connections

- Electron main → Preload API: creates IPC boundary
- Preload API → Shared API contracts: implements
- Svelte renderer → Renderer API client: uses
- Renderer API client → Preload API: invokes
- Svelte renderer → Workspace frames: renders
- Electron main → Intent dispatcher: dispatches
- Shared API contracts → Intent dispatcher: contracts
- Intent dispatcher → Workspace lifecycle intents: routes
- Workspace lifecycle intents → Project module: resolves project
- Workspace lifecycle intents → Git worktree workspace module: coordinates
- Git worktree workspace module → Git worktree provider: uses
- Git worktree provider → Git, agents & VSCodium: Git operations
- Workspace lifecycle intents → Agent module: starts and monitors
- Workspace lifecycle intents → IDE server module: opens workspace view
- Agent module → Claude server manager: selects
- Agent module → OpenCode server manager: selects
- Claude server manager → Process boundary: launches via
- OpenCode server manager → Process boundary: launches via
- IDE server module → Process boundary: launches via
- Process boundary → Git, agents & VSCodium: runs
- MCP module → Intent dispatcher: turns tools into intents
- MCP module → IDE server module: invokes editor commands
- Electron main → PostHog boundary: reports through
- Electron Builder → Electron main: packages
- npm launcher → Electron Builder: distributes
- Markdown review extension → Git, agents & VSCodium: integrates OpenCode
