3.5 KiB
3.5 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is a knowledge graph visualization system with a Go backend providing REST APIs and a React frontend using AntV G6 for interactive graph rendering. The system stores graph data in Neo4j and provides nodes, edges, and relationship visualization.
Architecture
Backend (/backend)
- Entry point:
main.go- Sets up Gin router, initializes Neo4j connection, registers handlers - Handlers (
/handlers): HTTP request handlers for/api/graph,/api/search,/api/nodes/:id,/api/nodes/:id/neighbors - Services (
/services): Business logic layer.Neo4jServicequeries Neo4j and converts results to domain models - Models (
/models): Domain models (Node,Edge,GraphData) and API response types - Neo4j client (
/neo4j): Connection wrapper usinggithub.com/neo4j/neo4j-go-driver/v5 - Config (
/config): Configuration loading from.envwith CORS and server settings
Important: Neo4j connection config is in backend/config/.env which contains credentials. The service queries Neo4j by executing Cypher queries and converting results to JSON.
Frontend (/frontend)
- React 19 + TypeScript + Vite build system
- State management: Zustand stores (
graphStore.ts,layoutStore.ts) - Graph visualization: AntV G6 v5 for force-directed layout and interactive graphs
- Styling: Tailwind CSS v4 + HeroUI components
- API client: Axios (
services/graphApi.ts)
Key frontend components:
KnowledgeGraph.tsx- Main page that wires up search, graph view, and node panelGraphView/index.tsx- G6 graph rendering with node selection, highlightingNodePanel/index.tsx- Sidebar showing selected node detailsSearchBar/index.tsx- Search input with node autocomplete
Common Commands
Backend
cd backend
go run main.go # Start dev server on :3001
swag init -g main.go # Regenerate Swagger docs
Frontend
cd frontend
npm run dev # Start dev server on :5173
npm run build # Production build
npm run lint # Lint code
API Endpoints
GET /health- Health checkGET /api/graph- Get all graph data (nodes + edges)GET /api/graph/stats- Graph statisticsGET /api/search?q=query- Search nodes by label, ID, or typeGET /api/nodes/:id- Get node by IDGET /api/nodes/:id/neighbors- Get node neighbors and related edgesGET /swagger/*- Swagger UI documentation
Data Flow
- Frontend fetches graph data via
/api/graph - Graph data is stored in
graphStore(Zustand) GraphViewrenders with G6 force-directed layout- Node clicks highlight connected nodes and trigger
NodePanelupdates - Search queries
/api/searchand selects matching nodes
Neo4j Queries
The backend uses these Cypher query patterns:
- All nodes:
MATCH (n) RETURN n - All edges:
MATCH (a)-[r]->(b) RETURN a.id AS source, b.id AS target, r - Node by ID:
MATCH (n {id: $id}) RETURN n - Search:
MATCH (n) WHERE toLower(n.label) CONTAINS toLower($query) OR ... RETURN n - Neighbors:
MATCH ({id: $id})-[r]-(m) RETURN m, r, startNode(r).id AS source, endNode(r).id AS target
File Conventions
- Backend handlers follow
*_handler.gonaming - Swagger annotations in handlers with
@Summary,@Router, etc. - Frontend types in
types/graph.tsshared between components - Graph styling utilities in
utils/graphStyle.ts