Skip to content

Commit 11671fb

Browse files
tae2089claude
andcommitted
docs: add comprehensive README
Covers quick start, custom annotations, Apache AGE Cypher queries, Claude Code integration (MCP + skill), architecture diagram, all 19 MCP tools, and CLI commands. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c367ee9 commit 11671fb

1 file changed

Lines changed: 261 additions & 0 deletions

File tree

README.md

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
# code-context-graph
2+
3+
Local code analysis tool that parses codebases via Tree-sitter into a knowledge graph. Supports 15 languages, 19 MCP tools, custom annotation search, and Apache AGE Cypher queries.
4+
5+
## Features
6+
7+
- **15 languages**: Go, Python, TypeScript, Java, Ruby, JavaScript, C, C++, Rust, C#, Kotlin, PHP, Swift, Scala, Lua, Bash
8+
- **19 MCP tools**: parse, search, impact analysis, flow tracing, dead code detection, Cypher queries, and more
9+
- **Custom annotations**: `@intent`, `@domainRule`, `@sideEffect`, `@mutates`, `@index` — search code by business context
10+
- **Apache AGE**: Cypher graph queries for path finding, blast-radius, pattern matching
11+
- **Multi-DB**: SQLite (local), PostgreSQL, MySQL
12+
- **Full-text search**: FTS5 (SQLite), tsvector+GIN (PostgreSQL), FULLTEXT (MySQL)
13+
14+
## Quick Start
15+
16+
### Build
17+
18+
```bash
19+
CGO_ENABLED=1 go build -tags "fts5" -o ccg ./cmd/ccg/
20+
```
21+
22+
### Parse your project
23+
24+
```bash
25+
./ccg build .
26+
```
27+
28+
```
29+
Build complete: 70 files, 749 nodes, 7387 edges
30+
```
31+
32+
### Search
33+
34+
```bash
35+
# Keyword search (includes annotations)
36+
./ccg search "authentication"
37+
38+
# Search by business context
39+
./ccg search "결제" # finds functions with @intent/@domainRule about payments
40+
./ccg search "dead code" # finds deadcode.Find via @intent annotation
41+
```
42+
43+
### Status
44+
45+
```bash
46+
./ccg status
47+
```
48+
49+
```
50+
Nodes: 747
51+
Edges: 6780
52+
Files: 70
53+
54+
Node kinds:
55+
function: 238
56+
test: 339
57+
class: 83
58+
type: 17
59+
file: 70
60+
61+
Edge kinds:
62+
calls: 5124
63+
contains: 679
64+
tested_by: 543
65+
imports_from: 434
66+
```
67+
68+
## Custom Annotations
69+
70+
Add structured metadata to your code. These are indexed and searchable.
71+
72+
### File-level
73+
74+
```go
75+
// @index User authentication and session management service.
76+
package auth
77+
```
78+
79+
### Function-level
80+
81+
```go
82+
// AuthenticateUser validates credentials and creates a session.
83+
// Called from login API handler.
84+
//
85+
// @param username user login ID
86+
// @param password plaintext password
87+
// @return JWT token on success
88+
// @intent verify user identity before granting system access
89+
// @domainRule lock account after 5 consecutive failed attempts
90+
// @sideEffect writes login attempt to audit_log table
91+
// @mutates user.FailedAttempts, user.LockedUntil
92+
// @requires user.IsActive == true
93+
// @ensures err == nil implies valid JWT with 24h expiry
94+
func AuthenticateUser(username, password string) (string, error) {
95+
```
96+
97+
### Available Tags
98+
99+
| Tag | Purpose | Example |
100+
|-----|---------|---------|
101+
| `@index` | File/package description | `@index Payment processing service` |
102+
| `@intent` | Why this function exists | `@intent verify credentials before session creation` |
103+
| `@domainRule` | Business rule | `@domainRule lock account after 5 failures` |
104+
| `@sideEffect` | Side effects | `@sideEffect sends notification email` |
105+
| `@mutates` | State changes | `@mutates user.FailedAttempts, session.Token` |
106+
| `@requires` | Precondition | `@requires user.IsActive == true` |
107+
| `@ensures` | Postcondition | `@ensures session != nil` |
108+
| `@param` | Parameter description | `@param username the login ID` |
109+
| `@return` | Return description | `@return JWT token on success` |
110+
| `@see` | Related function | `@see SessionManager.Create` |
111+
112+
## Apache AGE (Graph Queries)
113+
114+
### Setup
115+
116+
```bash
117+
docker compose up age -d
118+
```
119+
120+
### Build with graph sync
121+
122+
```bash
123+
AGE_DSN="host=127.0.0.1 port=5455 dbname=ccg user=ccg password=ccg sslmode=disable" \
124+
./ccg build --graph .
125+
```
126+
127+
### Cypher queries
128+
129+
```bash
130+
# All function call relationships
131+
./ccg query "MATCH (a:Function)-[:CALLS]->(b:Function) RETURN a.name, b.name" --columns 2
132+
133+
# Blast-radius (3 hops)
134+
./ccg query "MATCH ({name: 'Login'})-[*1..3]-(n) RETURN DISTINCT n.qualified_name"
135+
136+
# Call path between two functions
137+
./ccg query "MATCH path = (a {name: 'Handler'})-[:CALLS*]->(b {name: 'Save'}) RETURN path"
138+
139+
# Dead code
140+
./ccg query "MATCH (n:Function) WHERE NOT ()-[:CALLS]->(n) RETURN n.qualified_name"
141+
142+
# Most called functions
143+
./ccg query "MATCH ()-[:CALLS]->(n) RETURN n.name, count(*) AS c ORDER BY c DESC LIMIT 10"
144+
```
145+
146+
### Graph Schema
147+
148+
**Vertices**: `Function`, `Class`, `Type`, `Test`, `File`
149+
150+
**Edges**: `CALLS`, `IMPORTS_FROM`, `INHERITS`, `IMPLEMENTS`, `CONTAINS`, `TESTED_BY`, `DEPENDS_ON`, `REFERENCES`
151+
152+
## Claude Code Integration
153+
154+
### MCP Server
155+
156+
Add `.mcp.json` to your project:
157+
158+
```json
159+
{
160+
"mcpServers": {
161+
"ccg": {
162+
"command": "./ccg",
163+
"args": ["serve", "--db", "sqlite", "--dsn", "ccg.db"]
164+
}
165+
}
166+
}
167+
```
168+
169+
Claude Code automatically connects and gets access to 19 tools including `execute_cypher` for direct Cypher queries.
170+
171+
### Skill
172+
173+
The `/ccg` skill provides:
174+
175+
```
176+
/ccg build . — Build code graph
177+
/ccg status — Graph statistics
178+
/ccg search "query" — Full-text search
179+
/ccg query "MATCH ..." — Cypher query
180+
/ccg annotate internal/ — AI-generate annotations
181+
```
182+
183+
### AI-Driven Annotation
184+
185+
Claude can auto-generate annotations for your codebase:
186+
187+
```
188+
You: "이 프로젝트에 어노테이션 달아줘"
189+
Claude: reads code → generates @intent, @domainRule, @sideEffect, @mutates
190+
→ writes annotations → rebuilds index
191+
→ now searchable by business context
192+
```
193+
194+
## Architecture
195+
196+
```
197+
Source Code → Tree-sitter Parser → Nodes + Edges + Annotations
198+
199+
SQLite / PostgreSQL (GORM)
200+
↓ ↓
201+
FTS Search Apache AGE Graph
202+
↓ ↓
203+
MCP Server (19 tools)
204+
205+
Claude Code
206+
```
207+
208+
## CLI Commands
209+
210+
| Command | Description |
211+
|---------|-------------|
212+
| `ccg build [dir]` | Parse and build code graph |
213+
| `ccg build --graph [dir]` | Build + sync to Apache AGE |
214+
| `ccg build --embed [dir]` | Build + vector embeddings |
215+
| `ccg update [dir]` | Incremental sync |
216+
| `ccg status` | Graph statistics |
217+
| `ccg search <query>` | Full-text search |
218+
| `ccg search --semantic <q>` | Semantic vector search |
219+
| `ccg query <cypher>` | Execute Cypher query |
220+
| `ccg serve` | Start MCP server (stdio) |
221+
222+
## MCP Tools (19)
223+
224+
| Tool | Description |
225+
|------|-------------|
226+
| `parse_project` | Parse source files |
227+
| `build_or_update_graph` | Full/incremental build with postprocessing |
228+
| `run_postprocess` | Run flows/communities/search rebuild |
229+
| `get_node` | Get node by qualified name |
230+
| `search` | Full-text search |
231+
| `query_graph` | Predefined graph queries (callers, callees, imports, etc.) |
232+
| `list_graph_stats` | Node/edge/file counts |
233+
| `get_impact_radius` | BFS blast-radius analysis |
234+
| `trace_flow` | Call-chain flow tracing |
235+
| `find_large_functions` | Functions exceeding line threshold |
236+
| `find_dead_code` | Unused code detection |
237+
| `detect_changes` | Git diff risk scoring |
238+
| `get_affected_flows` | Flows affected by changes |
239+
| `list_flows` | List all traced flows |
240+
| `list_communities` | List module communities |
241+
| `get_community` | Community details + coverage |
242+
| `get_architecture_overview` | Architecture summary with coupling |
243+
| `get_annotation` | Get annotation and doc tags |
244+
| `execute_cypher` | Execute arbitrary Cypher queries |
245+
246+
## Development
247+
248+
```bash
249+
# Run tests
250+
CGO_ENABLED=1 go test -tags "fts5" ./... -count=1
251+
252+
# Build
253+
CGO_ENABLED=1 go build -tags "fts5" -o ccg ./cmd/ccg/
254+
255+
# Docker (PostgreSQL + AGE + MySQL)
256+
docker compose up -d
257+
```
258+
259+
## License
260+
261+
MIT

0 commit comments

Comments
 (0)