Skip to content

pageel/para-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Para-Graph Banner

para-graph 🧠

Structural code analysis tool powered by Tree-sitter AST parsing.

πŸ‡ΊπŸ‡Έ English

License: MIT Version 0.4.0 Node >= 18 TypeScript 5.x


Table of Contents

🎯 Overview

para-graph is a deterministic code analysis tool that extracts structural information from TypeScript codebases and produces a knowledge graph in JSONL format.

It uses Tree-sitter for fast, accurate AST parsing β€” no compiler pipeline required. The output graph captures:

  • Entities β€” classes, functions, interfaces, arrow functions, methods
  • Relationships β€” imports, function calls, inheritance (future)

Part of the PARA Workspace ecosystem.

✨ Features

  • Deterministic parsing β€” Tree-sitter AST, no heuristics
  • JSONL output β€” one entity/relation per line, easy to stream and process
  • Global Workspace Server β€” Serve multiple project graphs simultaneously via MCP
  • Semantic Enrichment β€” Agent-driven context tagging (summary, complexity, domain concepts)
  • Fast In-Memory Query Engine β€” Indexed lookups with LRU cache (Max=3 projects)

πŸš€ Quick Start

# Clone
git clone https://github.com/pageel/para-graph.git
cd para-graph

# Install
npm install

# Build
npm run build

# Scan any TypeScript project
npx para-graph build /path/to/your/ts/project ./output

Or run directly without cloning:

npx para-graph build ./src ./output

πŸ“– Usage

CLI Commands

# Scan source code and export graph
para-graph build <target-dir> [output-dir] [--import]

# Start MCP server for AI Agent integration
para-graph serve <workspace-root>

# Show help
para-graph --help

Build Command

# Basic usage
para-graph build ./src                       # Output to ./output/
para-graph build ./src ./my-graph            # Custom output directory
para-graph build ./src ./out --import        # Preserve semantic data on re-scan
Argument Required Default Description
target-dir βœ… β€” Directory containing TypeScript source files
output-dir β€” ./output Where to write the graph output
--import β€” β€” Load existing graph, preserve semantic enrichment data

Serve Command

# Start MCP server (stdio transport)
para-graph serve /path/to/workspace

Library Usage

// Import as a library
import { CodeGraph } from 'para-graph';

// Import MCP server factory
import { createServer } from 'para-graph/mcp';

πŸ“Š Output Format

Three files are generated in the output directory:

entities.jsonl

One code entity per line, sorted by file path:

{"id":"src/graph/code-graph.ts::CodeGraph","type":"class","name":"CodeGraph","filePath":"src/graph/code-graph.ts","startLine":10,"endLine":81,"exportType":"named","signature":"export class CodeGraph {"}

relations.jsonl

One relationship per line, sorted by source file:

{"sourceId":"src/index.ts","targetId":"./parser/file-walker.js","relation":"IMPORTS_FROM","sourceFile":"src/index.ts","sourceLine":3}

metadata.json

Summary statistics:

{
  "version": "0.1.0",
  "nodeCount": 31,
  "edgeCount": 47,
  "fileCount": 6,
  "createdAt": "2026-04-21T03:35:33.508Z"
}

Entity Types

Type Description
file Source file
class Class declaration
function Function, method, or arrow function
interface Interface declaration
variable Variable declaration (future)

Relation Types

Relation Description
IMPORTS_FROM File imports from another module
CALLS Function/method calls another function
INHERITS Class extends another (future)
IMPLEMENTS Class implements interface (future)

πŸ—οΈ Architecture

src/
β”œβ”€β”€ cli.ts                    # Subcommand router (shebang entrypoint)
β”œβ”€β”€ commands/
β”‚   β”œβ”€β”€ build.ts              # Build command β€” scan, parse, export graph
β”‚   └── serve.ts              # Serve command β€” MCP server lifecycle
β”œβ”€β”€ graph/
β”‚   β”œβ”€β”€ models.ts             # GraphNode, GraphEdge type definitions
β”‚   β”œβ”€β”€ code-graph.ts         # In-memory graph with dual indexing
β”‚   β”œβ”€β”€ jsonl-exporter.ts     # Serialize graph β†’ JSONL files
β”‚   β”œβ”€β”€ jsonl-importer.ts     # Load graph from JSONL files
β”‚   └── graph-store.ts        # LRU cache manager for multi-project graphs
β”œβ”€β”€ mcp/
β”‚   β”œβ”€β”€ server.ts             # MCP server factory (pure library export)
β”‚   β”œβ”€β”€ tools.ts              # MCP tools: query, edges, enrich
β”‚   └── resources.ts          # MCP resources: JSONL file access
β”œβ”€β”€ parser/
β”‚   β”œβ”€β”€ tree-sitter-parser.ts # AST parsing and entity extraction
β”‚   └── file-walker.ts        # Recursive TypeScript file scanner
└── queries/
    └── typescript.scm        # Tree-sitter query patterns

Data Flow

TypeScript files β†’ File Walker β†’ Tree-sitter Parser β†’ CodeGraph (in-memory) β†’ JSONL Export
                                                            β”‚
                                                      GraphStore (LRU)
                                                            β”‚
                                                      MCP Server β†’ AI Agent

πŸ› οΈ Development

# Install dependencies
npm install

# Run in development
npm run dev

# Build TypeScript
npm run build

# Run tests
npm run test

Tech Stack

Component Technology
Runtime Node.js β‰₯ 18
Language TypeScript 5.x (strict mode)
AST Parser tree-sitter + tree-sitter-typescript
Test Runner Vitest
Dev Runner tsx

πŸ—ΊοΈ Roadmap

Phase Description Status
P1 Structural Base (Tree-sitter AST) βœ… Done
P2 Semantic Enrichment (Agent-Driven) βœ… Done
P3 Storage & Query Engine βœ… Done
P4 CLI Integration & NPM Package βœ… Done
P5 Documentation & Stable Release πŸ“‹ Planned

πŸ“„ License

MIT

About

🧠 para-graph is a deterministic code analysis tool that extracts structural information from TypeScript codebases and produces a knowledge graph in JSONL format.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors