Overview
Emdash uses Electron’s IPC (Inter-Process Communication) to connect the main process (Node.js backend) and renderer process (React UI). All communication flows throughwindow.electronAPI, exposed via contextBridge in the preload script.
Key principles:
- Renderer has no direct access to Node.js APIs, filesystem, or native modules
- All operations go through IPC handlers in the main process
- IPC calls are async (Promise-based)
- Type safety enforced with TypeScript declarations
- Consistent response format:
{ success: boolean, data?: any, error?: string }
IPC pattern
Handler registration (main process)
All IPC handlers follow this pattern:src/main/ipc/index.ts:
main.ts during app initialization:
Preload bridge
src/main/preload.ts (~46KB, 1,400+ lines) exposes secure API to renderer:
Renderer usage
Type safety
All IPC methods must be declared insrc/renderer/types/electron-api.d.ts (~1,870 lines):
IPC handler registry
Emdash has 25+ IPC handler files covering all functionality:Core app/utility
appIpc.ts (src/main/ipc/appIpc.ts, ~800 lines)
- App version, platform info
- Font list for terminal/editor
- Undo/redo operations
- System diagnostics
src/main/ipc/settingsIpc.ts)
- User preferences (theme, fonts, behavior)
- Stored in
{userData}/settings.json
src/main/ipc/telemetryIpc.ts)
- Anonymous usage analytics (opt-in)
- PostHog integration
src/main/services/updateIpc.ts)
- Auto-update checks
- Download and install updates
- Release notes
Database
dbIpc.ts (src/main/ipc/dbIpc.ts)
- All database CRUD operations
- Projects, tasks, conversations, messages
- RPC-style interface using
createRPCRouter
Projects and tasks
projectIpc.ts (src/main/ipc/projectIpc.ts, ~200 lines)
- Project operations (create, update, delete)
- Git initialization
- Project settings
src/main/ipc/projectSettingsIpc.ts)
- Per-project configuration
- Branch prefix, preserve patterns, lifecycle scripts
- Reads/writes
.emdash.jsonat project root
Git and GitHub
gitIpc.ts (src/main/ipc/gitIpc.ts, ~3,000 lines)
- Git status, diff, commit, push, branch management
- File changes, staging
- Commit history
src/main/ipc/githubIpc.ts, ~600 lines)
- GitHub authentication via
ghCLI - PR creation, listing, status
- Check runs (CI status)
- Repository info
PTY management
ptyIpc.ts (src/main/services/ptyIpc.ts)
- PTY lifecycle (start, input, resize, kill)
- Terminal theme configuration
- Session snapshots
Worktrees
worktreeIpc.ts (src/main/services/worktreeIpc.ts)
- Create, remove, list worktrees
- Worktree pool management
- Cleanup operations
SSH remote development
sshIpc.ts (src/main/ipc/sshIpc.ts, ~1,000 lines)
- SSH connection management
- Credential storage (password, key, agent)
- Host key verification
- Remote file operations
Skills
skillsIpc.ts (src/main/ipc/skillsIpc.ts)
- Install/uninstall skills
- List available skills
- Sync to agent directories
- Agent Skills standard
Integrations
linearIpc.ts (src/main/ipc/linearIpc.ts)
- Linear issue sync
- OAuth authentication
src/main/ipc/jiraIpc.ts)
- Jira issue sync
- OAuth authentication
src/main/ipc/connectionsIpc.ts)
- Detect installed CLI agents
- Provider configuration
Filesystem
fsIpc.ts (src/main/services/fsIpc.ts)
- File reading, writing
- Directory listing
- Path resolution
- Security: All paths validated with
isPathSafe()
Request/response format
All IPC handlers follow a consistent response format:Success response
Error response
Variations
Some handlers useok instead of success (legacy PTY handlers):
Event subscription pattern
For real-time updates, handlers can emit events:Main process (emit)
Renderer (subscribe)
Preload (bridge)
Adding new IPC handlers
To add a new IPC handler:1. Create handler file
2. Register in index.ts
3. Add to preload.ts
4. Add type definition
5. Use in renderer
Security considerations
Input validation: Always validate input in handlers:Next steps
- Main process - Deep dive into services behind IPC handlers
- Renderer process - How UI consumes IPC APIs
- Architecture overview - High-level system design