Installation
Install Refactron using pip:
Refactron requires Python 3.8 or higher
Complete Workflow
Follow this workflow to get the most out of Refactron:
Login
Authenticate with Refactron to unlock AI features:
Initialize Configuration
Set up Refactron in your project: Choose a template (base, django, fastapi, or flask) to get started quickly.
Connect Repository (Optional)
Connect your GitHub repository for enhanced features:
Analyze Your Code
Run comprehensive code analysis: refactron analyze . --detailed
Get AI Suggestions
Generate AI-powered refactoring suggestions: refactron suggest myfile.py
Apply Refactoring
Preview and apply refactoring changes: # Preview changes first
refactron refactor myfile.py --preview
# Apply when ready
refactron refactor myfile.py --apply
Generate Report
Create a comprehensive technical debt report: refactron report . --format html -o report.html
Rollback if Needed
Rollback changes if something goes wrong:
Quick Commands
Analyze Code
# Analyze a file
refactron analyze mycode.py
# Analyze a directory
refactron analyze myproject/
# Get detailed analysis
refactron analyze . --detailed
Refactor Code
# Preview refactoring suggestions
refactron refactor myfile.py --preview
# Apply automated fixes
refactron autofix myfile.py --apply
# Apply specific refactoring
refactron refactor myfile.py --apply
AI-Powered Features
# Get AI suggestions
refactron suggest myfile.py --query "How can I improve this?"
# Generate documentation
refactron document myfile.py
# Use RAG for context-aware suggestions
refactron rag query "How to optimize database queries?"
Python API
Use Refactron programmatically in your Python code:
from refactron import Refactron
# Initialize Refactron
refactron = Refactron()
# Analyze code
analysis = refactron.analyze( "path/to/code.py" )
print (analysis.report())
# Preview refactoring
result = refactron.refactor( "path/to/code.py" , preview = True )
result.show_diff()
# Apply refactoring
result = refactron.refactor( "path/to/code.py" , preview = False )
Example Output
When you run an analysis, you’ll see:
Terminal Output
Python API
✓ Analyzing myproject/
Files analyzed: 25
Issues found: 12
CRITICAL (2):
- SQL injection vulnerability (line 45 )
- Hardcoded secret detected (line 78 )
ERROR (4):
- High cyclomatic complexity (line 120 )
- Deep nesting detected (line 156 )
WARNING (6):
- Magic number usage (line 23 )
- Missing type hints (line 67 )
Next Steps