kg-coder
v1.0.1
Published
Knowledge Graph system for agentic AI context engineering
Maintainers
Readme
kg-coder
Elite coding patterns from the world's best developers, delivered to your AI assistant.
Overview
kg-coder is a local-first knowledge graph system designed for agentic AI context engineering. It provides Claude Desktop and other MCP-compatible AI assistants with access to 115 elite coding patterns extracted from 13 legendary developers.
Each pattern includes:
- Problem - The specific issue the pattern solves
- Solution - The implementation approach
- Benefits - What the pattern enables
- Tradeoffs - What you sacrifice when using it
- Causality chains - Full reasoning path from problem to solution
Features
- 115 Elite Patterns from 13 legendary developers (bellard, antirez, ryansolid, mitchellh, and more)
- MCP Server for seamless Claude Desktop integration
- Context-Aware Discovery - Patterns matched by file type, keywords, and problem description
- Full Causality Chains - Understand the "why" behind each pattern
- Local-First - Your data stays on your machine
- SQLite Backend - Fast, reliable, WAL-mode enabled
Installation
Claude Desktop
Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"kg-coder": {
"command": "node",
"args": ["/path/to/kg-coder/dist/mcp-server/index.js"],
"env": {
"KG_DATABASE_PATH": "/path/to/kg-coder/elite-patterns/patterns.db"
}
}
}
}From Source
# Clone the repository
git clone https://github.com/bradheitmann/kg-coder.git
cd kg-coder
# Install dependencies
pnpm install
# Build
pnpm build
# Test
pnpm testQuick Start
Once installed in Claude Desktop, you can query patterns directly:
"What patterns solve rate limiting problems?"
"Show me patterns from antirez"
"How does bellard approach memory management?"Or use the MCP resources directly:
kg://patterns/context?ext=.tsx&keywords=state,reactive
kg://patterns/developer?dev=ryansolid&limit=5
kg://patterns/top?minWow=0.95Pattern Library
Tier 1: Legendary
| Developer | Known For | Patterns | |-----------|-----------|----------| | Fabrice Bellard | FFmpeg, QEMU, QuickJS | Systems programming, compression | | Salvatore Sanfilippo (antirez) | Redis | Data structures, idempotency | | Andrew Kelley | Zig | Comptime, error handling |
Tier 2: Elite
| Developer | Known For | Patterns | |-----------|-----------|----------| | Ryan Carniato | SolidJS | Fine-grained reactivity | | Rich Harris | Svelte | Compiler-driven UI | | Evan You | Vue | Reactive systems | | Mitchell Hashimoto | HashiCorp | Infrastructure patterns |
Tier 3: Master
| Developer | Known For | Patterns | |-----------|-----------|----------| | Matt Pocock (matklad) | rust-analyzer | IDE architecture | | Tanner Linsley | TanStack | State management | | Jarred Sumner | Bun | Runtime optimization | | Simon Willison | Datasette | Data tooling | | TJ Holowaychuk | Express, Koa | Node.js patterns |
MCP Tools
Memory Tools (6)
| Tool | Description |
|------|-------------|
| memory.upsert_entities | Create or update graph nodes |
| memory.upsert_edges | Create relationships between nodes |
| memory.invalidate_edges | Soft-delete edges (temporal versioning) |
| memory.query_subgraph | Query graph with traversal |
| context.assemble_pgn | Pack context for LLM consumption |
| memory.compact_session | Optimize session memory |
Pattern Tools (5)
| Tool | Description |
|------|-------------|
| patterns.find_for_problem | Find patterns by problem description |
| patterns.get_by_developer | Get patterns from specific developer |
| patterns.get_causality_chain | Get full causality chain for pattern |
| patterns.find_by_context | Find patterns by file/language context |
| patterns.search | Full-text pattern search |
MCP Resources
Graph Resources (8)
| Resource | Description |
|----------|-------------|
| kg://graph/stats | Graph statistics (nodes, edges, tokens) |
| kg://graph/entities | Entity listing with filtering |
| kg://graph/neighborhood | K-hop expansion from seeds |
| kg://graph/temporal | Time-slice graph state |
| kg://graph/clusters | Spectral clustering view |
| kg://graph/ranking | Marginal utility ranking |
| kg://graph/paths | Shortest path finder |
| kg://server/info | Server version and capabilities |
Pattern Resources (6)
| Resource | Description |
|----------|-------------|
| kg://patterns/context | Context-aware pattern discovery |
| kg://patterns/developer | Patterns by developer |
| kg://patterns/top | Highest-rated patterns |
| kg://patterns/problems | Problem-organized index |
| kg://patterns/chain | Full causality chains |
| kg://patterns/developers | Available developer listing |
Configuration
Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| KG_DATABASE_PATH | Path to SQLite database | ~/.kg-coder/memory.db |
| KG_VERBOSE | Enable verbose logging | false |
CLI Arguments
kg-coder-mcp --db /path/to/database.db --verbose| Argument | Description |
|----------|-------------|
| --db, --database | Database file path |
| --verbose, -v | Enable verbose logging |
| --help, -h | Show help |
Database Schema
kg-coder uses SQLite with:
- WAL mode for concurrent access
- Foreign key constraints for referential integrity
- 13 indexes for query performance
- Temporal versioning for edge history
Statistics
| Metric | Value | |--------|-------| | Nodes | 381 | | Edges | 335 | | Entity Types | 20 | | Predicates | 31 |
Serialization Formats
kg-coder supports multiple formats for context packing:
- PGN (Prompt Graph Notation) - Markdown for LLMs
- TOON (Tokens Optimized Notation) - CSV tables for efficiency
- GGN (Graph Grammar Notation) - Schema-first format
- JSON - Native format
Development
# Development mode (watch)
pnpm dev
# Run tests
pnpm test
# Run tests with coverage
pnpm test:coverage
# Type check
pnpm typecheck
# Lint
pnpm lintProject Structure
kg-coder/
├── src/
│ ├── core/ # Core types and models
│ ├── storage/ # SQLite database layer
│ ├── serialization/ # PGN, TOON, GGN formats
│ ├── mcp-server/ # MCP server implementation
│ ├── tools/ # MCP tool handlers
│ └── import/ # Data import pipeline
├── elite-patterns/ # Pattern database
├── tests/ # Test suite
└── docs/ # DocumentationContributing
See CONTRIBUTING.md for development setup and guidelines.
Security
See SECURITY.md for security model and vulnerability reporting.
License
MIT - see LICENSE
Acknowledgments
This project extracts and organizes coding patterns from publicly available talks, blog posts, and open-source code by the developers listed above. All attribution is preserved in the pattern metadata.
Built with care by OKOA Labs
