- Implement tests for migration 005 to verify removal of deprecated fields in the database schema. - Ensure that new databases are created with a clean schema. - Validate that keywords are correctly extracted from the normalized file_keywords table. - Test symbol insertion without deprecated fields and subdir operations without direct_files. - Create a detailed search comparison test to evaluate vector search vs hybrid search performance. - Add a script for reindexing projects to extract code relationships and verify GraphAnalyzer functionality. - Include a test script to check TreeSitter parser availability and relationship extraction from sample files.
3.8 KiB
Graph Routes API Documentation
Overview
The Graph Routes module provides REST API endpoints for querying and visualizing code structure data from CodexLens indices. It exposes symbols and their relationships as graph nodes and edges.
Endpoints
GET /api/graph/nodes
Query all symbols from the CodexLens SQLite database and return them as graph nodes.
Query Parameters:
path(optional): Project path. Defaults to server's initial path.
Response:
{
"nodes": [
{
"id": "src/file.ts:functionName:10",
"name": "functionName",
"type": "FUNCTION",
"file": "src/file.ts",
"line": 10
}
]
}
Node Types:
FUNCTION: Functions and proceduresCLASS: Classes, interfaces, and type definitionsMETHOD: Class methodsVARIABLE: Variables and constantsMODULE: Module-level definitions
GET /api/graph/edges
Query all code relationships from the CodexLens SQLite database and return them as graph edges.
Query Parameters:
path(optional): Project path. Defaults to server's initial path.
Response:
{
"edges": [
{
"source": "src/file.ts:caller:10",
"target": "module.callee",
"type": "CALLS",
"sourceLine": 10,
"sourceFile": "src/file.ts"
}
]
}
Edge Types:
CALLS: Function/method invocationsIMPORTS: Import/require relationshipsINHERITS: Class inheritance
GET /api/graph/impact
Get impact analysis for a symbol - determines what code is affected if this symbol changes.
Query Parameters:
path(optional): Project path. Defaults to server's initial path.symbol(required): Symbol ID in formatfile:name:line
Response:
{
"directDependents": [
"src/other.ts:caller:20",
"src/another.ts:user:35"
],
"affectedFiles": [
"src/other.ts",
"src/another.ts"
]
}
Implementation Details
PathMapper
Maps source code paths to CodexLens index database paths following the storage structure:
- Windows:
D:\path\to\project→~/.codexlens/indexes/D/path/to/project/_index.db - Unix:
/home/user/project→~/.codexlens/indexes/home/user/project/_index.db
Database Schema
Queries two main tables:
- symbols - Code symbol definitions
id,file_id,name,kind,start_line,end_line
- code_relationships - Inter-symbol dependencies
id,source_symbol_id,target_qualified_name,relationship_type,source_line,target_file
Error Handling
- Returns empty arrays (
[]) if index database doesn't exist - Returns 500 with error message on database query failures
- Returns 400 if required parameters are missing
Type Mappings
Symbol Kinds → Node Types:
{
'function' → 'FUNCTION',
'class' → 'CLASS',
'method' → 'METHOD',
'variable' → 'VARIABLE',
'module' → 'MODULE',
'interface' → 'CLASS',
'type' → 'CLASS'
}
Relationship Types → Edge Types:
{
'call' → 'CALLS',
'import' → 'IMPORTS',
'inherits' → 'INHERITS',
'uses' → 'CALLS'
}
Usage Examples
Fetch All Nodes
curl "http://localhost:3000/api/graph/nodes?path=/path/to/project"
Fetch All Edges
curl "http://localhost:3000/api/graph/edges?path=/path/to/project"
Analyze Impact
curl "http://localhost:3000/api/graph/impact?path=/path/to/project&symbol=src/file.ts:functionName:10"
Integration with CodexLens
This module requires:
- CodexLens to be installed and initialized (
/api/codexlens/init) - Project to be indexed (creates
_index.dbfiles) - better-sqlite3 package for direct database access
Dependencies
better-sqlite3: Direct SQLite database accesscodex-lens: Python package providing the indexing infrastructurepath,fs,os: Node.js built-in modules for file system operations