# Codebase Scanner Usage Examples
## Basic Usage
### 1. Scan a TypeScript Project
```bash
# Basic scan
npm run scan /path/to/your/typescript-project
# Example output:
π CodeRAG Scanner v1.0.0
π Project: /Users/dev/my-typescript-app
π Connected to Neo4j: bolt://localhost:7687
π Validating project structure...
π Project Analysis:
β
package.json found - Node.js project detected
β
tsconfig.json found - TypeScript project detected
βοΈ Scan Configuration:
Languages: typescript, javascript
Include tests: no
Exclude paths: node_modules, dist, build
π Starting codebase scan...
π Found 45 source files
π Processed 45/45 files
πΎ Storing 127 entities and 89 relationships...
π₯ Storing entities...
π Storing relationships...
π CODEBASE SCAN REPORT
βββββββββββββββββββββββ
π STATISTICS
Files processed: 45
Entities found: 127
Relationships found: 89
Processing time: 3.24s
ποΈ ENTITY BREAKDOWN
β’ class: 23
β’ method: 67
β’ interface: 12
β’ field: 18
β’ module: 7
π RELATIONSHIP BREAKDOWN
β’ contains: 85
β’ implements: 15
β’ extends: 8
β’ belongs_to: 45
β
Scan completed successfully!
```
### 2. Scan with Quality Analysis
```bash
npm run scan /path/to/project -- --analyze
# Additional output after scan:
π¬ Running quality analysis...
π QUALITY ANALYSIS RESULTS
βββββββββββββββββββββββββββ
π Project Metrics:
Total Classes: 23
Total Methods: 67
Total Packages: 7
Average Coupling: 4.2
Average RFC: 8.7
Average DIT: 1.8
β οΈ Issues Found: 3
1. [HIGH] God class detected: UserService (25 methods, 12 couplings)
2. [HIGH] Highly coupled class: DatabaseManager (18 couplings)
3. [MEDIUM] Circular dependency detected in package: com.example.utils
π‘ Recommendations:
β’ Use MCP tools to explore specific classes and metrics
β’ Focus on high-coupling classes and god classes first
β’ Consider refactoring classes with high CBO (>10) or RFC (>50)
```
## Advanced Usage
### 3. Clear and Rescan
```bash
# Clear this project's data before scanning
npm run scan /path/to/project -- --clear-graph --analyze
# Clear ALL database data before scanning (all projects)
npm run scan /path/to/project -- --clear-all --analyze
```
### 4. Include Test Files
```bash
# Include test files in the analysis
npm run scan /path/to/project -- --include-tests
```
### 5. Project Validation Only
```bash
# Validate project structure without scanning
npm run scan validate /path/to/project
# Output:
π Project: /Users/dev/my-project
β
Valid: Yes
π€ Languages detected: typescript, javascript
π Analysis:
β
package.json found - Node.js project detected
β
tsconfig.json found - TypeScript project detected
π‘ Consider organizing code in a src/ directory for better analysis
```
### 6. Custom Language Selection
```bash
# Scan only JavaScript files
npm run scan /path/to/project -- --languages javascript
# Scan multiple languages (when parsers are available)
npm run scan /path/to/project -- --languages typescript,javascript,java
```
## Integration Workflow
### Complete Analysis Workflow
```bash
# 1. Validate project structure
npm run scan validate /path/to/project
# 2. Clear previous data and scan with analysis
npm run scan /path/to/project -- --clear-graph --analyze --output-report
# 3. Start CodeRAG server
npm start
# 4. Use MCP tools to explore results
mcp call get_project_summary
mcp call find_architectural_issues
mcp call calculate_ck_metrics --arguments '{"class_id": "com.example.UserService"}'
```
## Supported File Types
### Currently Supported
- **TypeScript**: `.ts`, `.tsx`
- **JavaScript**: `.js`, `.jsx`
### Planned Support
- **Java**: `.java`
- **Python**: `.py`
- **C#**: `.cs`
## Common Use Cases
### 1. Legacy Codebase Analysis
```bash
# Analyze a large legacy codebase
npm run scan /path/to/legacy-project -- --clear-graph --analyze --verbose
# Focus on finding architectural issues
mcp call find_architectural_issues
```
### 2. Code Review Preparation
```bash
# Before major refactoring
npm run scan /path/to/project -- --analyze --output-report
# Identify high-risk areas
mcp call calculate_package_metrics --arguments '{"package_name": "com.example.core"}'
```
### 3. Microservices Architecture Analysis
```bash
# Scan each service separately (clear all data for first service)
npm run scan /path/to/service-a -- --clear-all
npm run scan /path/to/service-b
npm run scan /path/to/service-c
# Analyze inter-service dependencies
mcp call find_classes_calling_method --arguments '{"method_name": "sendNotification"}'
```
## Troubleshooting
### Common Issues
1. **"No source files found"**: Check project path and language selection
2. **"Parse errors"**: Use `--verbose` flag to see detailed error messages
3. **Neo4j connection issues**: Verify Neo4j is running and credentials are correct
### Performance Tips
- Use `--exclude` to skip large generated directories
- Consider scanning in smaller batches for very large codebases
- Use `--include-tests` only when needed for complete analysis
## Output Files
### Scan Report
When using `--output-report`, a file `coderag-scan-report.txt` is created in the project directory with:
- Complete scan statistics
- Entity and relationship breakdowns
- Quality analysis results
- Identified issues and recommendations