Skip to content

refactor: split main/index.ts monolith into IPC handler modules#214

Merged
github-actions[bot] merged 1 commit into
developfrom
refactor/split-main-ipc
Apr 23, 2026
Merged

refactor: split main/index.ts monolith into IPC handler modules#214
github-actions[bot] merged 1 commit into
developfrom
refactor/split-main-ipc

Conversation

@tomymaritano

@tomymaritano tomymaritano commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Splits the 3046-line monolithic main/index.ts into 10 focused handler modules.

Before

  • index.ts: 3,046 lines, 124 IPC handlers, 18 domains mixed together

After

  • index.ts: 887 lines (bootstrap + window management only)
  • 10 handler modules in handlers/ with clear domain boundaries
Module Lines Domain
noteHandlers.ts 429 notes, tags, links, embeds
notebookHandlers.ts 311 notebooks
authSyncHandlers.ts 583 auth, sync, encryption, subscription, devices
pluginHandlers.ts 410 plugin config + discovery/install
dataHandlers.ts 207 backup, export, import
gitHandlers.ts 154 git operations
updateHandlers.ts 132 auto-updater
logHandlers.ts 53 logging
aiKeyHandlers.ts 36 AI key storage
types.ts 62 shared dependency interfaces

Follows the existing pattern from licenseHandlers.ts and shareHandlers.ts.
No logic changes — purely structural.

Test plan

  • pnpm typecheck — 17/17 pass
  • pnpm test — 16/16 pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved internal architecture of the desktop application by modularizing core functionality components for better maintainability and code organization. No user-facing changes or new features included in this update.

Extract 124 IPC handlers from single 3046-line file into 10 domain
modules in apps/desktop/src/main/handlers/:

| Module              | Lines | Handlers                              |
|---------------------|-------|---------------------------------------|
| noteHandlers.ts     |   429 | notes:*, tags:*, links:*, embeds:*    |
| notebookHandlers.ts |   311 | notebooks:*                           |
| authSyncHandlers.ts |   583 | auth:*, sync:*, encryption:*, etc.    |
| pluginHandlers.ts   |   410 | pluginConfig:*, plugins:*             |
| dataHandlers.ts     |   207 | data:* (backup, export, import)       |
| gitHandlers.ts      |   154 | git:*                                 |
| updateHandlers.ts   |   132 | updates:* + auto-updater init         |
| logHandlers.ts      |    53 | log:*                                 |
| aiKeyHandlers.ts    |    36 | ai:saveKey/getKey/removeKey/hasKey     |
| types.ts            |    62 | Shared dependency interfaces          |

index.ts reduced from 3046 → 887 lines (bootstrap + window management).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Apr 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
readide Error Error Apr 23, 2026 10:11pm

Request Review

@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Refactors the Electron main process IPC handlers from a monolithic implementation into modular handler registrations. Extracts handlers for AI keys, auth/sync, data management, git operations, logging, notes, notebooks, plugins, and updates into dedicated modules with dependency injection, reducing index.ts complexity.

Changes

Cohort / File(s) Summary
Handler Infrastructure
apps/desktop/src/main/handlers/types.ts
Defines shared types for IPC handler dependencies: Database, BroadcastFn, NoteToSnapshotFn, and re-exports repository, service, and storage types for handler modules.
Authentication & Sync Handlers
apps/desktop/src/main/handlers/authSyncHandlers.ts, apps/desktop/src/main/handlers/aiKeyHandlers.ts
Registers IPC endpoints for auth/sync/E2EE/subscriptions/devices (+594 lines) and AI provider key management including save/retrieve/remove/check/list operations (+36 lines).
Data Management Handlers
apps/desktop/src/main/handlers/dataHandlers.ts, apps/desktop/src/main/handlers/logHandlers.ts
Adds IPC handlers for backup/restore, export/import notes (+207 lines) and renderer-side logging with log-path retrieval (+53 lines).
Content Handlers
apps/desktop/src/main/handlers/noteHandlers.ts, apps/desktop/src/main/handlers/notebookHandlers.ts
Implements comprehensive note/tag/link/embed/count operations (+429 lines) and notebook CRUD plus Git configuration management (+311 lines).
Feature Handlers
apps/desktop/src/main/handlers/gitHandlers.ts, apps/desktop/src/main/handlers/pluginHandlers.ts, apps/desktop/src/main/handlers/updateHandlers.ts
Registers git repository operations (+154 lines), plugin discovery/install/config/management (+410 lines), and update checking/download/install handling (+132 lines).
Main Process Integration
apps/desktop/src/main/index.ts
Refactors monolithic IPC handler code (~2400 lines) into modular handler registrations; extracts shared helpers broadcastToWindows and noteToSnapshot for reuse across handler modules.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • PR #172: Modifies desktop AI key handling surface with AiKeyStorage and IPC handlers (ai:saveKey, ai:getKey) wired into main/index.ts.
  • PR #156: Updates desktop AI IPC registration in main/index.ts to replace legacy registerAiHandlers with new AI-core flow.
  • PR #177: Modifies main-process auth/sync IPC wiring in authSyncHandlers and index.ts to add E2EE/encryption IPC handlers.

