Skip to content

Add a knowledge graph view #4

Description

@netclectic

Summary

Memories already support typed relationships (memory_relationships), but there is no way to visualize them. Add a knowledge graph view — a classic force-directed graph with nodes sized by their number of incoming relationships.

Changes

Backend

  • New IGraphService / GraphService (auto-registered via [AutoRegisterInterfaces]), depending on NpgsqlDataSource — does not extend IStorage, so no test-fake churn.
    • GetKnowledgeGraphAsync(WorkspaceId? workspaceId, ProjectId? projectId):
      • Nodes: memories with archetype IN (0,1), optionally scoped by owner (workspace subtree via recursive CTE, or a single project).
      • Edges: memory_relationships where both endpoints are non-archived and within scope.
  • New models GraphData, GraphNode { id, title, type }, GraphEdge { from, to, type }.
  • New endpoints in HomeController: GET /api/graph?workspaceId=&projectId= (JSON) and /graph (page).

Frontend

  • New Views/Home/Graph.cshtml rendering with vis-network 9.x (CDN, consistent with existing marked/mermaid/Prism usage).
  • Node size ∝ indegree (number of incoming relationships); minimum size for isolated nodes.
  • Node color by memory type; edge color by relationship type (reuse the existing getRelationshipBadgeColor color mapping).
  • Click a node → /view/{id}; hover tooltip shows the title; barnesHut physics; zoom/pan built in.
  • Light/dark theme support (read data-theme, MutationObserver on the <html data-theme> attribute to re-style on toggle).
  • Empty state when there are no relationships.
  • Sidebar nav link ("Graph") in the primary-actions row of _Layout.cshtml.

Files

  • New: src/Memorizer/Services/IGraphService.cs, Services/GraphService.cs, Models/GraphData.cs, Views/Home/Graph.cshtml
  • Modified: src/Memorizer/Controllers/HomeController.cs, Views/Shared/_Layout.cshtml, wwwroot/css/site.css

Notes

  • No dependencies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestuiWeb UI changes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions