Guides

Improving Code Quality

Workflow for measuring and improving code quality

This guide walks through a practical workflow for using Stellarion to measure and improve your code quality.

Step 1: Assess Current State

Start by getting an overview of your codebase health:

Analyze the code quality of this project.
Give me an overview of complexity and any issues.

This provides:

  • Overall complexity statistics
  • Files with high complexity
  • Maintainability scores
  • Identified issues

Step 2: Identify Problem Areas

Focus on the most problematic code:

Show me the 10 most complex functions in this project.
Which files have the lowest maintainability scores?
Are there any circular dependencies?

Step 3: Prioritize

Not all issues are equal. Prioritize based on:

Severity + Frequency

Find refactoring opportunities and prioritize by severity.
Focus on code that's frequently modified.

Business Impact

Focus on critical paths:

Analyze the complexity of src/api/ and src/core/

Quick Wins

Start with high-impact, low-effort items:

Find refactoring opportunities with low effort and high priority.

Step 4: Understand Before Changing

Before refactoring, understand the code:

Check Dependencies

What files depend on src/services/userService.ts?

Assess Impact

What would be affected if I refactor this function?

Review Implementation

Show me the implementation of the processOrder function.

Step 5: Make Improvements

Work on one issue at a time:

Break Up Complex Functions

This function has complexity of 35.
Help me break it into smaller functions.

Reduce Duplication

I see duplication between fileA.ts and fileB.ts.
Help me create a shared utility.

Simplify Nested Code

This function has deep nesting.
Help me flatten it using early returns.

Step 6: Verify Improvements

After changes, verify the improvement:

What's the complexity of processOrder now?
Re-analyze the quality of src/services/

Step 7: Track Progress

Generate reports to track improvement over time:

Generate a quality report and save it to docs/quality-report.md

Compare with previous reports:

How does this compare to last month's quality report?

Quality Targets

MetricTargetAction
Cyclomatic complexity< 15Refactor if higher
Cognitive complexity< 10Simplify if higher
File size< 300 linesSplit if larger
Function parameters< 5Consider object parameter

Establish Team Standards

Document your quality standards and use Stellarion to enforce them:

Check if any functions exceed our complexity threshold of 15.

Continuous Improvement

Regular Reviews

  • Weekly: Quick complexity check
  • Sprint: Detailed quality analysis
  • Monthly: Full technical debt review

Pre-commit Checks

Analyze the complexity of the files I modified.
Flag anything over our threshold.

Code Review Integration

Include quality metrics in code reviews:

Analyze the quality of the code in this PR.