This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm run build- Build the library using tsupnpm run dev- Build with watch mode for developmentnpm run typecheck- Run TypeScript type checking without emitting files
npm test- Run all tests oncenpm run test:watch- Run tests in watch modenpm run test:coverage- Run tests with coverage report- Run a single test file:
npx vitest run tests/basic.test.ts
npm run lint- Run ESLint on TypeScript filesnpm run format- Format code with Prettier
npm run example:basic- Run basic usage examplenpm run example:custom-extraction- Run custom extraction examplenpm run example:custom-types- Run custom types examplenpm run example:visualization- Run visualization examplenpm run example:viz-server- Run visualization server with Bun
@fluxgraph/knowledge is a flexible, database-agnostic knowledge graph implementation for TypeScript that supports multiple database backends.
-
KnowledgeGraph (
src/core/KnowledgeGraph.ts)- Main entry point for all graph operations
- Provides high-level API for nodes, edges, queries, and search
- Database-agnostic, works through adapters
-
Database Adapters (
src/adapters/)BaseAdapter: Abstract class defining the adapter interfaceSQLiteAdapter: Node.js SQLite implementation using better-sqlite3D1Adapter: Cloudflare D1 implementationBunSQLiteAdapter: Bun-specific SQLite implementation- Adapters handle low-level database operations and queries
-
Knowledge Extraction (
src/extraction/)KnowledgeExtractor: Extracts entities and relationships from text- Supports custom patterns for entity and relationship extraction
- Can process conversations and structured text
-
Graph Algorithms (
src/algorithms/)- Path finding (shortest path, all paths)
- Centrality measures (degree, PageRank)
- Community detection
- Cycle detection and clustering
-
Visualization (
src/visualization/)- Mermaid diagram generation for knowledge graphs
MermaidGraphVisualizer: Generates Mermaid diagram syntaxMermaidUtils: Utilities for HTML/Markdown output
- Uses TypeScript generics for custom node types
- Core types in
src/types/index.ts - Database schema defined in
src/schema/index.tsusing Drizzle ORM
Tables created in all adapters:
kg_nodes: Node storage with type, label, properties (JSON), confidencekg_edges: Edge storage with type, from/to nodes, properties (JSON)kg_node_indices: Indexes for efficient node lookupskg_edge_indices: Indexes for efficient edge lookupskg_search_index: Full-text search indexkg_graph_metadata: Graph-level metadata
- Adapter Pattern: Database operations abstracted behind adapters
- Factory Pattern:
createKnowledgeGraph()andcreateAdapter()for easy instantiation - Builder Pattern: Mermaid diagram options built incrementally
- Strategy Pattern: Different output formats (HTML, Markdown, Live Editor) for Mermaid diagrams
when writing commits and pull requests don't put Claude Code as the author