|
| 1 | +# Code Quality Refactor |
| 2 | + |
| 3 | +> Comprehensive code quality analysis for the pyplots repository. Checks readability, performance, code smells, consistency, and modernization opportunities across all components. |
| 4 | +
|
| 5 | +## Context |
| 6 | + |
| 7 | +@CLAUDE.md |
| 8 | +@pyproject.toml |
| 9 | + |
| 10 | +## Analysis Scope |
| 11 | + |
| 12 | +Analyze the following areas systematically. For each area, identify: |
| 13 | +- **Code Smells**: Dead code, duplication, overly complex functions, god classes |
| 14 | +- **Readability**: Unclear naming, missing/outdated comments, inconsistent formatting |
| 15 | +- **Performance**: Inefficient patterns, N+1 queries, unnecessary computations |
| 16 | +- **Modernization**: Deprecated APIs, old Python patterns, outdated dependencies |
| 17 | +- **Consistency**: Naming conventions, import styles, error handling patterns |
| 18 | +- **Type Safety**: Missing type hints, incorrect types, Any overuse |
| 19 | +- **Test Quality**: Missing tests, flaky tests, poor assertions |
| 20 | + |
| 21 | +## Discover Structure |
| 22 | + |
| 23 | +```bash |
| 24 | +# Overview of repository structure |
| 25 | +find . -type f -name "*.py" | grep -E "^\./(api|core|automation|tests)/" | head -80 |
| 26 | + |
| 27 | +# Frontend structure |
| 28 | +find ./app/src -type f -name "*.ts" -o -name "*.tsx" 2>/dev/null | head -40 |
| 29 | + |
| 30 | +# Workflow files |
| 31 | +ls -la .github/workflows/*.yml 2>/dev/null |
| 32 | + |
| 33 | +# Prompt files |
| 34 | +find ./prompts -type f -name "*.md" 2>/dev/null |
| 35 | + |
| 36 | +# Documentation |
| 37 | +find ./docs -type f -name "*.md" 2>/dev/null |
| 38 | +``` |
| 39 | + |
| 40 | +## Run Quality Checks |
| 41 | + |
| 42 | +```bash |
| 43 | +# Linting issues |
| 44 | +uv run ruff check . |
| 45 | + |
| 46 | +# Format check (dry-run) |
| 47 | +uv run ruff format . --check --diff |
| 48 | +``` |
| 49 | + |
| 50 | +## Analyze Backend (api/) |
| 51 | + |
| 52 | +Check for: |
| 53 | +- Router organization and REST conventions |
| 54 | +- Dependency injection patterns |
| 55 | +- Error handling consistency |
| 56 | +- Response schema completeness |
| 57 | +- Async/await correctness |
| 58 | +- Caching strategies |
| 59 | + |
| 60 | +```bash |
| 61 | +ls -la api/*.py api/**/*.py 2>/dev/null |
| 62 | +``` |
| 63 | + |
| 64 | +## Analyze Core Logic (core/) |
| 65 | + |
| 66 | +Check for: |
| 67 | +- Repository pattern implementation |
| 68 | +- Database model design |
| 69 | +- Configuration management |
| 70 | +- Utility function organization |
| 71 | +- Type definitions |
| 72 | + |
| 73 | +```bash |
| 74 | +ls -la core/*.py core/**/*.py 2>/dev/null |
| 75 | +``` |
| 76 | + |
| 77 | +## Analyze Automation (automation/) |
| 78 | + |
| 79 | +Check for: |
| 80 | +- Script modularity |
| 81 | +- Error handling in workflows |
| 82 | +- CLI argument parsing |
| 83 | +- Logging consistency |
| 84 | + |
| 85 | +```bash |
| 86 | +ls -la automation/**/*.py 2>/dev/null |
| 87 | +``` |
| 88 | + |
| 89 | +## Analyze Frontend (app/src/) |
| 90 | + |
| 91 | +Check for: |
| 92 | +- Component structure and reusability |
| 93 | +- Hook patterns and custom hooks |
| 94 | +- TypeScript strictness (no `any`, proper interfaces) |
| 95 | +- Performance (memo, useCallback only where truly needed) |
| 96 | +- Accessibility (aria-labels, keyboard navigation, focus management) |
| 97 | +- Consistent error handling and error boundaries |
| 98 | +- Loading states and skeletons |
| 99 | +- Unused imports and dead code |
| 100 | + |
| 101 | +```bash |
| 102 | +ls -la app/src/**/*.tsx app/src/**/*.ts 2>/dev/null | head -30 |
| 103 | +``` |
| 104 | + |
| 105 | +## Analyze Tests (tests/) |
| 106 | + |
| 107 | +Check for: |
| 108 | +- Test coverage gaps |
| 109 | +- Fixture organization |
| 110 | +- Mock patterns |
| 111 | +- Assertion quality |
| 112 | +- Test naming conventions |
| 113 | + |
| 114 | +```bash |
| 115 | +find tests -name "*.py" -type f | head -30 |
| 116 | +``` |
| 117 | + |
| 118 | +## Analyze GitHub Workflows (.github/workflows/) |
| 119 | + |
| 120 | +Check for: |
| 121 | +- Workflow consistency and naming |
| 122 | +- Job dependencies and parallelization |
| 123 | +- Secret handling and security |
| 124 | +- Error handling and failure modes |
| 125 | +- Concurrency settings |
| 126 | +- Reusable workflows vs duplication |
| 127 | +- Environment variable consistency |
| 128 | +- Trigger conditions (labels, paths, branches) |
| 129 | + |
| 130 | +```bash |
| 131 | +ls -la .github/workflows/*.yml |
| 132 | +``` |
| 133 | + |
| 134 | +## Analyze AI Prompts (prompts/) |
| 135 | + |
| 136 | +Check for: |
| 137 | +- Prompt clarity and structure |
| 138 | +- Consistency across prompt files |
| 139 | +- Outdated instructions or references |
| 140 | +- Missing edge cases |
| 141 | +- Template completeness |
| 142 | +- Library-specific rules alignment |
| 143 | + |
| 144 | +```bash |
| 145 | +find prompts -name "*.md" -o -name "*.yaml" | sort |
| 146 | +``` |
| 147 | + |
| 148 | +## Analyze Documentation (docs/) |
| 149 | + |
| 150 | +Check for: |
| 151 | +- Outdated information vs actual code |
| 152 | +- Missing documentation for new features |
| 153 | +- Broken internal links |
| 154 | +- Inconsistent formatting |
| 155 | +- Sync with CLAUDE.md |
| 156 | + |
| 157 | +```bash |
| 158 | +find docs -name "*.md" | sort |
| 159 | +``` |
| 160 | + |
| 161 | +## Cross-Check: Consistency |
| 162 | + |
| 163 | +Verify alignment across components: |
| 164 | +- Do workflows reference existing prompt files? |
| 165 | +- Are library names consistent across `prompts/library/`, `core/constants.py`, workflows? |
| 166 | +- Do workflow labels match documentation? |
| 167 | +- Are schema definitions in sync between API and frontend types? |
| 168 | + |
| 169 | +```bash |
| 170 | +# Check prompt references in workflows |
| 171 | +grep -r "prompts/" .github/workflows/ 2>/dev/null | head -20 |
| 172 | + |
| 173 | +# Library definitions |
| 174 | +ls prompts/library/ 2>/dev/null | sed 's/.md//' | sort |
| 175 | +grep -E "SUPPORTED_LIBRARIES|LIBRARIES" core/constants.py 2>/dev/null | head -5 |
| 176 | +``` |
| 177 | + |
| 178 | +## Run Test Suite |
| 179 | + |
| 180 | +```bash |
| 181 | +# Quick test run to check for failures |
| 182 | +uv run pytest tests/unit -x -q --tb=no 2>/dev/null | tail -20 |
| 183 | +``` |
| 184 | + |
| 185 | +## Output Format |
| 186 | + |
| 187 | +After analysis, provide a structured report: |
| 188 | + |
| 189 | +### 1. Critical Issues (Must Fix) |
| 190 | +Issues that could cause bugs, security problems, or break functionality. |
| 191 | + |
| 192 | +### 2. High Priority (Should Fix) |
| 193 | +Code smells, performance issues, or maintainability concerns. |
| 194 | + |
| 195 | +### 3. Medium Priority (Consider) |
| 196 | +Modernization opportunities, style improvements, minor inconsistencies. |
| 197 | + |
| 198 | +### 4. Low Priority (Nice to Have) |
| 199 | +Minor improvements, documentation updates, cosmetic changes. |
| 200 | + |
| 201 | +### 5. Positive Patterns |
| 202 | +Good practices found that should be maintained or expanded. |
| 203 | + |
| 204 | +For each issue, provide: |
| 205 | +- **Location**: File path and line number |
| 206 | +- **Problem**: Clear description of the issue |
| 207 | +- **Impact**: Why this matters |
| 208 | +- **Solution**: Specific fix recommendation |
| 209 | +- **Effort**: Low/Medium/High |
| 210 | + |
| 211 | +## Exclusions |
| 212 | + |
| 213 | +Do NOT flag: |
| 214 | +- Plot implementations in `plots/` (AI-generated, different style rules) |
| 215 | +- Generated files or lock files (`uv.lock`, `yarn.lock`, etc.) |
| 216 | +- Third-party code |
| 217 | +- Issues already tracked in pyproject.toml exclusions |
0 commit comments