Smart Static Analysis Tool for Intelligent Code Splitting
SMART-SPLIT is a sophisticated static analysis framework designed to analyze Go codebases, extract function dependencies, and provide intelligent insights for code modularization and splitting decisions. The tool combines AST (Abstract Syntax Tree) analysis with graph database storage and visualization capabilities.
- AST-based Code Analysis: Deep analysis of Go source code using Go's built-in AST parser
- Function Dependency Mapping: Identifies and tracks function calls and dependencies across files
- Semantic Tagging: Automatically categorizes functions based on naming patterns and context
- Graph Database Integration: Stores analysis results in KuzuDB for efficient querying
- Cross-file Dependency Tracking: Detects dependencies that span multiple files and packages
- JSON Output: Structured output format for further processing and integration
- Visualization Support: Tools for visualizing function dependencies and code structure
The system consists of three main components:
- AST Analyzer (Go): Parses Go source code and extracts function metadata and dependencies
- Graph Database (KuzuDB): Stores and manages the dependency graph
- Visualizer (Python): Provides analysis and visualization capabilities
smart-split/
├── README.md
├── docs/
│ └── smart-split-architecture.png
└── static-analyzer/
├── ast-analyzer/ # Go-based AST analysis tool
│ ├── main.go
│ ├── go.mod
│ └── go.sum
├── output/ # Analysis output files
│ ├── static_analysis_outputv1.json
│ └── local_b_static_analysis_output.json
└── visualizer/ # Python-based visualization tools
├── main.py
├── visualize.py
├── requirements.txt
└── graph_db/ # KuzuDB database files
- Go 1.24.1 or higher
- Python 3.8+
- KuzuDB Python package
-
Clone the repository:
git clone <repository-url> cd smart-split
-
Set up the AST Analyzer:
cd static-analyzer/ast-analyzer go mod tidy -
Set up the Python environment:
cd ../visualizer pip install -r requirements.txt
Navigate to the AST analyzer directory and run the analysis:
cd static-analyzer/ast-analyzer
go run main.goThis will:
- Parse all Go files in the target directory
- Extract function metadata (name, parameters, return types, comments)
- Identify function dependencies
- Generate semantic tags for functions
- Output results to
static_analysis_output.json
cd ../visualizer
python main.pyThis will:
- Initialize KuzuDB database
- Create function and dependency tables
- Load the JSON analysis results into the graph database
python visualize.pyThis provides:
- Graph visualization of function dependencies
- Query capabilities for exploring the codebase structure
- Analysis of cross-file and cross-package dependencies
The static analysis generates JSON output with the following structure:
{
"functions": [
{
"id": "uuid",
"name": "functionName",
"exported": true,
"receiver": "ReceiverType",
"file": "/path/to/file.go",
"line": 42,
"params": ["string", "int"],
"returns": ["error"],
"semantic_tag": "Handler",
"comments": "Function documentation"
}
],
"dependencies": [
{
"id": "uuid",
"from": "function-id-1",
"to": "function-id-2",
"type": "calls",
"cross_file": true
}
]
}The analyzer automatically assigns semantic tags to functions based on naming patterns:
- Handler: Functions ending with "Handler"
- Controller: Functions in controller packages
- Service: Business logic functions
- Repository: Data access functions
- Middleware: HTTP middleware functions
- General: Default category for other functions
- Code Modularization: Identify tightly coupled functions for better module organization
- Microservice Extraction: Find logical boundaries for splitting monolithic applications
- Dependency Analysis: Understand code dependencies before refactoring
- Architecture Visualization: Generate visual representations of code structure
- Code Quality Assessment: Identify highly connected functions that may need refactoring
Modify the target directory in ast-analyzer/main.go:
dir := "/path/to/your/go/project"Customize the output file path:
outputFile := "./your-output-file.json"- Support for additional programming languages
- Interactive web-based visualization
- Integration with popular IDEs
- Automated splitting recommendations
- Performance metrics and complexity analysis
- Support for distributed systems analysis
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions, issues, or contributions, please:
- Open an issue on GitHub
- Contact the development team
- Check the documentation in the
docs/directory
Built with ❤️ for better code organization and intelligent software architecture decisions.
