Skip to content

Complete HierarchyRelationship abstraction - replace in/out with parentId/childId - #610

Merged
malibio merged 2 commits into
mainfrom
feature/issue-608-hierarchy-abstraction
Nov 22, 2025
Merged

malibio merged 2 commits into
mainfrom
feature/issue-608-hierarchy-abstraction

Conversation

@malibio

@malibio malibio commented Nov 22, 2025

Copy link
Copy Markdown
Collaborator

Summary

Test plan

  • All 1427 TypeScript tests passing
  • Rust code compiles and passes clippy
  • Quality checks pass (eslint, svelte-check)
  • Verified serialization boundary converts correctly

Closes #608

🤖 Generated with Claude Code

…tId/childId

This completes the abstraction started in PR #604 by:

## Frontend Changes
- Update HierarchyRelationship type to use parentId/childId instead of in/out
- Remove id field from type (frontend doesn't need edge IDs)
- Remove helper functions getParentId()/getChildId() (no longer needed)
- Update all usages in reactive-structure-tree.svelte.ts
- Update debug logging in tauri-sync-listener.ts

## Backend Changes (Rust)
- Create separate EdgeDbRecord (deserialize from SurrealDB) and
  HierarchyRelationship (serialize to frontend) types in live_query_service.rs
- Add custom Serialize impl for EdgeRecord to emit parentId/childId (camelCase)
- Remove id field from EdgeRecord serialization (frontend doesn't need it)

## Test Updates
- Update all test files using old field names (in/out/id) to new format
- All 1427 tests passing

Benefits:
- Clean domain model - Frontend uses domain terminology
- Single responsibility - Database format isolated to backend
- Better readability - Self-documenting parent/child semantics
- Easier maintenance - Database changes don't ripple through frontend

Closes #608

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

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Nov 22, 2025

Copy link
Copy Markdown
Collaborator Author

Code Review: PR #610 - Complete HierarchyRelationship Abstraction

Review Type: Initial Review


Requirements Check (from Issue #608)

Criterion Status
HierarchyRelationship type uses parentId/childId instead of in/out ✅ Implemented
id field removed from type (frontend doesn't need edge IDs) ✅ Implemented
Helper functions getParentId()/getChildId() removed (no longer needed) ✅ Implemented
All frontend usages updated to use new field names ✅ Implemented
Rust backend converts at serialization boundary ✅ Implemented
All 1427+ tests passing ✅ Verified (per PR description)
No TypeScript errors or linting issues ✅ Verified (per PR description)

All acceptance criteria are met.


Code Review Summary

This is a well-executed refactoring PR that completes the abstraction started in PR #604. The implementation correctly isolates SurrealDB-specific terminology (in/out) from the frontend domain model (parentId/childId), following the serialization boundary pattern.

Architectural Assessment

The implementation follows Single Responsibility Principle well:

  • Backend (Rust): Deserializes SurrealDB format, converts to domain model at serialization boundary
  • Frontend (TypeScript): Works exclusively with domain-focused parentId/childId terminology

The separation between EdgeDbRecord (internal) and HierarchyRelationship (frontend) in live_query_service.rs is a clean abstraction pattern.


Code Review Findings

🟢 [Good Practice]: Clean Type Separation in Rust

File: packages/desktop-app/src-tauri/src/services/live_query_service.rs:23-53

The implementation correctly separates concerns:

  • EdgeDbRecord (private, with #[serde(rename)] for deserializing SurrealDB format)
  • HierarchyRelationship (public, with #[serde(rename_all = "camelCase")] for frontend)
  • Clean From trait implementation for conversion

This is the correct pattern for serialization boundary abstraction.


🟢 [Good Practice]: Custom Serialization in Core Store

File: packages/core/src/db/surreal_store.rs:79-91

The custom Serialize implementation for EdgeRecord is well-structured:

impl serde::Serialize for EdgeRecord {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        use serde::ser::SerializeStruct;
        let mut state = serializer.serialize_struct("EdgeRecord", 3)?;
        state.serialize_field("parentId", &self.parent_id)?;
        state.serialize_field("childId", &self.child_id)?;
        state.serialize_field("order", &self.order)?;
        state.end()
    }
}

Explicitly implementing Serialize rather than using derive with complex rename attributes provides clarity and control over the serialization format.


🟢 [Good Practice]: Simplified Frontend Type

File: packages/desktop-app/src/lib/types/event-types.ts:38-42

The new type is clean and self-documenting:

export interface HierarchyRelationship {
  parentId: string; // Parent node ID
  childId: string; // Child node ID
  order: number; // Sort order for children (fractional ordering)
}

Removing id and the helper functions (getParentId/getChildId) reduces cognitive overhead - the type is now self-explanatory.


🟢 [Good Practice]: Comprehensive Test Updates

All test files have been systematically updated to use the new field names. The test updates in:

  • reactive-structure-tree.test.ts
  • optimistic-operation-manager.test.ts
  • split-pane-isolation.test.ts

demonstrate thorough coverage of the refactoring.


🟡 [Nit]: Variable Naming Consistency

File: packages/desktop-app/src/lib/stores/reactive-structure-tree.svelte.ts:61-77

The parameter rename from edges to relationships is good, but the parameter name change could be applied consistently to the loop variable as well. Currently correct with rel, which is good.

No action required - this is just noting the naming is already well done.


🟡 [Nit]: Type Number vs f64 Discrepancy

File: packages/desktop-app/src/lib/types/event-types.ts:41 vs packages/desktop-app/src-tauri/src/services/live_query_service.rs:42

TypeScript uses order: number while Rust uses order: f64. This is semantically correct (TypeScript number is always IEEE 754 double precision, same as Rust f64), but worth noting for documentation purposes. The fractional ordering comment in the TypeScript type helps clarify this.

No action required - the types are compatible.


🟢 [Good Practice]: SQL Query Optimization

File: packages/core/src/db/surreal_store.rs:3212

The SQL query was simplified to remove the id field selection:

-- Before:
SELECT id, in, out, order FROM has_child ORDER BY `in`, `order` ASC;
-- After:
SELECT in, out, order FROM has_child ORDER BY `in`, `order` ASC;

This is a micro-optimization that reduces data transfer, aligning with the principle that if data isn't needed, don't fetch it.


Security Assessment

✅ No security concerns identified

  • No new user input handling
  • No changes to authentication/authorization
  • No sensitive data exposure
  • Internal refactoring only

Performance Assessment

✅ No performance concerns

  • Conversion overhead at serialization boundary is minimal (struct-to-struct copy)
  • SQL query is slightly more efficient (fewer fields selected)
  • No algorithmic complexity changes

Summary

Category Assessment
Architecture ✅ Clean separation, correct patterns
Functionality ✅ All acceptance criteria met
Security ✅ No concerns
Maintainability ✅ Improved readability
Testing ✅ Comprehensive updates
Performance ✅ No regressions

Recommendation

✅ APPROVE

This PR demonstrates excellent refactoring discipline:

  1. Single atomic change - One cohesive purpose (complete the abstraction)
  2. Clean domain modeling - Frontend uses domain language, database details isolated
  3. Comprehensive updates - All usages and tests updated systematically
  4. No breaking changes - Serialization boundary handles conversion transparently

The implementation completes what PR #604 started, resulting in cleaner, more maintainable code. Ready to merge.


Reviewed using Pragmatic Quality Framework - Principal Engineer AI Reviewer

Resolved conflict in event-types.ts:
- Kept new NodeWithChildren type from main
- Removed getParentId/getChildId helper functions (obsolete with new naming)
- Updated index.ts exports to remove helper function re-exports

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

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit 263cd8e into main Nov 22, 2025
@malibio
malibio deleted the feature/issue-608-hierarchy-abstraction branch November 22, 2025 14:26
malibio added a commit that referenced this pull request Feb 4, 2026
…tId/childId (#610)

This completes the abstraction started in PR #604 by:

## Frontend Changes
- Update HierarchyRelationship type to use parentId/childId instead of in/out
- Remove id field from type (frontend doesn't need edge IDs)
- Remove helper functions getParentId()/getChildId() (no longer needed)
- Update all usages in reactive-structure-tree.svelte.ts
- Update debug logging in tauri-sync-listener.ts

## Backend Changes (Rust)
- Create separate EdgeDbRecord (deserialize from SurrealDB) and
  HierarchyRelationship (serialize to frontend) types in live_query_service.rs
- Add custom Serialize impl for EdgeRecord to emit parentId/childId (camelCase)
- Remove id field from EdgeRecord serialization (frontend doesn't need it)

## Test Updates
- Update all test files using old field names (in/out/id) to new format
- All 1427 tests passing

Benefits:
- Clean domain model - Frontend uses domain terminology
- Single responsibility - Database format isolated to backend
- Better readability - Self-documenting parent/child semantics
- Easier maintenance - Database changes don't ripple through frontend

Closes #608

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

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 5, 2026
…tId/childId (#610)

This completes the abstraction started in PR #604 by:

## Frontend Changes
- Update HierarchyRelationship type to use parentId/childId instead of in/out
- Remove id field from type (frontend doesn't need edge IDs)
- Remove helper functions getParentId()/getChildId() (no longer needed)
- Update all usages in reactive-structure-tree.svelte.ts
- Update debug logging in tauri-sync-listener.ts

## Backend Changes (Rust)
- Create separate EdgeDbRecord (deserialize from SurrealDB) and
  HierarchyRelationship (serialize to frontend) types in live_query_service.rs
- Add custom Serialize impl for EdgeRecord to emit parentId/childId (camelCase)
- Remove id field from EdgeRecord serialization (frontend doesn't need it)

## Test Updates
- Update all test files using old field names (in/out/id) to new format
- All 1427 tests passing

Benefits:
- Clean domain model - Frontend uses domain terminology
- Single responsibility - Database format isolated to backend
- Better readability - Self-documenting parent/child semantics
- Easier maintenance - Database changes don't ripple through frontend

Closes #608

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

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 26, 2026
…tId/childId (#610)

This completes the abstraction started in PR #604 by:

## Frontend Changes
- Update HierarchyRelationship type to use parentId/childId instead of in/out
- Remove id field from type (frontend doesn't need edge IDs)
- Remove helper functions getParentId()/getChildId() (no longer needed)
- Update all usages in reactive-structure-tree.svelte.ts
- Update debug logging in tauri-sync-listener.ts

## Backend Changes (Rust)
- Create separate EdgeDbRecord (deserialize from SurrealDB) and
  HierarchyRelationship (serialize to frontend) types in live_query_service.rs
- Add custom Serialize impl for EdgeRecord to emit parentId/childId (camelCase)
- Remove id field from EdgeRecord serialization (frontend doesn't need it)

## Test Updates
- Update all test files using old field names (in/out/id) to new format
- All 1427 tests passing

Benefits:
- Clean domain model - Frontend uses domain terminology
- Single responsibility - Database format isolated to backend
- Better readability - Self-documenting parent/child semantics
- Easier maintenance - Database changes don't ripple through frontend

Closes #608

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

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Complete HierarchyRelationship abstraction - replace in/out with parentId/childId

1 participant