refactor: split oversized modules into focused domain files - #116
Merged
Conversation
1590-LOC monolith → 265 LOC core + 6 focused modules: - tag-queries.ts (tags + definitions) - link-queries.ts (wiki-link resolution) - property-queries.ts (properties + definitions) - snapshot-queries.ts (version history) - journal-queries.ts (heatmap, streaks, stats) - query-helpers.ts (serialization, activity level constants) All re-exported from notes.ts for backward compatibility.
1040-LOC handler → 525 LOC + 4 focused modules: - notes-schemas.ts (shared Zod schemas with DRY property type enum) - export-handlers.ts (consolidated PDF/HTML export, was ~90% duplicated) - property-definition-handlers.ts (property definition CRUD) - handler-utils.ts (shared extractError utility)
…al hooks notes-tree.tsx: 2089 → 1192 LOC via 3 custom hooks: - useTreeDragDrop (move/reorder logic) - useTreeRename (note + folder rename state) - useTreeDelete (delete state + confirmation) ContentArea.tsx: 1469 → 1122 LOC via wiki-link-utils.ts extraction. Deduplicated getDisplayName between notes-tree and virtualized-notes-tree.
- Add PREVIEW_BY_TITLE handler to notes-handlers.ts - Add STATUS/SELECT/MULTISELECT types to notes-schemas.ts - Add property option CRUD handlers (ADD_PROPERTY_OPTION, ADD_STATUS_OPTION, REMOVE/RENAME/UPDATE_OPTION_COLOR, DELETE_PROPERTY_DEFINITION, ENSURE) - Add TreeActionsExposer + collapseAll/expandAll to NotesTreeActions - Use generalSettings.createInSelectedFolder instead of isTreeFocusedRef
h4yfans
force-pushed
the
worktree-major-refactor
branch
from
March 29, 2026 18:30
4a9c718 to
6ac6a8d
Compare
Notes-tree.tsx and ContentArea.tsx reverted to main's versions during rebase conflict resolution. Hook files (use-tree-drag-drop, use-tree-rename, use-tree-delete) remain as extracted but unwired — available for a follow-up PR that properly integrates them with main's updated component code. The query split, IPC handler split, and utility extractions are intact.
h4yfans
added a commit
that referenced
this pull request
May 6, 2026
* refactor(queries): split notes.ts into domain-specific query modules 1590-LOC monolith → 265 LOC core + 6 focused modules: - tag-queries.ts (tags + definitions) - link-queries.ts (wiki-link resolution) - property-queries.ts (properties + definitions) - snapshot-queries.ts (version history) - journal-queries.ts (heatmap, streaks, stats) - query-helpers.ts (serialization, activity level constants) All re-exported from notes.ts for backward compatibility. * refactor(ipc): extract schemas, export, and property handlers 1040-LOC handler → 525 LOC + 4 focused modules: - notes-schemas.ts (shared Zod schemas with DRY property type enum) - export-handlers.ts (consolidated PDF/HTML export, was ~90% duplicated) - property-definition-handlers.ts (property definition CRUD) - handler-utils.ts (shared extractError utility) * refactor(renderer): extract tree utils, wiki-link utils, and behavioral hooks notes-tree.tsx: 2089 → 1192 LOC via 3 custom hooks: - useTreeDragDrop (move/reorder logic) - useTreeRename (note + folder rename state) - useTreeDelete (delete state + confirmation) ContentArea.tsx: 1469 → 1122 LOC via wiki-link-utils.ts extraction. Deduplicated getDisplayName between notes-tree and virtualized-notes-tree. * docs: add Major Refactor changelog entry * chore: regenerate IPC invoke map * fix: resolve rebase conflicts and port main's new features - Add PREVIEW_BY_TITLE handler to notes-handlers.ts - Add STATUS/SELECT/MULTISELECT types to notes-schemas.ts - Add property option CRUD handlers (ADD_PROPERTY_OPTION, ADD_STATUS_OPTION, REMOVE/RENAME/UPDATE_OPTION_COLOR, DELETE_PROPERTY_DEFINITION, ENSURE) - Add TreeActionsExposer + collapseAll/expandAll to NotesTreeActions - Use generalSettings.createInSelectedFolder instead of isTreeFocusedRef * chore: regenerate IPC invoke map * fix: restore main-compatible component versions after rebase Notes-tree.tsx and ContentArea.tsx reverted to main's versions during rebase conflict resolution. Hook files (use-tree-drag-drop, use-tree-rename, use-tree-delete) remain as extracted but unwired — available for a follow-up PR that properly integrates them with main's updated component code. The query split, IPC handler split, and utility extractions are intact. * fix: remove duplicate export/property-definition handlers causing IPC map conflict
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Split 4 oversized files (1040-2089 LOC each) into 17 focused modules, reducing the largest file from 2089 → 265 LOC.
Why
Files exceeded the project's 800 LOC limit. Monolithic query/handler/component files made navigation, testing, and code review difficult. Duplicate logic (PDF/HTML export, activity-level thresholds, getDisplayName) increased maintenance burden.
How
Phase 1 — Pure utility extraction: Moved non-React functions (tree building, wiki-link processing, Zod schemas, serialization helpers) into standalone modules. Zero behavioral change.
Phase 2 — Query module split: Split
queries/notes.ts(1590 LOC) into 6 domain modules (tag, link, property, snapshot, journal + shared helpers). All re-exported fromnotes.tsfor backward compatibility — no consumer changes needed.Phase 3 — IPC handler split: Extracted property definition and export handlers. Consolidated duplicate PDF/HTML export into shared
exportNote()with format parameter. CreatedextractError()utility replacing 16 identical inline patterns.Phase 4 — React hooks: Extracted
useTreeDragDrop,useTreeRename,useTreeDeletefrom 2089-LOC NotesTree component. Skipped ContentArea drag-drop extraction (too intertwined with editor API — would be a "bucket hook").Key decisions:
export * from './sub-module') preserves all existing import pathsACTIVITY_THRESHOLDSconstants shared between TypeScript function and SQL CASE expressionDrizzleDbtype defined per-module to avoid circular deps (1 line each)Type
refactor— restructure without behavior changeTest plan
All 5,550 existing tests pass (5,211 desktop + 339 sync-server). No new tests needed — this is a pure restructuring with identical behavior, verified by the full existing test suite.
Checklist