Suggested labels

app:desktop, size/XL, package:storage

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main refactoring work: extracting IPC handlers from a monolithic index.ts into separate handler modules.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/split-main-ipc

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot merged commit a1a6679 into develop Apr 23, 2026
13 of 15 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d315334290

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

broadcastToWindows,
});
registerShareHandlers({ apiClient });
registerAiKeyHandlers({ aiKeyStorage });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Register AI key IPC handlers during startup bootstrap

ai:*Key handlers are now only registered inside initAuthSync() after several awaited initialization steps, so renderer calls can hit “No handler registered” if that async setup is still in progress or if auth/sync init fails. In the previous layout these handlers were always registered and returned safe defaults when storage wasn’t ready, so this refactor introduces a runtime regression for AI settings flows in those startup/error paths.

Useful? React with 👍 / 👎.

github-actions Bot pushed a commit that referenced this pull request Apr 23, 2026
…oliths (#215)

## Summary

Splits the 4 remaining monolithic files into focused modules.

| File | Before | After | Modules |
|------|--------|-------|---------|
| `preload/index.ts` | 1,227 | 161 | 14 API modules in `preload/api/` |
| `App.tsx` | 1,010 | 643 | 4 hooks extracted |
| `PluginsSection.tsx` | 1,043 | 11 (barrel) | PluginCard, BrowseTab,
PluginInspector |
| `syncService.ts` | 1,065 | 18 (barrel) | types, helpers, SyncService
class |

Combined with PR #214 (main/index.ts split), all 5 monoliths are
resolved:
- **main/index.ts**: 3,046 → 887
- **preload/index.ts**: 1,227 → 161
- **App.tsx**: 1,010 → 643
- **PluginsSection.tsx**: 1,043 → 11
- **syncService.ts**: 1,065 → 18

No behavior changes — purely structural.

## Test plan
- [x] `pnpm typecheck` — 17/17 pass
- [x] `pnpm test` — 16/16 pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
tomymaritano added a commit that referenced this pull request Apr 23, 2026
#217)

## Patch v0.12.1

Critical fixes since v0.12.0:

### Bug Fixes
- **Fix "Object has been destroyed" crash on update** — safe broadcast
helper with double isDestroyed check + try/catch (#213)
- **Move single-instance lock before whenReady()** — prevents secondary
instances from initializing DB/IPC (#216)

### Architecture Refactor
- **main/index.ts**: 3,046 → 887 lines (10 IPC handler modules) (#214)
- **preload/index.ts**: 1,227 → 161 lines (14 API modules) (#215)
- **App.tsx**: 1,010 → 643 lines (4 hooks extracted) (#215)
- **PluginsSection.tsx**: 1,043 → 11 lines (3 sub-components) (#215)
- **syncService.ts**: 1,065 → 18 lines (types + helpers extracted)
(#215)

### CI Improvements
- Fix Linux build: expanded cache cleanup, removed corrupted fpm (#212)
- Remove broken dart-actions/tweet action (#210)
- Node.js 24 via FORCE_JAVASCRIPT_ACTIONS_TO_NODE24 (#212)
- Branch protection configured on develop + main (#216)

## Test plan
- [x] `pnpm typecheck` — 17/17 pass
- [x] `pnpm test` — 16/16 pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant