Skip to content

Commit 012ce27

Browse files
authored
Add files via upload
1 parent 8ea7976 commit 012ce27

35 files changed

+18734
-0
lines changed
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
# CodeGen Analyzer
2+
3+
The CodeGen Analyzer module provides comprehensive static analysis capabilities for codebases, focusing on code quality, dependencies, structure, and visualization. It serves as a backend API that can be used by frontend applications to analyze repositories.
4+
5+
## Architecture
6+
7+
The analyzer system is built with a modular plugin-based architecture:
8+
9+
```
10+
analyzers/
11+
├── api.py # Main API endpoints for frontend integration
12+
├── analyzer.py # Plugin-based analyzer system
13+
├── issues.py # Issue tracking and management
14+
├── code_quality.py # Code quality analysis
15+
├── dependencies.py # Dependency analysis
16+
├── models/
17+
│ └── analysis_result.py # Data models for analysis results
18+
├── context/ # Code context management
19+
├── visualization/ # Visualization support
20+
└── resolution/ # Issue resolution tools
21+
```
22+
23+
## Core Components
24+
25+
### 1. API Interface (`api.py`)
26+
27+
The main entry point for frontend applications. Provides REST-like endpoints for:
28+
- Codebase analysis
29+
- PR analysis
30+
- Dependency visualization
31+
- Issue reporting
32+
- Code quality assessment
33+
34+
### 2. Analyzer System (`analyzer.py`)
35+
36+
Plugin-based system that coordinates different types of analysis:
37+
- Code quality analysis (complexity, maintainability)
38+
- Dependency analysis (imports, cycles, coupling)
39+
- PR impact analysis
40+
- Type checking and error detection
41+
42+
### 3. Issue Tracking (`issues.py`)
43+
44+
Comprehensive issue model with:
45+
- Severity levels (critical, error, warning, info)
46+
- Categories (dead code, complexity, dependency, etc.)
47+
- Location information and suggestions
48+
- Filtering and grouping capabilities
49+
50+
### 4. Dependency Analysis (`dependencies.py`)
51+
52+
Analysis of codebase dependencies:
53+
- Import dependencies between modules
54+
- Circular dependency detection
55+
- Module coupling analysis
56+
- External dependencies tracking
57+
- Call graphs and class hierarchies
58+
59+
### 5. Code Quality Analysis (`code_quality.py`)
60+
61+
Analysis of code quality aspects:
62+
- Dead code detection (unused functions, variables)
63+
- Complexity metrics (cyclomatic, cognitive)
64+
- Parameter checking (types, usage)
65+
- Style issues and maintainability
66+
67+
## Using the API
68+
69+
### Setup
70+
71+
```python
72+
from codegen_on_oss.analyzers.api import CodegenAnalyzerAPI
73+
74+
# Create API instance with repository
75+
api = CodegenAnalyzerAPI(repo_path="/path/to/repo")
76+
# OR
77+
api = CodegenAnalyzerAPI(repo_url="https://github.com/owner/repo")
78+
```
79+
80+
### Analyzing a Codebase
81+
82+
```python
83+
# Run comprehensive analysis
84+
results = api.analyze_codebase()
85+
86+
# Run specific analysis types
87+
results = api.analyze_codebase(analysis_types=["code_quality", "dependency"])
88+
89+
# Force refresh of cached analysis
90+
results = api.analyze_codebase(force_refresh=True)
91+
```
92+
93+
### Analyzing a PR
94+
95+
```python
96+
# Analyze a specific PR
97+
pr_results = api.analyze_pr(pr_number=123)
98+
99+
# Get PR impact visualization
100+
impact_viz = api.get_pr_impact(pr_number=123, format="json")
101+
```
102+
103+
### Getting Issues
104+
105+
```python
106+
# Get all issues
107+
all_issues = api.get_issues()
108+
109+
# Get issues by severity
110+
critical_issues = api.get_issues(severity="critical")
111+
error_issues = api.get_issues(severity="error")
112+
113+
# Get issues by category
114+
dependency_issues = api.get_issues(category="dependency_cycle")
115+
```
116+
117+
### Getting Visualizations
118+
119+
```python
120+
# Get module dependency graph
121+
module_deps = api.get_module_dependencies(format="json")
122+
123+
# Get function call graph
124+
call_graph = api.get_function_call_graph(
125+
function_name="main",
126+
depth=3,
127+
format="json"
128+
)
129+
130+
# Export visualization to file
131+
api.export_visualization(call_graph, format="html", filename="call_graph.html")
132+
```
133+
134+
### Common Analysis Patterns
135+
136+
```python
137+
# Find dead code
138+
api.analyze_codebase(analysis_types=["code_quality"])
139+
dead_code = api.get_issues(category="dead_code")
140+
141+
# Find circular dependencies
142+
api.analyze_codebase(analysis_types=["dependency"])
143+
circular_deps = api.get_circular_dependencies()
144+
145+
# Find parameter issues
146+
api.analyze_codebase(analysis_types=["code_quality"])
147+
param_issues = api.get_parameter_issues()
148+
```
149+
150+
## REST API Endpoints
151+
152+
The analyzer can be exposed as REST API endpoints for integration with frontend applications:
153+
154+
### Codebase Analysis
155+
156+
```
157+
POST /api/analyze/codebase
158+
{
159+
"repo_path": "/path/to/repo",
160+
"analysis_types": ["code_quality", "dependency"]
161+
}
162+
```
163+
164+
### PR Analysis
165+
166+
```
167+
POST /api/analyze/pr
168+
{
169+
"repo_path": "/path/to/repo",
170+
"pr_number": 123
171+
}
172+
```
173+
174+
### Visualization
175+
176+
```
177+
POST /api/visualize
178+
{
179+
"repo_path": "/path/to/repo",
180+
"viz_type": "module_dependencies",
181+
"params": {
182+
"layout": "hierarchical",
183+
"format": "json"
184+
}
185+
}
186+
```
187+
188+
### Issues
189+
190+
```
191+
GET /api/issues?severity=error&category=dependency_cycle
192+
```
193+
194+
## Implementation Example
195+
196+
For a web application exposing these endpoints with Flask:
197+
198+
```python
199+
from flask import Flask, request, jsonify
200+
from codegen_on_oss.analyzers.api import (
201+
api_analyze_codebase,
202+
api_analyze_pr,
203+
api_get_visualization,
204+
api_get_static_errors
205+
)
206+
207+
app = Flask(__name__)
208+
209+
@app.route("/api/analyze/codebase", methods=["POST"])
210+
def analyze_codebase():
211+
data = request.json
212+
result = api_analyze_codebase(
213+
repo_path=data.get("repo_path"),
214+
analysis_types=data.get("analysis_types")
215+
)
216+
return jsonify(result)
217+
218+
@app.route("/api/analyze/pr", methods=["POST"])
219+
def analyze_pr():
220+
data = request.json
221+
result = api_analyze_pr(
222+
repo_path=data.get("repo_path"),
223+
pr_number=data.get("pr_number")
224+
)
225+
return jsonify(result)
226+
227+
@app.route("/api/visualize", methods=["POST"])
228+
def visualize():
229+
data = request.json
230+
result = api_get_visualization(
231+
repo_path=data.get("repo_path"),
232+
viz_type=data.get("viz_type"),
233+
params=data.get("params", {})
234+
)
235+
return jsonify(result)
236+
237+
@app.route("/api/issues", methods=["GET"])
238+
def get_issues():
239+
repo_path = request.args.get("repo_path")
240+
severity = request.args.get("severity")
241+
category = request.args.get("category")
242+
243+
api = create_api(repo_path=repo_path)
244+
return jsonify(api.get_issues(severity=severity, category=category))
245+
246+
if __name__ == "__main__":
247+
app.run(debug=True)
248+
```
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"""
2+
Codebase Analysis Module
3+
4+
This package provides comprehensive codebase analysis tools for static code analysis,
5+
quality checking, dependency analysis, and PR validation. It's designed to be used
6+
as an API backend for frontend applications.
7+
"""
8+
9+
# Main API interface
10+
from codegen_on_oss.analyzers.api import (
11+
CodegenAnalyzerAPI,
12+
create_api,
13+
api_analyze_codebase,
14+
api_analyze_pr,
15+
api_get_visualization,
16+
api_get_static_errors
17+
)
18+
19+
# Modern analyzer architecture
20+
from codegen_on_oss.analyzers.analyzer import (
21+
AnalyzerManager,
22+
AnalyzerPlugin,
23+
AnalyzerRegistry,
24+
CodeQualityPlugin,
25+
DependencyPlugin
26+
)
27+
28+
# Issue tracking system
29+
from codegen_on_oss.analyzers.issues import (
30+
Issue,
31+
IssueCollection,
32+
IssueSeverity,
33+
AnalysisType,
34+
IssueCategory,
35+
CodeLocation
36+
)
37+
38+
# Analysis result models
39+
from codegen_on_oss.analyzers.models.analysis_result import (
40+
AnalysisResult,
41+
CodeQualityResult,
42+
DependencyResult,
43+
PrAnalysisResult
44+
)
45+
46+
# Core analysis modules
47+
from codegen_on_oss.analyzers.code_quality import CodeQualityAnalyzer
48+
from codegen_on_oss.analyzers.dependencies import DependencyAnalyzer
49+
50+
# Legacy analyzer interfaces (for backward compatibility)
51+
from codegen_on_oss.analyzers.base_analyzer import BaseCodeAnalyzer
52+
from codegen_on_oss.analyzers.codebase_analyzer import CodebaseAnalyzer
53+
from codegen_on_oss.analyzers.error_analyzer import CodebaseAnalyzer as ErrorAnalyzer
54+
55+
__all__ = [
56+
# Main API
57+
'CodegenAnalyzerAPI',
58+
'create_api',
59+
'api_analyze_codebase',
60+
'api_analyze_pr',
61+
'api_get_visualization',
62+
'api_get_static_errors',
63+
64+
# Modern architecture
65+
'AnalyzerManager',
66+
'AnalyzerPlugin',
67+
'AnalyzerRegistry',
68+
'CodeQualityPlugin',
69+
'DependencyPlugin',
70+
71+
# Issue tracking
72+
'Issue',
73+
'IssueCollection',
74+
'IssueSeverity',
75+
'AnalysisType',
76+
'IssueCategory',
77+
'CodeLocation',
78+
79+
# Analysis results
80+
'AnalysisResult',
81+
'CodeQualityResult',
82+
'DependencyResult',
83+
'PrAnalysisResult',
84+
85+
# Core analyzers
86+
'CodeQualityAnalyzer',
87+
'DependencyAnalyzer',
88+
89+
# Legacy interfaces (for backward compatibility)
90+
'BaseCodeAnalyzer',
91+
'CodebaseAnalyzer',
92+
'ErrorAnalyzer',
93+
]

0 commit comments

Comments
 (0)