@@ -184,59 +184,27 @@ gograph analyze . \
184
184
185
185
### 3. Essential Graph Visualization Queries
186
186
187
- Once connected, try these queries to explore your codebase:
187
+ Once connected to Neo4j Browser, you can explore your codebase using Cypher queries.
188
188
189
- #### ** Complete Project Overview**
189
+ ** 📚 For a comprehensive collection of queries, see [ docs/QUERIES.md] ( docs/QUERIES.md ) **
190
+
191
+ Here are a few essential queries to get you started:
190
192
191
193
``` cypher
192
194
// View the entire project structure
193
195
MATCH (n)
194
196
WHERE n.project_id = 'my-awesome-project'
195
197
RETURN n
196
198
LIMIT 500
197
- ```
198
-
199
- #### ** Package Dependencies**
200
-
201
- ``` cypher
202
- // Visualize package import relationships
203
- MATCH (p1:Package)-[:IMPORTS]->(p2:Package)
204
- WHERE p1.project_id = 'my-awesome-project'
205
- RETURN p1, p2
206
- ```
207
-
208
- #### ** Function Call Graph**
209
-
210
- ``` cypher
211
- // See function call relationships
212
- MATCH (f1:Function)-[:CALLS]->(f2:Function)
213
- WHERE f1.project_id = 'my-awesome-project'
214
- RETURN f1, f2
215
- LIMIT 100
216
- ```
217
199
218
- #### ** Architecture Overview**
219
-
220
- ``` cypher
221
- // High-level architecture view (packages and their relationships)
222
- MATCH path = (p1:Package)-[:IMPORTS*1..2]->(p2:Package)
223
- WHERE p1.project_id = 'my-awesome-project'
224
- AND p2.project_id = 'my-awesome-project'
225
- RETURN path
226
- LIMIT 50
227
- ```
228
-
229
- #### ** Code Complexity Hotspots**
230
-
231
- ``` cypher
232
- // Find the most connected functions (potential complexity hotspots)
200
+ // Find the most connected functions
233
201
MATCH (f:Function)
234
202
WHERE f.project_id = 'my-awesome-project'
235
- WITH f,
236
- size((f)-[:CALLS]->()) as outgoing_calls,
237
- size(( f)<-[:CALLS]-()) as incoming_calls
238
- RETURN f.name, f.package, outgoing_calls, incoming_calls,
239
- (outgoing_calls + incoming_calls ) as total_connections
203
+ OPTIONAL MATCH (f)-[:CALLS]->(called)
204
+ WITH f, count(called) as outgoing_calls
205
+ OPTIONAL MATCH ( f)<-[:CALLS]-(caller)
206
+ RETURN f.name, f.package, outgoing_calls, count(caller) as incoming_calls,
207
+ (outgoing_calls + count(caller) ) as total_connections
240
208
ORDER BY total_connections DESC
241
209
LIMIT 20
242
210
```
@@ -253,63 +221,22 @@ LIMIT 20
253
221
254
222
** Useful Browser Commands:**
255
223
256
- ``` cypher
257
- // Show node labels and relationship types
258
- CALL db.labels()
259
- CALL db.relationshipTypes()
260
-
261
- // Count nodes by type
262
- MATCH (n)
263
- WHERE n.project_id = 'my-awesome-project'
264
- RETURN labels(n)[0] as NodeType, count(n) as Count
265
- ORDER BY Count DESC
266
-
267
- // Find circular dependencies
268
- MATCH path = (p:Package)-[:IMPORTS*2..]->(p)
269
- WHERE p.project_id = 'my-awesome-project'
270
- RETURN path
271
- LIMIT 10
272
- ```
224
+ See [ docs/QUERIES.md] ( docs/QUERIES.md ) for more queries including:
225
+ - Node and relationship type discovery
226
+ - Circular dependency detection
227
+ - Package dependency analysis
228
+ - Test coverage analysis
229
+ - And many more!
273
230
274
231
### 5. Advanced Analysis Examples
275
232
276
- ``` bash
277
- # Find unused functions
278
- gograph query "
279
- MATCH (f:Function)
280
- WHERE f.project_id = 'my-awesome-project'
281
- AND NOT (f)<-[:CALLS]-()
282
- AND NOT f.name = 'main'
283
- RETURN f.name, f.package, f.file
284
- ORDER BY f.package, f.name
285
- "
286
-
287
- # Analyze test coverage by package
288
- gograph query "
289
- MATCH (p:Package)
290
- WHERE p.project_id = 'my-awesome-project'
291
- OPTIONAL MATCH (p)-[:CONTAINS]->(f:File)
292
- WHERE f.name ENDS WITH '_test.go'
293
- WITH p, count(f) as test_files
294
- OPTIONAL MATCH (p)-[:CONTAINS]->(f2:File)
295
- WHERE NOT f2.name ENDS WITH '_test.go'
296
- RETURN p.name, count(f2) as source_files, test_files,
297
- CASE WHEN count(f2) > 0
298
- THEN round(100.0 * test_files / count(f2), 2)
299
- ELSE 0 END as test_ratio
300
- ORDER BY test_ratio DESC
301
- "
302
-
303
- # Find interface implementations
304
- gograph query "
305
- MATCH (s:Struct)-[:IMPLEMENTS]->(i:Interface)
306
- WHERE s.project_id = 'my-awesome-project'
307
- RETURN i.name as Interface,
308
- collect(s.name) as Implementations,
309
- count(s) as ImplementationCount
310
- ORDER BY ImplementationCount DESC
311
- "
312
- ```
233
+ For advanced analysis queries, see [ docs/QUERIES.md] ( docs/QUERIES.md ) which includes:
234
+ - Finding unused functions
235
+ - Analyzing test coverage by package
236
+ - Finding interface implementations
237
+ - Detecting circular dependencies
238
+ - Identifying code complexity hotspots
239
+ - And many more analysis patterns!
313
240
314
241
### 6. Export and Share Results
315
242
@@ -569,33 +496,26 @@ export GOGRAPH_MCP_PORT=8080
569
496
| ` IMPLEMENTS ` | Struct implements interface |
570
497
| ` HAS_METHOD ` | Struct/interface has method |
571
498
| ` DEPENDS_ON ` | File depends on another file |
572
- | ` DECLARES ` | File declares function/struct/interface |
499
+ | ` DEFINES ` | File defines function/struct/interface |
573
500
| ` USES ` | Function uses variable/constant |
574
501
575
502
### Example Queries
576
503
577
- ``` cypher
578
- -- Find all functions in a package
579
- MATCH (p:Package {name: "main"})-[:CONTAINS]->(f:File)-[:DECLARES]->(fn:Function)
580
- RETURN fn.name, fn.signature
581
-
582
- -- Find circular dependencies
583
- MATCH path=(p1:Package)-[:IMPORTS*]->(p1)
584
- RETURN path
504
+ For a comprehensive collection of Cypher queries organized by use case, see [ docs/QUERIES.md] ( docs/QUERIES.md ) .
585
505
506
+ Quick examples:
507
+ ``` cypher
586
508
-- Find most called functions
587
509
MATCH (f:Function)<-[:CALLS]-(caller)
510
+ WHERE f.project_id = 'my-project'
588
511
RETURN f.name, count(caller) as call_count
589
512
ORDER BY call_count DESC
513
+ LIMIT 10
590
514
591
- -- Find unused functions
592
- MATCH (f:Function)
593
- WHERE NOT (f)<-[:CALLS]-()
594
- RETURN f.name, f.package
595
-
596
- -- Find interface implementations
515
+ -- Find interface implementations
597
516
MATCH (s:Struct)-[:IMPLEMENTS]->(i:Interface)
598
- RETURN s.name, i.name
517
+ WHERE s.project_id = 'my-project'
518
+ RETURN i.name as Interface, collect(s.name) as Implementations
599
519
```
600
520
601
521
## 🤖 MCP Integration
@@ -817,6 +737,7 @@ Inspired by:
817
737
## 🔗 Links
818
738
819
739
- [ Documentation] ( docs/ )
740
+ - [ Query Reference Guide] ( docs/QUERIES.md )
820
741
- [ MCP Integration Guide] ( docs/MCP_INTEGRATION.md )
821
742
- [ Issue Tracker] ( https://github.com/compozy/gograph/issues )
822
743
- [ Discussions] ( https://github.com/compozy/gograph/discussions )
0 commit comments