Skip to content

Document Service Layer Pattern: Direct NodeService vs. Dedicated Services #689

Closed

Description

@malibio

Overview

Clarify when to use NodeService directly vs. creating dedicated services like SchemaService.

Problem

Current architecture has:

  • TaskNode → Direct NodeService usage
  • SchemaNode → Dedicated SchemaService

This appears inconsistent but is actually intentional complexity-driven differentiation.

Analysis

Complexity Comparison

Aspect TaskNode SchemaNode
Fields Flat (status, priority) Nested array (fields: Vec<SchemaField>)
Updates Atomic replacement Surgical array mutations
Validation Simple type checks Protection level enforcement
Side effects None DDL synchronization
Service Direct NodeService Dedicated SchemaService

Why SchemaService Exists

  1. Array Manipulation - add_field() appends to array, not replaces
  2. Nested Updates - extend_enum_field() modifies userValues inside array element
  3. Protection Rules - Prevents deletion of core fields that UI depends on
  4. DDL Synchronization - sync_schema_to_database() generates SurrealDB DEFINE FIELD statements
  5. Transaction Integrity - Multi-step workflows (read-validate-mutate-persist-sync) encapsulated

When to Use Each Pattern

Direct NodeService Pattern:

  • Simple node types with flat properties
  • Atomic property updates
  • No nested mutations
  • Examples: TaskNode, PersonNode, ProjectNode

Dedicated Service Pattern:

  • Complex node types requiring surgical operations
  • Nested array/object mutations
  • Domain-specific validation rules
  • External system synchronization
  • Example: SchemaNode → SchemaService

Solution

Add documentation explaining the service layer pattern to prevent future "why is this different?" questions.

Acceptance Criteria

  • Update /docs/architecture/business-logic/node-behavior-system.md with service pattern guide
  • Add code comments to SchemaService explaining when to create dedicated services
  • Document examples of both patterns

Technical Notes

This is NOT architectural inconsistency - it's appropriate separation of concerns:

  • TaskNode: User-facing data entity (simple, frequent updates)
  • SchemaNode: Meta-schema entity (complex, infrequent updates, system-critical)

Related Issues

Activity

  1. added
    documentation
    on Nov 30, 2025
  2. malibio commented on Nov 30, 2025

    @malibio
    CollaboratorAuthor

    Superseded by #690 - we're deleting SchemaService entirely rather than documenting why it exists.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    architecturedocumentationfoundation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions