Skip to content

Entity Graph: server-side BFS + enhanced visualization #81

Description

@damienriehl

Summary

Port the Entity Graph implementation from folio-mapper to ontokit-web as a full-stack feature: a server-side BFS graph building endpoint on the API side, and enhanced React Flow visualization components on the frontend.

This replaces the current client-side graph building (Phase 6A) with a faster, more scalable server-driven approach while preserving ontokit's ontology-agnostic node type system.

Motivation

The current graph visualization builds the graph client-side by iteratively fetching individual class details — limited to ~100 nodes and slow for deep hierarchies. folio-mapper's implementation uses server-side BFS traversal that returns a complete subgraph in one response (up to 200 nodes with truncation detection), handles seeAlso cross-links properly, and supports progressive node expansion.

Proposed Changes

Backend (ontokit-api)

  • New endpoint: GET /api/v1/projects/{id}/ontology/graph/{iri} — server-side BFS traversal
  • Configurable: ancestors_depth, descendants_depth, max_nodes, include_see_also
  • Returns: nodes + edges + truncation flag + total concept count
  • BFS upward (ancestors to root), downward (descendants), and lateral (seeAlso cross-links)

Frontend (ontokit-web)

  • Replace buildGraphData.ts (client-side builder) with API-backed data fetching
  • Port EntityGraphModal — full-screen overlay with close/Esc support
  • Port ConceptNode — adapted with ontokit's node types (focus, class, root, individual, property, external, unexplored)
  • Port HierarchyEdge — subClassOf (solid) + seeAlso (dashed purple) + equivalentClass + disjointWith
  • Port useELKLayout — ELK layered algorithm with TB/LR direction toggle
  • Keep both inline graph (detail panel toggle) AND full-screen modal (expand button)

Coloring (ontology-agnostic)

  • Branch root / ultimate ancestor nodes: red accent
  • Other ancestor nodes: dark gray accent
  • Focus node: blue accent
  • seeAlso edges: purple dashed
  • subClassOf edges: solid gray
  • No hardcoded ontology-specific colors — lineage determines color

Reference Implementation

  • folio-mapper frontend: packages/ui/src/components/mapping/graph/ (EntityGraph, ConceptNode, HierarchyEdge, useELKLayout)
  • folio-mapper backend: backend/app/services/folio_service.py lines 861-1024 (build_entity_graph())
  • folio-mapper types: packages/core/src/folio/graph-types.ts

Testing Plan

  • Backend: BFS traversal returns correct ancestor/descendant/seeAlso subgraph
  • Backend: Truncation flag set when node count exceeds max_nodes
  • Frontend: Graph renders with correct node types and lineage-based colors
  • Frontend: Inline graph toggle works in both standard and developer layouts
  • Frontend: Full-screen modal opens/closes correctly
  • Frontend: Progressive node expansion (click unexplored → fetch 1-hop neighbors)
  • Frontend: Direction toggle (TB ⟷ LR) relayouts correctly
  • E2E: Works with FOLIO ontology and at least one non-FOLIO ontology

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions