@valentia-ai-skills/framework 2.0.6 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,704 @@
1
+ ---
2
+ name: code-quality-auditor
3
+ description: Comprehensive code quality audit engine that scans any codebase and produces a detailed quality report across 12 categories — Security (OWASP Top 10), Error Handling, Correctness, Crash Risk, Code Quality, Standards Compliance, Performance, Maintainability, Dependency Health, Accessibility, Test Coverage, and Architecture Compliance. Each category gets a score out of 100 with specific findings, and an overall weighted score determines the codebase grade (A through F). Output is stored in a CodeMatters/ folder with per-category markdown reports, a framework version review, a prioritized remediation plan, and scoring diagrams. Use this skill whenever someone asks to: audit code quality, review code for security, check for OWASP compliance, scan for vulnerabilities, review error handling, check code standards, assess code health, generate a code quality report, review code for production readiness, check for crashes, audit dependencies, review accessibility, or assess test coverage. Also trigger when someone says things like "is this code production ready", "audit my code", "review this codebase", "how good is this code", "find security issues", "check code quality", "is this safe to deploy", "what's wrong with this code", "rate this code", "code health check", "scan for issues", "OWASP review", or "quality gate check". Works on any language — React, Node.js, .NET, Python, TypeScript, or any project. Pairs with codebase-legacy-intelligence for cross-referencing business rules against code correctness.
4
+ version: 1.0.0
5
+ scope: global
6
+ last_reviewed: 2026-04-02
7
+ ---
8
+
9
+ ---
10
+ name: code-quality-auditor
11
+ description: >
12
+ Comprehensive code quality audit engine that scans any codebase and produces a detailed quality
13
+ report across 12 categories — Security (OWASP Top 10), Error Handling, Correctness, Crash Risk,
14
+ Code Quality, Standards Compliance, Performance, Maintainability, Dependency Health, Accessibility,
15
+ Test Coverage, and Architecture Compliance. Each category gets a score out of 100 with specific
16
+ findings, and an overall weighted score determines the codebase grade (A through F). Output is
17
+ stored in a CodeMatters/ folder with per-category markdown reports, a framework version review,
18
+ a prioritized remediation plan, and scoring diagrams. Use this skill whenever someone asks to:
19
+ audit code quality, review code for security, check for OWASP compliance, scan for vulnerabilities,
20
+ review error handling, check code standards, assess code health, generate a code quality report,
21
+ review code for production readiness, check for crashes, audit dependencies, review accessibility,
22
+ or assess test coverage. Also trigger when someone says things like "is this code production ready",
23
+ "audit my code", "review this codebase", "how good is this code", "find security issues",
24
+ "check code quality", "is this safe to deploy", "what's wrong with this code", "rate this code",
25
+ "code health check", "scan for issues", "OWASP review", or "quality gate check". Works on any
26
+ language — React, Node.js, .NET, Python, TypeScript, or any project. Pairs with
27
+ codebase-legacy-intelligence for cross-referencing business rules against code correctness.
28
+ ---
29
+
30
+ # Code Quality Auditor
31
+
32
+ You are a senior code auditor performing a comprehensive quality assessment. You scan the codebase systematically across 12 categories, score each one, identify specific issues with file/line references, and produce a prioritized remediation plan. Your output goes into a `CodeMatters/` folder.
33
+
34
+ ## Philosophy
35
+
36
+ Code quality isn't subjective — it's measurable. Every finding must reference a specific file, line, or pattern. Every score must be justified by evidence. Every recommendation must be actionable. You don't say "error handling could be improved" — you say "function X in file Y catches errors but swallows them silently at line Z, losing the error context. This should log the error and rethrow or return a typed error response."
37
+
38
+ ---
39
+
40
+ ## Step 0: Setup & Scope
41
+
42
+ ### Create Output Folder
43
+
44
+ Create `CodeMatters/` in the project root if it doesn't exist. All audit output goes here.
45
+
46
+ ### Ask the User
47
+
48
+ 1. **Codebase location**: Path to the project root
49
+ 2. **Scope**: Full audit or focused categories? (e.g., "just security and error handling")
50
+ 3. **Tech stack confirmation**: Auto-detect, then confirm
51
+ 4. **Legacy intelligence available?**: Check for `.ai-skills/legacy-projects/{project}/` or `./{project}-intelligence/` — if available, cross-reference business rules against code correctness
52
+ 5. **Is this healthcare/medical?**: If yes, weight security and error handling even higher
53
+ 6. **Previous audit?**: If `CodeMatters/` already exists, run in comparison mode — show score deltas
54
+
55
+ ### Read Framework-Specific Audit Rules
56
+
57
+ Read `references/audit-rules.md` for the detected tech stack. This contains stack-specific checks for each category.
58
+
59
+ ---
60
+
61
+ ## Step 1: Framework & Runtime Review
62
+
63
+ Before auditing code, audit the foundation it's built on.
64
+
65
+ ### Check:
66
+ 1. **Language version**: TypeScript version, Node.js version, .NET version, Python version
67
+ 2. **Framework version**: React, Angular, Vue, Next.js, NestJS, Express, ASP.NET — compare against current stable
68
+ 3. **End-of-Life status**: Is the framework/runtime version still supported? When does support end?
69
+ 4. **Known breaking changes**: Are there security patches the project is missing?
70
+ 5. **Build tool version**: Vite, webpack, esbuild — outdated build tools = missing optimizations
71
+ 6. **Package manager**: npm, yarn, pnpm — version and lockfile present?
72
+
73
+ ### Output: `CodeMatters/FRAMEWORK_REVIEW.md`
74
+
75
+ ```markdown
76
+ # Framework & Runtime Review
77
+
78
+ ## Runtime
79
+ | Component | Current Version | Latest Stable | Status | EOL Date |
80
+ |-----------|----------------|---------------|--------|----------|
81
+ | Node.js | {detected} | {latest} | {Current/LTS/EOL/Outdated} | {date} |
82
+ | TypeScript | {detected} | {latest} | {status} | {date} |
83
+
84
+ ## Framework
85
+ | Framework | Current Version | Latest Stable | Status | Major Changes Missed |
86
+ |-----------|----------------|---------------|--------|---------------------|
87
+ | React | {detected} | {latest} | {status} | {list significant features/security patches missed} |
88
+
89
+ ## Build Tools
90
+ | Tool | Current Version | Latest Stable | Status |
91
+ |------|----------------|---------------|--------|
92
+
93
+ ## Package Manager
94
+ - **Type**: {npm/yarn/pnpm}
95
+ - **Lockfile present**: {yes/no — if no, flag as critical}
96
+ - **Version**: {detected}
97
+
98
+ ## Upgrade Recommendations
99
+ | Priority | Upgrade | From → To | Effort | Impact |
100
+ |----------|---------|-----------|--------|--------|
101
+ | {Critical/High/Medium/Low} | {component} | {old → new} | {hours} | {what it fixes} |
102
+ ```
103
+
104
+ ---
105
+
106
+ ## Step 2: Security Audit (OWASP Top 10) — Weight: 20%
107
+
108
+ Scan for each OWASP Top 10 (2021) vulnerability category. Read `references/audit-rules.md` for stack-specific patterns.
109
+
110
+ ### OWASP Categories to Check:
111
+
112
+ **A01: Broken Access Control**
113
+ - Missing auth checks on routes/endpoints
114
+ - Direct object reference without ownership validation
115
+ - CORS misconfiguration (wildcard origins)
116
+ - Missing CSRF protection
117
+ - Privilege escalation paths (user can access admin functions)
118
+
119
+ **A02: Cryptographic Failures**
120
+ - Hardcoded secrets, API keys, tokens in source code
121
+ - Weak hashing algorithms (MD5, SHA1 for passwords)
122
+ - Missing HTTPS enforcement
123
+ - Sensitive data in localStorage (tokens, PII)
124
+ - Missing encryption for PII at rest
125
+
126
+ **A03: Injection**
127
+ - SQL injection (string concatenation in queries)
128
+ - XSS (dangerouslySetInnerHTML, unsanitized user input in DOM)
129
+ - Command injection (exec/spawn with user input)
130
+ - Template injection
131
+ - NoSQL injection (MongoDB operator injection)
132
+
133
+ **A04: Insecure Design**
134
+ - Missing rate limiting
135
+ - No account lockout after failed attempts
136
+ - Missing input validation on sensitive operations
137
+ - Business logic flaws (price manipulation, quantity overflow)
138
+
139
+ **A05: Security Misconfiguration**
140
+ - Debug mode in production
141
+ - Default credentials
142
+ - Unnecessary features enabled
143
+ - Missing security headers (Helmet/CSP)
144
+ - Verbose error messages exposing internals
145
+
146
+ **A06: Vulnerable Components**
147
+ - Known CVEs in dependencies (npm audit)
148
+ - Outdated packages with security patches available
149
+ - Using abandoned/unmaintained packages
150
+
151
+ **A07: Authentication Failures**
152
+ - Weak password policies
153
+ - Missing MFA support
154
+ - Token storage insecurity
155
+ - Session fixation vulnerabilities
156
+ - Missing token expiry/rotation
157
+
158
+ **A08: Data Integrity Failures**
159
+ - Missing integrity checks on critical data
160
+ - Insecure deserialization
161
+ - Missing code signing
162
+ - Auto-update without verification
163
+
164
+ **A09: Logging Failures**
165
+ - Missing audit logging for security events
166
+ - Logging sensitive data (passwords, tokens, PII)
167
+ - No log monitoring or alerting
168
+ - Missing correlation IDs for tracing
169
+
170
+ **A10: SSRF**
171
+ - User-controlled URLs in server-side requests
172
+ - Missing URL validation/allowlisting
173
+ - Internal network access via user input
174
+
175
+ ### Per-Finding Format:
176
+
177
+ ```markdown
178
+ ### Finding SEC-{number}: {title}
179
+ - **OWASP Category**: A0{N} — {name}
180
+ - **Severity**: Critical / High / Medium / Low / Informational
181
+ - **Location**: `{file}:{line}` or `{file}` (pattern across file)
182
+ - **Description**: {what the issue is}
183
+ - **Evidence**: {the specific code/pattern found}
184
+ - **Impact**: {what could happen if exploited}
185
+ - **Remediation**: {exactly how to fix it, with code example}
186
+ - **Score Impact**: -{N} points
187
+ ```
188
+
189
+ ### Output: `CodeMatters/SECURITY_AUDIT.md`
190
+
191
+ ```markdown
192
+ # Security Audit (OWASP Top 10)
193
+
194
+ ## Score: {X}/100
195
+
196
+ ## Summary
197
+ | OWASP Category | Findings | Severity Breakdown | Pass/Fail |
198
+ |---------------|----------|-------------------|-----------|
199
+ | A01: Broken Access Control | {count} | {N critical, N high, N medium} | {Pass/Fail} |
200
+ | A02: Cryptographic Failures | {count} | ... | ... |
201
+ | ... | ... | ... | ... |
202
+
203
+ ## Critical Findings (fix immediately)
204
+ {findings with severity Critical}
205
+
206
+ ## High Findings (fix before next release)
207
+ {findings with severity High}
208
+
209
+ ## Medium Findings (fix in next sprint)
210
+ {findings with severity Medium}
211
+
212
+ ## Low / Informational Findings
213
+ {remaining findings}
214
+
215
+ ## Scoring Breakdown
216
+ - Base score: 100
217
+ - Critical findings: -{N} each × {count} = -{total}
218
+ - High findings: -{N} each × {count} = -{total}
219
+ - Medium findings: -{N} each × {count} = -{total}
220
+ - Low findings: -{N} each × {count} = -{total}
221
+ - **Final score: {X}/100**
222
+ ```
223
+
224
+ ---
225
+
226
+ ## Step 3: Error Handling Audit — Weight: 12%
227
+
228
+ ### Check:
229
+ 1. **Empty catch blocks**: Catching errors and doing nothing — silent failures
230
+ 2. **Generic catches**: Catching `Error` or `any` without handling specific error types
231
+ 3. **Missing try/catch**: Async operations without error handling
232
+ 4. **Error swallowing**: Catching and logging but not propagating to the user
233
+ 5. **Missing error boundaries**: React components without ErrorBoundary wrapping
234
+ 6. **Unhandled promise rejections**: Async functions called without `.catch()` or `await` in try/catch
235
+ 7. **Missing finally blocks**: Resource cleanup not guaranteed (connections, streams, files)
236
+ 8. **Inconsistent error response shapes**: Different endpoints return errors in different formats
237
+ 9. **Missing HTTP error status codes**: Returning 200 with error body instead of proper status codes
238
+ 10. **User-facing error messages**: Are error messages helpful to users or just raw stack traces?
239
+ 11. **Crash recovery**: Does the app recover gracefully or leave the user on a broken screen?
240
+ 12. **API error handling**: Are API call failures handled at every call site?
241
+
242
+ ### Per-Finding Format:
243
+
244
+ ```markdown
245
+ ### Finding ERR-{number}: {title}
246
+ - **Category**: {Empty Catch / Missing Try-Catch / Unhandled Promise / Silent Failure / etc.}
247
+ - **Severity**: Critical / High / Medium / Low
248
+ - **Location**: `{file}:{line}`
249
+ - **Code**:
250
+ ```{lang}
251
+ {the problematic code snippet}
252
+ ```
253
+ - **Issue**: {why this is a problem}
254
+ - **Fix**:
255
+ ```{lang}
256
+ {corrected code}
257
+ ```
258
+ - **Score Impact**: -{N} points
259
+ ```
260
+
261
+ ### Output: `CodeMatters/ERROR_HANDLING.md`
262
+
263
+ ---
264
+
265
+ ## Step 4: Correctness Audit — Weight: 12%
266
+
267
+ ### Check:
268
+ 1. **Logic errors**: Off-by-one, wrong comparisons, inverted conditions, missed edge cases
269
+ 2. **Type safety violations**: TypeScript `any` usage, type assertions (`as`), non-null assertions (`!`)
270
+ 3. **Null/undefined handling**: Missing null checks before property access, optional chaining gaps
271
+ 4. **Race conditions**: Concurrent state updates, stale closures in React, missing debounce/throttle
272
+ 5. **Data transformation errors**: Incorrect mapping, filtering, or reducing of data
273
+ 6. **Date/time handling**: Timezone issues, incorrect date formatting, locale assumptions
274
+ 7. **Number precision**: Floating point comparisons, currency calculations without proper precision
275
+ 8. **String handling**: Missing trim(), case sensitivity issues, encoding problems
276
+ 9. **Business rule compliance**: If legacy intelligence exists, cross-reference every documented rule against the implementation
277
+ 10. **State management bugs**: React state not updating as expected, stale state in effects, missing dependency arrays
278
+
279
+ ### Business Rule Cross-Reference (if legacy intelligence available):
280
+
281
+ ```markdown
282
+ ### Rule Compliance: {rule_id} — {rule_name}
283
+ - **Rule**: {from BUSINESS_RULES.md}
284
+ - **Implementation**: `{file}:{line}`
285
+ - **Status**: ✅ Correctly implemented / ⚠️ Partially implemented / ❌ Not implemented / 🔴 Incorrectly implemented
286
+ - **Issue**: {if not correct, what's wrong}
287
+ ```
288
+
289
+ ### Output: `CodeMatters/CORRECTNESS.md`
290
+
291
+ ---
292
+
293
+ ## Step 5: Crash Risk Audit — Weight: 10%
294
+
295
+ ### Check:
296
+ 1. **Unguarded property access**: `obj.deep.property` without null checks on a potentially null chain
297
+ 2. **Array index out of bounds**: Accessing `arr[n]` without length check
298
+ 3. **Division by zero**: Mathematical operations without zero-divisor checks
299
+ 4. **Infinite loops**: Loops without clear exit conditions, recursive functions without base cases
300
+ 5. **Memory leaks**: Event listeners not removed, intervals not cleared, subscriptions not unsubscribed, large objects retained in closures
301
+ 6. **Stack overflow risk**: Deep recursion without tail-call optimization
302
+ 7. **DOM exceptions**: Accessing DOM elements that may not exist, manipulating unmounted components
303
+ 8. **Network failure handling**: API calls without timeout, no retry logic, no offline handling
304
+ 9. **Large data handling**: Processing unbounded arrays/objects without pagination or streaming
305
+ 10. **Concurrent modification**: Modifying collections while iterating, shared mutable state
306
+
307
+ ### Output: `CodeMatters/CRASH_RISK.md`
308
+
309
+ ---
310
+
311
+ ## Step 6: Code Quality & Standards Audit — Weight: 8% + 8%
312
+
313
+ ### Quality Checks:
314
+ 1. **Function length**: Functions over 50 lines (flag), over 100 lines (critical)
315
+ 2. **File length**: Files over 300 lines (flag), over 500 lines (critical)
316
+ 3. **Cyclomatic complexity**: Functions with complexity > 10 (flag), > 20 (critical)
317
+ 4. **Code duplication**: Repeated logic blocks (3+ occurrences of similar patterns)
318
+ 5. **Dead code**: Unreachable branches, unused functions, commented-out code blocks
319
+ 6. **Magic numbers/strings**: Hardcoded values without named constants
320
+ 7. **Naming conventions**: Inconsistent naming (camelCase mixed with snake_case), unclear names (x, temp, data, result)
321
+ 8. **Comments quality**: Outdated comments, obvious comments ("increment i"), missing comments on complex logic
322
+ 9. **Import organization**: Unused imports, circular imports, deep relative paths
323
+
324
+ ### Standards Checks:
325
+ 1. **Linter configuration**: Is ESLint/Prettier configured? Are rules enforced?
326
+ 2. **TypeScript strictness**: Is `strict: true` enabled? `noImplicitAny`? `strictNullChecks`?
327
+ 3. **Consistent patterns**: Are similar operations done the same way throughout the codebase?
328
+ 4. **File/folder structure**: Follows a recognizable pattern (feature-based, layer-based)?
329
+ 5. **API design consistency**: Same request/response patterns across endpoints?
330
+ 6. **Git hygiene**: Meaningful commit messages? `.gitignore` covering node_modules, .env, build artifacts?
331
+
332
+ ### Output: `CodeMatters/CODE_QUALITY.md`
333
+
334
+ ---
335
+
336
+ ## Step 7: Performance Audit — Weight: 7%
337
+
338
+ ### Check:
339
+ 1. **Bundle size**: Total bundle size, largest chunks, unused code in bundle (tree-shaking failures)
340
+ 2. **Lazy loading**: Are routes/heavy components code-split? Or is everything in one bundle?
341
+ 3. **Render performance** (React): Unnecessary re-renders, missing `useMemo`/`useCallback` on expensive operations, large lists without virtualization
342
+ 4. **Image optimization**: Unoptimized images, missing lazy loading for below-fold images, no WebP/AVIF
343
+ 5. **Network**: Unnecessary API calls, missing request caching, no debounce on search inputs, waterfall requests that could be parallelized
344
+ 6. **Memory**: Large objects held in state unnecessarily, growing arrays without cleanup, event listener accumulation
345
+ 7. **CSS**: Unused CSS loaded, render-blocking stylesheets, layout thrashing
346
+ 8. **Third-party scripts**: Heavy scripts loaded synchronously, blocking render
347
+ 9. **Database/API**: N+1 query patterns, unbounded queries without pagination, missing indexes (if visible from frontend patterns)
348
+
349
+ ### Output: `CodeMatters/PERFORMANCE.md`
350
+
351
+ ---
352
+
353
+ ## Step 8: Maintainability Audit — Weight: 7%
354
+
355
+ ### Check:
356
+ 1. **Cyclomatic complexity distribution**: How many functions are simple vs complex?
357
+ 2. **Code duplication rate**: Percentage of duplicated logic across the codebase
358
+ 3. **TODO/FIXME/HACK count**: Technical debt markers — count and categorize
359
+ 4. **Dependency coupling**: How many imports does each module have? High coupling = hard to change
360
+ 5. **Test-to-code ratio**: Lines of test code vs lines of production code
361
+ 6. **Documentation**: README quality, inline documentation for complex functions, API documentation
362
+ 7. **Configuration complexity**: How many config files? Are they well-organized or scattered?
363
+ 8. **Onboarding difficulty**: How long would it take a new developer to understand and contribute?
364
+
365
+ ### Output: `CodeMatters/MAINTAINABILITY.md` (merged into CODE_QUALITY.md if small enough)
366
+
367
+ ---
368
+
369
+ ## Step 9: Dependency Health Audit — Weight: 5%
370
+
371
+ ### Check:
372
+ 1. **Known vulnerabilities**: Run `npm audit` equivalent — list all CVEs by severity
373
+ 2. **Outdated packages**: How many are behind latest? How far behind?
374
+ 3. **Abandoned packages**: Packages with no updates in 2+ years, no maintainer activity
375
+ 4. **License compliance**: Any GPL/AGPL packages in a commercial project? License conflicts?
376
+ 5. **Dependency bloat**: Packages that could be replaced with native APIs or lighter alternatives
377
+ 6. **Duplicate dependencies**: Multiple versions of the same package in the tree
378
+ 7. **Direct vs transitive**: How many vulnerabilities are in direct deps vs transitive?
379
+ 8. **Lock file integrity**: Is package-lock.json / yarn.lock present and up to date?
380
+
381
+ ### Output: `CodeMatters/DEPENDENCY_HEALTH.md`
382
+
383
+ ---
384
+
385
+ ## Step 10: Accessibility Audit — Weight: 4%
386
+
387
+ ### Check:
388
+ 1. **Semantic HTML**: Using `<button>` for buttons (not `<div onClick>`), proper heading hierarchy
389
+ 2. **ARIA attributes**: Missing `aria-label`, `aria-describedby`, `role` attributes on interactive elements
390
+ 3. **Keyboard navigation**: All interactive elements reachable via Tab, actionable via Enter/Space
391
+ 4. **Color contrast**: Text meets WCAG AA contrast ratios (4.5:1 for normal, 3:1 for large text)
392
+ 5. **Focus management**: Focus visible, focus trapped in modals, focus restored after modal close
393
+ 6. **Form labels**: Every input has an associated label (Mantine handles this well, but verify)
394
+ 7. **Image alt text**: All `<img>` tags have meaningful `alt` attributes
395
+ 8. **Screen reader support**: Dynamic content updates announced via aria-live regions
396
+ 9. **Motion**: `prefers-reduced-motion` respected for animations
397
+
398
+ ### Output: `CodeMatters/ACCESSIBILITY.md`
399
+
400
+ ---
401
+
402
+ ## Step 11: Test Coverage Audit — Weight: 4%
403
+
404
+ ### Check:
405
+ 1. **Test existence**: Does the project have ANY tests?
406
+ 2. **Test framework**: What's used? (Jest, Vitest, Mocha, xUnit, pytest)
407
+ 3. **Coverage percentage**: If measurable, overall and per-module
408
+ 4. **Critical path coverage**: Are the most important business flows tested?
409
+ 5. **Test quality**: Do tests assert meaningful outcomes or just "doesn't crash"?
410
+ 6. **Edge case coverage**: Are boundary conditions, null inputs, error paths tested?
411
+ 7. **Integration tests**: Are API endpoints tested end-to-end?
412
+ 8. **Flaky tests**: Any tests that pass/fail intermittently?
413
+ 9. **Test speed**: How long does the test suite take? Slow suites get skipped.
414
+ 10. **Mock quality**: Are mocks realistic or do they mask real behavior?
415
+
416
+ ### Output: `CodeMatters/TEST_COVERAGE.md`
417
+
418
+ ---
419
+
420
+ ## Step 12: Architecture Compliance Audit — Weight: 3%
421
+
422
+ ### Check:
423
+ 1. **Layer violations**: UI components importing from data layer directly, bypassing service layer
424
+ 2. **Circular dependencies**: Module A imports B, B imports A
425
+ 3. **God files/classes**: Single files/classes doing everything
426
+ 4. **Separation of concerns**: Is business logic in the right layer? Or spread across components, utils, and helpers?
427
+ 5. **API boundary discipline**: Are all API calls going through a centralized client? Or scattered `fetch` calls?
428
+ 6. **State management discipline**: Is state in the right place? Global state for local concerns? Local state for shared data?
429
+ 7. **Pattern consistency**: If the project uses Repository pattern, does every module follow it? Or do some bypass it?
430
+
431
+ ### Output: `CodeMatters/ARCHITECTURE.md`
432
+
433
+ ---
434
+
435
+ ## Step 13: Score Calculation
436
+
437
+ After all audits are complete, calculate the final scores.
438
+
439
+ ### Scoring Method Per Category:
440
+
441
+ Each category starts at 100. Deductions based on finding severity:
442
+
443
+ | Severity | Points Deducted Per Finding | Cap |
444
+ |----------|---------------------------|-----|
445
+ | Critical | -15 per finding | No cap — critical findings can drive score to 0 |
446
+ | High | -8 per finding | Maximum -40 from high findings alone |
447
+ | Medium | -3 per finding | Maximum -20 from medium findings alone |
448
+ | Low | -1 per finding | Maximum -10 from low findings alone |
449
+
450
+ Minimum score per category: 0 (never negative).
451
+
452
+ ### Overall Score Calculation:
453
+
454
+ ```
455
+ Overall = (Security × 0.20) + (Error Handling × 0.12) + (Correctness × 0.12) +
456
+ (Crash Risk × 0.10) + (Code Quality × 0.08) + (Standards × 0.08) +
457
+ (Performance × 0.07) + (Maintainability × 0.07) + (Dependency Health × 0.05) +
458
+ (Accessibility × 0.04) + (Test Coverage × 0.04) + (Architecture × 0.03)
459
+ ```
460
+
461
+ ### Grade Assignment:
462
+
463
+ | Score Range | Grade | Meaning |
464
+ |-------------|-------|---------|
465
+ | 90-100 | **A** | Production-ready, exemplary code |
466
+ | 75-89 | **B** | Good, minor improvements needed |
467
+ | 60-74 | **C** | Acceptable, notable issues to address |
468
+ | 40-59 | **D** | Concerning, significant issues |
469
+ | 0-39 | **F** | Critical, not production-safe |
470
+
471
+ ### Healthcare Modifier:
472
+
473
+ If the application is flagged as healthcare:
474
+ - Security weight increases to 25% (from 20%)
475
+ - Error Handling weight increases to 15% (from 12%)
476
+ - Other weights proportionally reduced
477
+ - Any unencrypted PII storage is automatically Critical severity
478
+
479
+ ### Output: `CodeMatters/CODE_AUDIT_OVERVIEW.md`
480
+
481
+ ```markdown
482
+ # Code Quality Audit — {Project Name}
483
+
484
+ ## Overall Score: {X}/100 — Grade: {A/B/C/D/F}
485
+
486
+ ## Score Breakdown
487
+
488
+ | Category | Score | Grade | Weight | Weighted | Critical | High | Medium | Low |
489
+ |----------|-------|-------|--------|----------|----------|------|--------|-----|
490
+ | Security (OWASP) | {X} | {grade} | 20% | {weighted} | {n} | {n} | {n} | {n} |
491
+ | Error Handling | {X} | {grade} | 12% | {weighted} | {n} | {n} | {n} | {n} |
492
+ | Correctness | {X} | {grade} | 12% | {weighted} | {n} | {n} | {n} | {n} |
493
+ | Crash Risk | {X} | {grade} | 10% | {weighted} | {n} | {n} | {n} | {n} |
494
+ | Code Quality | {X} | {grade} | 8% | {weighted} | {n} | {n} | {n} | {n} |
495
+ | Standards | {X} | {grade} | 8% | {weighted} | {n} | {n} | {n} | {n} |
496
+ | Performance | {X} | {grade} | 7% | {weighted} | {n} | {n} | {n} | {n} |
497
+ | Maintainability | {X} | {grade} | 7% | {weighted} | {n} | {n} | {n} | {n} |
498
+ | Dependency Health | {X} | {grade} | 5% | {weighted} | {n} | {n} | {n} | {n} |
499
+ | Accessibility | {X} | {grade} | 4% | {weighted} | {n} | {n} | {n} | {n} |
500
+ | Test Coverage | {X} | {grade} | 4% | {weighted} | {n} | {n} | {n} | {n} |
501
+ | Architecture | {X} | {grade} | 3% | {weighted} | {n} | {n} | {n} | {n} |
502
+ | **Overall** | **{X}** | **{grade}** | **100%** | **{total}** | **{n}** | **{n}** | **{n}** | **{n}** |
503
+
504
+ ## Framework Health
505
+ | Component | Version | Status |
506
+ |-----------|---------|--------|
507
+ {from FRAMEWORK_REVIEW.md}
508
+
509
+ ## Total Findings: {count}
510
+ - Critical: {n} (fix immediately)
511
+ - High: {n} (fix before next release)
512
+ - Medium: {n} (fix in next sprint)
513
+ - Low: {n} (address when convenient)
514
+
515
+ ## Top 5 Most Impactful Fixes
516
+ {The 5 changes that would improve the overall score the most}
517
+
518
+ | # | Fix | Category | Severity | Score Impact | Effort |
519
+ |---|-----|----------|----------|-------------|--------|
520
+ | 1 | {fix description} | {category} | {severity} | +{points} | {hours} |
521
+ | 2 | ... | ... | ... | ... | ... |
522
+
523
+ ## Category Summaries
524
+ {One paragraph per category summarizing the key findings}
525
+
526
+ ## Detailed Reports
527
+ - [Security Audit](./SECURITY_AUDIT.md)
528
+ - [Error Handling](./ERROR_HANDLING.md)
529
+ - [Correctness](./CORRECTNESS.md)
530
+ - [Crash Risk](./CRASH_RISK.md)
531
+ - [Code Quality](./CODE_QUALITY.md)
532
+ - [Performance](./PERFORMANCE.md)
533
+ - [Dependency Health](./DEPENDENCY_HEALTH.md)
534
+ - [Accessibility](./ACCESSIBILITY.md)
535
+ - [Test Coverage](./TEST_COVERAGE.md)
536
+ - [Architecture](./ARCHITECTURE.md)
537
+ - [Framework Review](./FRAMEWORK_REVIEW.md)
538
+ - [Remediation Plan](./REMEDIATION_PLAN.md)
539
+ ```
540
+
541
+ ---
542
+
543
+ ## Step 14: Remediation Plan
544
+
545
+ Generate a prioritized fix list across ALL categories.
546
+
547
+ ### Output: `CodeMatters/REMEDIATION_PLAN.md`
548
+
549
+ ```markdown
550
+ # Remediation Plan
551
+
552
+ ## Priority Matrix
553
+
554
+ ### Phase 1: Critical (fix immediately, before any deployment)
555
+ | Finding ID | Category | Issue | File | Effort | Score Impact |
556
+ |-----------|----------|-------|------|--------|-------------|
557
+ | SEC-001 | Security | {description} | {file}:{line} | {hours} | +{points} |
558
+ | ERR-003 | Error Handling | {description} | {file}:{line} | {hours} | +{points} |
559
+
560
+ **Phase 1 Total**: {N} findings, ~{hours} effort, +{points} score improvement
561
+
562
+ ### Phase 2: High Priority (fix before next release)
563
+ | Finding ID | Category | Issue | File | Effort | Score Impact |
564
+ |-----------|----------|-------|------|--------|-------------|
565
+
566
+ **Phase 2 Total**: {N} findings, ~{hours} effort, +{points} score improvement
567
+
568
+ ### Phase 3: Medium Priority (fix in next sprint)
569
+ ...
570
+
571
+ ### Phase 4: Low Priority (address when convenient)
572
+ ...
573
+
574
+ ## Projected Score After Remediation
575
+ | Phase | Cumulative Score | Grade |
576
+ |-------|-----------------|-------|
577
+ | Current | {X} | {grade} |
578
+ | After Phase 1 | {X} | {grade} |
579
+ | After Phase 2 | {X} | {grade} |
580
+ | After Phase 3 | {X} | {grade} |
581
+ | After Phase 4 | {X} | {grade} |
582
+
583
+ ## Quick Wins (biggest score improvement for least effort)
584
+ {Findings where score_impact / effort_hours is highest}
585
+ ```
586
+
587
+ ---
588
+
589
+ ## Step 15: Generate Manifest
590
+
591
+ ### Output: `CodeMatters/manifest.json`
592
+
593
+ ```json
594
+ {
595
+ "project": "{project-name}",
596
+ "audited_at": "{ISO timestamp}",
597
+ "scan_type": "code-quality-audit",
598
+ "tech_stack": {
599
+ "language": "{detected}",
600
+ "framework": "{detected}",
601
+ "runtime_version": "{detected}"
602
+ },
603
+ "scores": {
604
+ "overall": { "score": 0, "grade": "X", "weight": 1.0 },
605
+ "security": { "score": 0, "grade": "X", "weight": 0.20, "findings": { "critical": 0, "high": 0, "medium": 0, "low": 0 } },
606
+ "error_handling": { "score": 0, "grade": "X", "weight": 0.12, "findings": { "critical": 0, "high": 0, "medium": 0, "low": 0 } },
607
+ "correctness": { "score": 0, "grade": "X", "weight": 0.12, "findings": { "critical": 0, "high": 0, "medium": 0, "low": 0 } },
608
+ "crash_risk": { "score": 0, "grade": "X", "weight": 0.10, "findings": { "critical": 0, "high": 0, "medium": 0, "low": 0 } },
609
+ "code_quality": { "score": 0, "grade": "X", "weight": 0.08, "findings": { "critical": 0, "high": 0, "medium": 0, "low": 0 } },
610
+ "standards": { "score": 0, "grade": "X", "weight": 0.08, "findings": { "critical": 0, "high": 0, "medium": 0, "low": 0 } },
611
+ "performance": { "score": 0, "grade": "X", "weight": 0.07, "findings": { "critical": 0, "high": 0, "medium": 0, "low": 0 } },
612
+ "maintainability": { "score": 0, "grade": "X", "weight": 0.07, "findings": { "critical": 0, "high": 0, "medium": 0, "low": 0 } },
613
+ "dependency_health": { "score": 0, "grade": "X", "weight": 0.05, "findings": { "critical": 0, "high": 0, "medium": 0, "low": 0 } },
614
+ "accessibility": { "score": 0, "grade": "X", "weight": 0.04, "findings": { "critical": 0, "high": 0, "medium": 0, "low": 0 } },
615
+ "test_coverage": { "score": 0, "grade": "X", "weight": 0.04, "findings": { "critical": 0, "high": 0, "medium": 0, "low": 0 } },
616
+ "architecture": { "score": 0, "grade": "X", "weight": 0.03, "findings": { "critical": 0, "high": 0, "medium": 0, "low": 0 } }
617
+ },
618
+ "total_findings": { "critical": 0, "high": 0, "medium": 0, "low": 0, "total": 0 },
619
+ "reports": {
620
+ "overview": "CODE_AUDIT_OVERVIEW.md",
621
+ "security": "SECURITY_AUDIT.md",
622
+ "error_handling": "ERROR_HANDLING.md",
623
+ "correctness": "CORRECTNESS.md",
624
+ "crash_risk": "CRASH_RISK.md",
625
+ "code_quality": "CODE_QUALITY.md",
626
+ "performance": "PERFORMANCE.md",
627
+ "dependency_health": "DEPENDENCY_HEALTH.md",
628
+ "accessibility": "ACCESSIBILITY.md",
629
+ "test_coverage": "TEST_COVERAGE.md",
630
+ "architecture": "ARCHITECTURE.md",
631
+ "framework_review": "FRAMEWORK_REVIEW.md",
632
+ "remediation_plan": "REMEDIATION_PLAN.md"
633
+ },
634
+ "previous_audit": null
635
+ }
636
+ ```
637
+
638
+ ---
639
+
640
+ ## Comparison Mode
641
+
642
+ If a previous `CodeMatters/manifest.json` exists:
643
+
644
+ 1. Read the previous scores
645
+ 2. After the new audit, show deltas:
646
+
647
+ ```markdown
648
+ ## Score Comparison (vs previous audit)
649
+
650
+ | Category | Previous | Current | Delta |
651
+ |----------|----------|---------|-------|
652
+ | Security | 42 (F) | 78 (B) | +36 ↑ |
653
+ | Error Handling | 55 (D) | 55 (D) | 0 — |
654
+ | Overall | 51 (D) | 72 (C) | +21 ↑ |
655
+
656
+ ## New Findings Since Last Audit: {count}
657
+ ## Fixed Findings Since Last Audit: {count}
658
+ ## Unchanged Findings: {count}
659
+ ```
660
+
661
+ Save the previous manifest as `manifest.previous.json` before overwriting.
662
+
663
+ ---
664
+
665
+ ## Output Folder Structure
666
+
667
+ ```
668
+ CodeMatters/
669
+ ├── manifest.json ← Scores, metadata, file inventory
670
+ ├── manifest.previous.json ← Previous audit (if comparison mode)
671
+ ├── CODE_AUDIT_OVERVIEW.md ← Executive summary + all scores
672
+ ├── SECURITY_AUDIT.md ← OWASP Top 10 findings
673
+ ├── ERROR_HANDLING.md ← Error handling + unhandled errors
674
+ ├── CORRECTNESS.md ← Logic correctness + business rule compliance
675
+ ├── CRASH_RISK.md ← Crash risk analysis
676
+ ├── CODE_QUALITY.md ← Quality + standards + maintainability
677
+ ├── PERFORMANCE.md ← Performance issues
678
+ ├── DEPENDENCY_HEALTH.md ← Package audit + CVEs
679
+ ├── ACCESSIBILITY.md ← a11y audit
680
+ ├── TEST_COVERAGE.md ← Test quality + coverage gaps
681
+ ├── ARCHITECTURE.md ← Architecture compliance
682
+ ├── FRAMEWORK_REVIEW.md ← Framework versions + EOL dates
683
+ ├── REMEDIATION_PLAN.md ← Prioritized fix list
684
+ └── diagrams/
685
+ ├── score-breakdown.mermaid ← Visual score chart
686
+ └── finding-distribution.mermaid ← Findings by severity and category
687
+ ```
688
+
689
+ ---
690
+
691
+ ## Quality Gate
692
+
693
+ Before delivering, verify:
694
+
695
+ - [ ] Every finding has a specific file/line reference (no vague findings)
696
+ - [ ] Every finding has a severity rating with justification
697
+ - [ ] Every finding has a concrete remediation with code example where applicable
698
+ - [ ] Scores are calculated correctly (spot-check the math)
699
+ - [ ] The remediation plan is ordered by priority (critical first)
700
+ - [ ] Quick wins are identified (high impact, low effort)
701
+ - [ ] If legacy intelligence exists, business rules are cross-referenced
702
+ - [ ] Framework versions are checked against current stable releases
703
+ - [ ] Manifest has all scores populated with actual values
704
+ - [ ] Overview file has the complete score table