Version: 0.20.0 | Author: Olivier Vitrac, PhD, HDR | [email protected] | Adservio Updated: 2025-11-28
The RAGIX Abstract Syntax Tree (ragix-ast) tool is a powerful command-line interface for deep code analysis, architectural exploration, and software metrics calculation. It works by parsing source code into an Abstract Syntax Tree (AST) and building a comprehensive dependency graph of your entire project.
An AST is a tree representation of source code structure. ragix-ast uses language-specific parsers to build these trees:
- Python: Built-in
astmodule - Java:
javalangparser
A graph where:
- Nodes are symbols (classes, functions, methods, interfaces)
- Edges are relationships (imports, calls, inheritance, implementation)
This graph powers all analysis features.
| Language | File Extensions | Parser |
|---|---|---|
| Python | .py |
Built-in ast |
| Java | .java |
javalang |
# Scan a project and get summary
ragix-ast scan ./src
# Calculate code metrics
ragix-ast metrics ./src
# Find the most complex code
ragix-ast hotspots ./src --top 10
# Generate interactive dependency visualization
ragix-ast graph ./src --format html --output deps.html
# Search for patterns
ragix-ast search ./src "type:class name:*Service*"Performs a full analysis of a project directory.
Usage:
ragix-ast scan <path> [OPTIONS]Options:
| Option | Description | Default |
|---|---|---|
--lang LANG |
Force language (python, java, auto) |
auto |
--exclude PATTERN |
Exclude paths matching pattern | None |
--json |
Output raw JSON | Disabled |
--verbose |
Show detailed progress | Disabled |
Example:
# Scan Java project
ragix-ast scan ./src --lang java
# Scan with exclusions
ragix-ast scan . --exclude "test/*" --exclude "vendor/*"
# Get JSON output for scripting
ragix-ast scan ./src --json > analysis.jsonOutput:
Project Analysis: ./src
โโโโโโโโโโโโโโโโโโโโโโโโ
Files analyzed: 150
Symbols extracted: 1,234
Dependencies found: 3,456
Classes: 89
Functions: 456
Methods: 689
Parses a single file and shows its AST. Useful for debugging and understanding code structure.
Usage:
ragix-ast parse <file> [OPTIONS]Options:
| Option | Description | Default |
|---|---|---|
--json |
Full AST as JSON | Disabled |
--symbols |
List symbols only | Disabled |
--depth N |
Limit tree depth | Unlimited |
Examples:
# Show AST summary
ragix-ast parse src/main.py --depth 5
# List all symbols in a file
ragix-ast parse src/api/user.java --symbols
# Get full AST as JSON
ragix-ast parse src/handler.py --jsonSearch for symbols using the RAGIX query language. This is one of the most powerful features.
Usage:
ragix-ast search <path> "<query>" [OPTIONS]Options:
| Option | Description | Default |
|---|---|---|
--limit N |
Maximum results | 50 |
--json |
Output as JSON | Disabled |
--context N |
Show N lines of context | 0 |
Examples:
# Find all classes with "Service" in name
ragix-ast search . "type:class name:*Service*"
# Find all public methods calling database
ragix-ast search . "type:method visibility:public calls:database.query"
# Find all test methods
ragix-ast search . "type:method @Test"
# Find classes extending BaseRepository
ragix-ast search . "type:class extends:BaseRepository"
# Find non-abstract service classes
ragix-ast search . "type:class extends:BaseService ! name:*Abstract*"See Query Language for full syntax.
Generate dependency graph visualizations.
Usage:
ragix-ast graph <path> [OPTIONS]Options:
| Option | Description | Default |
|---|---|---|
--format FMT |
Output format (html, dot, mermaid, json) |
html |
--output FILE |
Output file path | stdout |
--cluster |
Group by file/package | Enabled |
--max-nodes N |
Limit nodes for performance | 1000 |
Examples:
# Interactive HTML visualization
ragix-ast graph ./src --format html --output deps.html
# Graphviz DOT format (pipe to dot)
ragix-ast graph ./src --format dot | dot -Tpng -o graph.png
# Mermaid for documentation
ragix-ast graph ./src --format mermaid > deps.md
# JSON for custom processing
ragix-ast graph ./src --format json > graph.jsonCalculate professional code metrics.
Usage:
ragix-ast metrics <path> [OPTIONS]Options:
| Option | Description | Default |
|---|---|---|
--json |
Output as JSON | Disabled |
--csv |
Output as CSV | Disabled |
Metrics Reported:
| Category | Metrics |
|---|---|
| Overview | Files, Lines of Code, Code Lines, Comment Lines |
| Complexity | Cyclomatic Complexity (total, average, max) |
| Maintainability | Maintainability Index (0-100) |
| Technical Debt | Estimated hours to fix issues |
| Coupling | Afferent (Ca), Efferent (Ce), Instability (I) |
| Cycles | Number of circular dependencies |
Example:
ragix-ast metrics ./srcOutput:
Code Metrics Report: ./src
โโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Overview
Files: 150
Lines of Code: 25,432
Code Lines: 18,567
Comment Lines: 3,245
๐งฎ Complexity
Total: 1,234
Average: 3.5
Maximum: 45 (UserService.processOrder)
๐ ๏ธ Maintainability
Index: 72.5 (Good)
โฑ๏ธ Technical Debt
Estimated: 45.5 hours
๐ Coupling
Afferent (Ca): 234
Efferent (Ce): 567
Instability: 0.71
โ ๏ธ Circular Dependencies: 3 detected
- UserService โ OrderService
- AuthModule โ UserModule
- Cache โ Database
Generate a Dependency Structure Matrix (DSM) - a compact representation for analyzing architecture.
Usage:
ragix-ast matrix <path> [OPTIONS]Options:
| Option | Description | Default |
|---|---|---|
--level LEVEL |
Aggregation (class, package, file) |
package |
--output FILE |
Output HTML file | stdout |
Example:
# Package-level DSM
ragix-ast matrix ./src --level package --output matrix.html
# Class-level for detailed analysis
ragix-ast matrix ./src --level class --output class_matrix.htmlHow to Read:
- Rows: Dependent modules (who depends on others)
- Columns: Depended-upon modules (who is depended upon)
- Cell values: Number of dependencies
- Colors: Intensity indicates coupling strength
- Diagonal: Self-dependencies (cycles if non-zero)
Generate an ego-centric visualization showing a central symbol and its dependencies radiating outward.
Usage:
ragix-ast radial <path> [OPTIONS]Options:
| Option | Description | Default |
|---|---|---|
--focal SYMBOL |
Central symbol to focus on | Most connected |
--levels N |
Dependency depth levels | 3 |
--output FILE |
Output HTML file | stdout |
Example:
# Explore UserService dependencies
ragix-ast radial ./src --focal UserService --output user_deps.html
# Auto-select most connected class
ragix-ast radial ./src --levels 2 --output core_deps.htmlFind the most complex and problematic code.
Usage:
ragix-ast hotspots <path> [OPTIONS]Options:
| Option | Description | Default |
|---|---|---|
--top N |
Number of hotspots to show | 20 |
--metric METRIC |
Sort by metric (complexity, size, coupling) |
complexity |
Example:
ragix-ast hotspots ./src --top 10Output:
Top 10 Complexity Hotspots
โโโโโโโโโโโโโโโโโโโโโโโโโ
1. UserService.processOrder (CC: 45)
๐ src/services/user.py:234
2. PaymentHandler.validate (CC: 38)
๐ src/handlers/payment.py:89
3. OrderValidator.checkRules (CC: 32)
๐ src/validators/order.py:156
...
Detect and list circular dependencies.
Usage:
ragix-ast cycles <path>Example:
ragix-ast cycles ./srcOutput:
Circular Dependencies Detected: 3
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Cycle 1 (length: 2):
UserService โ OrderService โ UserService
Cycle 2 (length: 3):
AuthModule โ UserModule โ SessionModule โ AuthModule
Cycle 3 (length: 2):
Cache โ Database โ Cache
Parse Maven POM files for Java project analysis.
Usage:
ragix-ast maven <path>Example:
ragix-ast maven ./pom.xml
ragix-ast maven ./ # Scans for pom.xml filesQuery a SonarQube/SonarCloud instance.
Usage:
ragix-ast sonar <project_key> [OPTIONS]Options:
| Option | Description | Default |
|---|---|---|
--url URL |
SonarQube server URL | SONAR_URL env |
--token TOKEN |
Authentication token | SONAR_TOKEN env |
Example:
export SONAR_URL="https://sonarcloud.io"
export SONAR_TOKEN="your_token"
ragix-ast sonar my-project-keyThe RAGIX query language enables powerful symbol searches.
| Predicate | Description | Example |
|---|---|---|
type:<type> |
Symbol type | type:class, type:method |
name:<pattern> |
Name pattern (supports *) |
name:*Service* |
extends:<pattern> |
Parent class | extends:BaseEntity |
implements:<pattern> |
Interface | implements:Serializable |
calls:<pattern> |
Called function | calls:database.* |
@<annotation> |
Has annotation | @Test, @Override |
visibility:<vis> |
Access level | visibility:public |
! <predicate> |
Negation | ! type:method |
class- Classesinterface- Interfacesmethod- Class methodsfunction- Standalone functionsfield- Class fields/attributesenum- Enumerations
Predicates are ANDed together by default:
# Find public methods in Service classes
ragix-ast search . "type:method visibility:public name:*Service*"
# Find abstract classes that extend BaseEntity
ragix-ast search . "type:class extends:BaseEntity name:Abstract*"Self-contained HTML files with D3.js visualizations. Features:
- Zoom and pan
- Node filtering
- Search highlighting
- Tooltip details
- Package grouping
Standard DOT format for custom rendering:
ragix-ast graph ./src --format dot | dot -Tsvg -o graph.svgMarkdown-embeddable diagrams:
ragix-ast graph ./src --format mermaid >> README.mdStructured data for custom processing:
ragix-ast graph ./src --format json | jq '.nodes | length'#!/bin/bash
# quality_check.sh
# Check for high complexity
HOTSPOTS=$(ragix-ast hotspots ./src --top 5 --metric complexity)
MAX_CC=$(echo "$HOTSPOTS" | grep -oP 'CC: \K\d+' | head -1)
if [ "$MAX_CC" -gt 30 ]; then
echo "FAIL: Maximum complexity ($MAX_CC) exceeds threshold (30)"
exit 1
fi
# Check for cycles
CYCLES=$(ragix-ast cycles ./src 2>&1)
if echo "$CYCLES" | grep -q "Detected:"; then
echo "FAIL: Circular dependencies found"
exit 1
fi
echo "PASS: Code quality checks passed"# Generate all visualizations for documentation
ragix-ast graph ./src --format html --output docs/dependency_graph.html
ragix-ast matrix ./src --level package --output docs/dsm.html
ragix-ast metrics ./src --json > docs/metrics.json
ragix-ast hotspots ./src --top 20 > docs/hotspots.txtimport subprocess
import json
# Get metrics as JSON
result = subprocess.run(
["ragix-ast", "metrics", "./src", "--json"],
capture_output=True, text=True
)
metrics = json.loads(result.stdout)
# Check maintainability
if metrics["maintainability"]["index"] < 50:
print("Warning: Low maintainability score!")For more information, see the CLI Guide or run ragix-ast --help.