Skip to content

Phase 2.1: Implement BacklinkService Foundation #73

Closed

Description

@malibio

Parent Issue

Part of Epic #69: Text Editor Architecture Enhancement - Phase 2

Summary

Implement Universal Node Reference Service to provide real-time @ trigger detection, nodespace:// URI creation, and autocomplete-based node selection with bidirectional reference tracking.

Background

Building on Phase 1's enhanced ContentProcessor, this implements the universal node reference system that enables NodeSpace to reference any node type (users, tasks, documents, dates, custom entities) through a single @ trigger interface.

Architectural Foundation: ADR-005 establishes the universal @ trigger system with nodespace:// URIs and content-driven decorations.

Core Functionality

  • Universal @ Trigger: Single interface for referencing any node type
  • Autocomplete Selection: Modal with search/filter for existing nodes or creation
  • nodespace:// URI Storage: Standard markdown links with custom URI scheme
  • Bidirectional References: Maintain consistent relationship tracking

Service Interface

interface NodeReferenceService {
  // @ trigger detection and handling
  detectTrigger(content: string, cursorPosition: number): TriggerContext | null;
  showAutocomplete(triggerContext: TriggerContext): Promise<AutocompleteResult>;
  insertNodeReference(selectedNode: BaseNode, insertPosition: Position): string;
  
  // nodespace:// URI handling  
  parseNodespaceURI(uri: string): NodeReference;
  createNodespaceURI(nodeId: string, options?: URIOptions): string;
  resolveNodespaceURI(uri: string): BaseNode | null;
  
  // Bidirectional reference management
  addReference(sourceId: string, targetId: string): void;
  removeReference(sourceId: string, targetId: string): void;
  getOutgoingReferences(nodeId: string): NodeReference[];
  getIncomingReferences(nodeId: string): NodeReference[];
  
  // Node search and creation
  searchNodes(query: string, nodeType?: string): BaseNode[];
  createNode(nodeType: string, content: string): BaseNode;
  
  // ContentProcessor integration
  enhanceContentProcessor(): void;
  detectNodespaceLinks(content: string): NodespaceLink[];
}

interface TriggerContext {
  position: number;
  query: string;
  element: HTMLElement;
  cursorRect: DOMRect;
}

interface NodeReference {
  sourceId: string;
  targetId: string;
  linkText: string;
  nodeType: string;
  created: Date;
  resolved: boolean;
}

interface NodespaceLink {
  linkText: string;
  nodeId: string;
  startPos: number;
  endPos: number;
  resolved: boolean;
}

Implementation Tasks

  • Create NodeReferenceService interface and core implementation
  • Implement @ keystroke detection in contenteditable elements
  • Build autocomplete modal with node search and filtering
  • Create nodespace:// URI parsing and generation
  • Implement bidirectional reference tracking with Map storage
  • Enhance ContentProcessor to detect nodespace:// links
  • Build node search service with fuzzy matching
  • Create node creation flow for new entities
  • Integrate with existing TextNode component
  • Add real-time reference updates via EventBus

Acceptance Criteria

  • @ keystroke triggers autocomplete modal in any text editing context
  • Autocomplete shows existing nodes filtered by search query
  • Selecting node inserts [content](nodespace://uuid) markdown link
  • Creating new node generates UUID and inserts reference
  • nodespace:// URIs resolve to correct node instances
  • Bidirectional reference tracking maintains consistency
  • Performance handles 100+ simultaneous references efficiently
  • Integration preserves all existing TextNode functionality
  • Foundation ready for Phase 2.2 rich decorations

Dependencies

Estimated Effort

7-8 days

Definition of Done

  • NodeReferenceService implemented with comprehensive functionality
  • @ trigger detection working in text editor
  • Autocomplete modal functional with node search/creation
  • nodespace:// URI system operational and tested
  • Bidirectional reference tracking working
  • ContentProcessor enhanced for nodespace:// link detection
  • Performance benchmarks meet requirements
  • All existing functionality preserved
  • Documentation and code review completed

Technical Notes

This service replaces the planned [[wikilink]] approach with the superior universal @ trigger system documented in ADR-005. The implementation prepares the foundation for rich node type decorations in Phase 2.2.

Activity

  1. self-assigned this
    on Aug 21, 2025
  2. malibio commented on Sep 25, 2025

    @malibio
    CollaboratorAuthor

    Closing as superseded by business logic layer approach. Mentions/backlinks will be handled by the new Rust backend mention system (Issue #105).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions