Skip to content

Epic: Query and Listing System for NodeSpace #444

Closed

Description

@malibio

Overview

Implement comprehensive query and listing system for NodeSpace, enabling users to create queries, view results in multiple formats (list, table, kanban), and persist view preferences. Primary use case is AI chat creating queries as child nodes.

Architecture References

Epic Scope

This epic encompasses the complete query system from data model to user interface, designed for AI-first interaction with support for manual query creation.

Problem Statement

NodeSpace needs a way to create, store, execute, and view queries that filter/search nodes. The system must:

  • Store structured query definitions as first-class nodes
  • Execute queries efficiently against the database
  • Present results in multiple view types (list, table, kanban)
  • Remember user view preferences per query
  • Support AI chat creating queries as child nodes
  • Enable future inline query embeds without refactoring

Architecture Overview

┌─────────────────────────────────────────────────────────┐
│                    QueryNode (Data)                     │
│  ┌───────────────────────────────────────────────────┐  │
│  │ Rust: QueryNodeBehavior in behaviors/mod.rs      │  │
│  │ Schema: query spoke table (auto-generated)       │  │
│  │ Content: Full QueryDefinition JSON               │  │
│  └───────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────┘
                          ↓
┌─────────────────────────────────────────────────────────┐
│              QueryService (Execution)                    │
│  ┌───────────────────────────────────────────────────┐  │
│  │ Core Rust Service: packages/core                 │  │
│  │ SurrealQL Query Building                         │  │
│  │ Hub-and-spoke query patterns                     │  │
│  └───────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────┘
                          ↓
┌─────────────────────────────────────────────────────────┐
│          QueryNodeViewer (Presentation)                  │
│  ┌───────────────────────────────────────────────────┐  │
│  │ Specialized Viewer (like DateNodeViewer)         │  │
│  │ View Tabs: List | Table | Kanban                 │  │
│  └───────────────────────────────────────────────────┘  │
│                          ↓                              │
│  ┌─────────────┬─────────────────┬─────────────────┐  │
│  │  ListView   │   TableView     │   KanbanView    │  │
│  └─────────────┴─────────────────┴─────────────────┘  │
└─────────────────────────────────────────────────────────┘
                          ↓
┌─────────────────────────────────────────────────────────┐
│       QueryPreferencesService (Persistence)              │
│  ┌───────────────────────────────────────────────────┐  │
│  │ Last-used view per query                         │  │
│  │ localStorage + in-memory cache                   │  │
│  └───────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────┘

Implementation Plan

Phase 1: Foundation

Issues: #439, #440

  1. QueryNode Behavior (QueryNode Behavior and Core Type Definitions #439)

    • QueryNodeBehavior in packages/core/src/behaviors/mod.rs
    • Core schema in get_core_schemas()
    • TypeScript type definitions
    • Frontend plugin definition
  2. QueryService (QueryService with SQL Query Execution #440)

    • Core Rust service in packages/core/src/services/
    • SurrealQL query translation
    • Property filters via spoke table (data.property)
    • Relationship filters via graph edges

Deliverable: QueryNode can be created and queries can be executed

Phase 2: User Interface

Issues: #441, #442, #443

  1. QueryNodeViewer (QueryNodeViewer with Multi-View Rendering Support #441)

    • Specialized full-page viewer
    • Multi-view rendering (list/table/kanban)
    • Loading/error/empty states
  2. QueryEditor (QueryEditor with JSON Textarea Interface #442)

    • JSON textarea for query editing
    • Validation and error display
    • Query examples and templates
  3. QueryPreferencesService (QueryPreferencesService for User View Preferences #443)

    • Per-query view preferences
    • localStorage persistence
    • In-memory caching

Deliverable: Users can create, edit, and view queries with persisted preferences

Sub-Issues

Foundation

User Interface

Acceptance Criteria

  • QueryNode can be created and persisted
  • Queries execute and return matching nodes
  • Results render in list, table, and kanban views
  • View tabs switch seamlessly
  • User view preferences persist across sessions
  • Query editor allows JSON editing with validation
  • AI chat can create QueryNode children
  • All tests pass (bun run test:all)
  • Code passes bun run quality:fix
  • Architecture supports future inline embeds

Key Design Decisions

1. Query vs View Separation

QueryNode stores ONLY query definition (no view preferences). Preferences stored via QueryPreferencesService (#443).

2. Specialized Viewer Pattern

QueryNodeViewer is specialized (like DateNodeViewer), NOT wrapping BaseNodeViewer. Different use case = different pattern.

3. Core Rust Service

QueryService in packages/core (not Tauri-specific). Reusable by Tauri commands, MCP servers, CLI tools.

4. JSON Editor First

Start with JSON textarea, not visual builder. Immediate functionality, full power, progressive enhancement path.

5. AI Query Ownership

AI-generated queries are children of chat nodes. Uses has_child graph edges for hierarchical organization.

Common Patterns to Follow

Component Naming:

  • *Node = Individual node components wrapping BaseNode
  • *NodeViewer = Page-level viewers

Service Pattern:

  • Singleton exported instance
  • Async methods with error handling
  • In-memory caching where appropriate

Type Safety:

  • Discriminated unions for ViewConfig
  • Explicit error types
  • Proper null handling

Resources & References

Architecture Documentation

  • docs/architecture/development/how-to-add-new-node-type.md
  • docs/architecture/components/component-architecture-guide.md
  • docs/architecture/business-logic/node-behavior-system.md

Similar Implementations

  • DateNodeViewer: Pattern reference for specialized viewers
  • SharedNodeStore: Caching pattern reference

Technology Stack

  • Backend: Rust with SurrealDB
  • Frontend: Svelte 5.x with $state/$derived runes
  • Testing: Vitest with Happy-DOM

Future Enhancements (Not in This Epic)

  • Visual query builder UI
  • Natural language query interface
  • Inline query embeds in markdown
  • Real-time query updates
  • Query optimization and indexing
  • Export functionality

Epic Status: Ready to Begin
Total Issues: 5 (all created and tracked)
Start Here: #439 (QueryNode Behavior)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions