Overview
Review source code for correctness, quality, security, style conformance, and maintainability. This skill reads and evaluates code — it does not modify any files. The output is a structured review report with an overall assessment, strengths, severity-graded findings grouped by category, prioritized recommendations, and open questions.
Do not use this skill when the main task is to write code, refactor code, create tests, review tests, review a design, or review a delivery plan.
Required Inputs
| Input |
Required |
Description |
| Target files |
Yes |
Paths to the source code files to review |
| Review focus |
No |
Specific areas to prioritize (e.g., "security", "error handling", "API design") |
| Target packages |
No |
Packages, crates, modules, or directories involved |
| Acceptance criteria |
No |
Requirements or criteria the code should satisfy |
When used standalone, these inputs come from the user or the agent's prompt. When used within a workflow, the workflow's stage prompt will specify how to obtain them.
Outputs
| Output |
Description |
| Overall verdict |
Summary assessment of the code's quality and readiness |
| Review report |
Structured report with strengths, findings, recommendations, and open questions |
Steps
1. Gather inputs and context
Ensure the required inputs are available:
- If target files are missing, report the error — there is nothing to review
- If a review focus is specified, prioritize that area but still evaluate all categories
- If acceptance criteria are provided, check whether the code satisfies them
2. Read the target files
- Use
read_file to load each target file
- If a file does not exist or cannot be read, flag it immediately as a finding
- Note the language, framework, and overall structure of each file
3. Discover codebase conventions
Independently discover the codebase's conventions to evaluate style conformance. Do not assume conventions from the target files themselves — those files may deviate from the codebase's norms.
3a. Identify the language and build system
- Use
glob to search for build and configuration files in the relevant packages:
**/Cargo.toml, **/go.mod, **/package.json, **/tsconfig.json, **/pyproject.toml, **/setup.py, **/Gemfile, **/Makefile, **/CMakeLists.txt
- Read relevant config files to understand the project structure, dependencies, and any linting or formatting tools configured
3b. Study surrounding source code
- Use
glob and grep to find source files in the target packages
- Use
read_file to examine 2–3 representative source files (other than the target files) to learn:
- Naming conventions: How are files, functions, types, constants, and variables named?
- Module layout: How are files and directories organized?
- Import patterns: How does code import from other modules?
- Error handling: What error handling pattern does the codebase use?
- Coding style: Indentation, line length, brace style, comment style, documentation patterns
- Common patterns: Builder patterns, trait implementations, factory functions, dependency injection, etc.
- Idioms: Language-specific idioms the codebase favors
3c. If no surrounding code is found
- Broaden the search to sibling packages or the project root
- If still nothing is found, note this in the review — convention conformance will be assessed against general best practices for the language only
4. Evaluate correctness
Analyze the code for bugs, logic errors, and unhandled error paths:
4a. Logic errors
- Off-by-one errors in loops, slices, or indexing
- Incorrect boolean logic (wrong operator, inverted condition, missing case)
- Unreachable code or dead branches that suggest a logic mistake
- Race conditions or incorrect ordering of operations
- Integer overflow, underflow, or truncation
- Null/None/nil dereferences or missing null checks where the type system does not prevent them
4b. Error handling
- Unhandled error cases (swallowed errors, empty catch blocks, bare
unwrap() in Rust, unchecked exceptions)
- Error messages that leak internal details or provide no useful information
- Missing validation of inputs, return values, or external data
- Resource leaks (unclosed files, connections, or handles)
- Inconsistent error handling strategy within the same module
4c. Behavioral correctness
- Does the code do what its name, comments, and API contract suggest?
- Are there edge cases that would produce incorrect results (empty input, boundary values, large input, concurrent access)?
- Are type conversions safe, or could they lose precision or fail silently?
5. Evaluate security
Analyze the code for security vulnerabilities and unsafe patterns:
5a. Injection
- SQL injection (string concatenation in queries instead of parameterized queries)
- Command injection (unsanitized input passed to shell commands)
- Path traversal (unsanitized file paths from user input)
- Cross-site scripting (XSS) if the code generates HTML or handles web content
- Template injection or format-string vulnerabilities
5b. Credential and secret exposure
- Hardcoded secrets, API keys, tokens, or passwords
- Secrets logged to stdout, stderr, or log files
- Secrets passed as command-line arguments (visible in process listings)
- Sensitive data in error messages or stack traces
5c. Unsafe input handling
- Missing input validation or sanitization
- Trusting user-supplied data for authorization decisions
- Deserialization of untrusted data without validation
- Buffer overflows or unbounded allocations from external input
5d. Cryptography and authentication
- Use of weak or deprecated cryptographic algorithms
- Custom cryptography implementations instead of well-audited libraries
- Missing authentication or authorization checks
- Insecure default configurations
Flag security findings with appropriate severity — a hardcoded secret or SQL injection is High; a missing input length check may be Medium or Low depending on context.
6. Evaluate quality and style
Assess code quality and adherence to codebase conventions:
6a. Naming
- Are names descriptive and consistent with the codebase conventions discovered in Step 3?
- Do function names describe what they do? Do variable names describe what they hold?
- Are abbreviations avoided unless they are well-established in the codebase?
- Do boolean variables and functions read as predicates?
6b. Complexity
- Are functions or methods excessively long or doing too many things?
- Are there deeply nested conditionals or loops that could be flattened?
- Are there complex boolean expressions that should be extracted into named variables or helper functions?
- Are there functions with too many parameters?
6c. Duplication
- Is there repeated code that could be extracted into a shared function or method?
- Are there copy-pasted blocks with minor variations that could be parameterized?
- Is there duplication across the target files that suggests a missing abstraction?
6d. Readability
- Is the code understandable without extensive context?
- Is the control flow clear and easy to follow?
- Are magic numbers or cryptic constants explained with named constants or comments?
- Are comments accurate and helpful, or are they stale, misleading, or restating the obvious?
6e. Convention alignment
- Does the code follow the naming, formatting, import, and structural conventions discovered in Step 3?
- Does error handling follow the codebase's established pattern?
- Does the code use the codebase's preferred idioms?
7. Evaluate maintainability
Assess the code's long-term maintainability:
7a. Modularity
- Are responsibilities clearly separated?
- Does each function, method, or class have a single, well-defined purpose?
- Could the code be tested, reused, or replaced independently?
7b. Coupling
- Is the code tightly coupled to external systems, global state, or implementation details of other modules?
- Are dependencies explicit (via parameters or constructors) or hidden (via global access or side effects)?
- Would changing one part of the code require changes in many other places?
7c. Testability
- Can the code be unit-tested without elaborate setup?
- Are dependencies injectable or mockable?
- Are side effects isolated from business logic?
- Is there logic that is difficult to test because it is buried inside a large function or tightly coupled to I/O?
7d. API design
- Are public interfaces clear, minimal, and hard to misuse?
- Are parameters and return types appropriate? Would callers need to do unnecessary work?
- Are optional or configuration parameters handled cleanly (builder pattern, options struct, default values)?
- Are error types informative and actionable for callers?
8. Check acceptance criteria (if provided)
If acceptance criteria were provided:
- For each criterion, assess whether the code satisfies it
- Flag criteria that appear unsatisfied or only partially satisfied
- Include a coverage matrix in the report
| Acceptance Criterion |
Status |
Notes |
| Criterion text |
✅ Satisfied / ❌ Not satisfied / ⚠️ Partially satisfied |
Brief explanation |
9. Produce the structured review report
Follow the Report Format below.
Report Format
Overall Assessment
One to three sentences summarizing the code's quality and the most important findings. State the overall quality level and the primary area needing attention.
Strengths
A short bullet list of what the code does well. Recognizing strengths helps the author know what to preserve.
Acceptance-Criteria Coverage
Include this section only if acceptance criteria were provided. Use the coverage matrix from Step 8.
Findings
Group findings under these headings when relevant (omit headings with no findings):
- Correctness — bugs, logic errors, unhandled error paths, edge-case failures
- Security — injection, credential exposure, unsafe input handling, cryptographic issues
- Quality and style — naming, complexity, duplication, readability, convention violations
- Maintainability — modularity, coupling, testability, API design issues
For each finding:
- Indicate severity as High, Medium, or Low
- Describe the issue precisely, referencing the specific file, function, and line range
- Explain why it matters
Severity guidelines:
- High: Bugs that would produce incorrect results, security vulnerabilities exploitable by an attacker, crashes or data loss, completely missing error handling for critical paths
- Medium: Logic that works but is fragile or likely to break under edge cases, security issues that require specific conditions to exploit, significant convention violations, high complexity that materially hinders understanding, poor API design that makes misuse easy
- Low: Style inconsistencies, minor naming improvements, small duplication, opportunities to simplify, documentation gaps, minor readability improvements
Recommendations
A numbered list of concrete improvements in priority order. Each recommendation should say what to change, where, and why. When useful, suggest specific approaches, patterns, or restructuring strategies.
Open Questions
List questions that should be answered to improve confidence in the review. Include this section only when such questions remain — for example, when the reviewer cannot determine whether a pattern is intentional without more context, or when the review focus was too narrow to fully assess a concern.
Examples
Example 1: Small function with a bug and a security issue
Target files: src/auth/token.rs
Review:
Overall Assessment
The token validation function has a critical logic error that accepts expired tokens and a hardcoded fallback secret. These must be fixed before the code is safe for production.
Strengths
- Clear function signature with appropriate error types
- Good use of the codebase's
AuthError enum for error reporting
- Follows the module's existing import and naming conventions
Findings
Correctness
- High:
validate_token in src/auth/token.rs:42-58 compares token.exp > now but should compare token.exp < now to detect expiration. Currently, all expired tokens are accepted and all valid tokens are rejected.
Security
- High:
src/auth/token.rs:15 contains a hardcoded fallback secret "dev-secret-key" used when the environment variable is not set. This would allow token forgery in any deployment that fails to set the variable.
- Medium:
src/auth/token.rs:51 logs the full token payload at debug level, which could expose user claims in log files.
Quality and style
- Low: The function
validate_token is 40 lines long. Extracting the claims-parsing logic into a helper would improve readability, consistent with how parse_header is structured in the same module.
Recommendations
- Fix the expiration check on line 45: change
token.exp > now to token.exp < now
- Remove the hardcoded fallback secret on line 15. Return an error when the environment variable is missing instead of falling back to an insecure default.
- Redact or remove the debug log of the full token payload on line 51. Log only the token ID or a truncated hash if debugging information is needed.
- Consider extracting the claims-parsing block (lines 30–45) into a
parse_claims helper for consistency with the module's existing structure.
Example 2: Multi-file review with convention and maintainability issues
Target files: lib/handlers/user_handler.py, lib/handlers/order_handler.py
Review focus: maintainability
Review:
Overall Assessment
Both handler files work correctly but share significant duplicated code and are tightly coupled to the database module through direct imports of internal functions. Refactoring the shared patterns into a base handler and using the public db.query API would substantially improve maintainability.
Strengths
- Both handlers follow the project's URL routing convention
- Error responses use the standardized
ErrorResponse format consistently
- Input validation is present for all endpoints
Findings
Quality and style
- Medium:
user_handler.py:12-35 and order_handler.py:15-38 contain nearly identical authentication and permission-checking boilerplate. This pattern is repeated in both files and would need to be updated in multiple places if the auth logic changes.
- Low:
order_handler.py:72 uses camelCase for the local variable orderItems, while the rest of the codebase uses snake_case. The codebase convention (confirmed in lib/handlers/product_handler.py and lib/utils/helpers.py) is snake_case throughout.
Maintainability
- Medium: Both handlers import
db._execute_raw_query (a private function indicated by the underscore prefix) instead of using the public db.query interface. This creates tight coupling to the database module's internals and would break if the internal implementation changes.
- Medium:
user_handler.py:88-120 contains a 32-line function handle_update that mixes validation, database access, cache invalidation, and response formatting. Separating these concerns would make each step independently testable.
- Low: Neither handler has type annotations on function parameters or return values, while the three other handler files in
lib/handlers/ all use type annotations. Adding them would improve IDE support and catch type errors earlier.
Recommendations
- Extract the shared auth/permission boilerplate into a decorator or base handler class to eliminate duplication and centralize auth logic changes
- Replace
db._execute_raw_query imports with db.query in both handlers to depend on the public API
- Break
handle_update into smaller functions: validate_update_request, apply_update, invalidate_user_cache, to improve testability
- Rename
orderItems to order_items on line 72 of order_handler.py to match the codebase's snake_case convention
- Add type annotations to function signatures in both handlers for consistency with the rest of
lib/handlers/
Edge Cases
- Partial code or code snippets: Review what is provided. Note any limitations caused by missing context (e.g., cannot assess error handling without seeing the caller, cannot assess security without seeing how input arrives). Do not refuse to review — provide the best assessment possible with available information.
- Multi-file reviews: Review each file against the same package's conventions. Produce a single unified report covering all files. Note cross-file issues such as duplicated patterns, inconsistent styles between files, or coupling between the reviewed files.
- Code without tests: Do not penalize the code for lacking tests in the correctness or quality findings — that is a testability observation under maintainability. Focus on the code itself. Note in the maintainability section whether the code's structure would make it easy or hard to test.
- Generated code: If the code appears to be generated (e.g., by a code generator, ORM, or protocol buffer compiler), note this and limit the review to correctness and security. Style, naming, and structural critiques are usually not actionable for generated code since the generator, not the code, should be changed.
- Performance-sensitive code: If code has comments indicating performance sensitivity (benchmarks, hot paths, optimization notes) or if the review focus includes performance, be conservative about recommending changes that could affect performance (e.g., adding function call overhead, changing data structures). Note performance concerns separately when the current code sacrifices readability for speed.
- Very large files: Focus on the highest-impact findings. Summarize patterns (e.g., "the same missing-null-check pattern appears in 12 functions") rather than listing every instance individually. Prioritize findings that affect correctness and security over style observations.
- Code in unfamiliar languages: If the language is not well-known, focus on universal concerns (logic errors, security, naming clarity, structural complexity) and note that language-specific idiom assessment may be limited.
- Review focus specified: When a specific focus is provided, give that area extra depth but still scan all categories. A security-focused review should still flag an obvious bug; a quality-focused review should still flag an obvious vulnerability.
- Acceptance criteria provided but code is incomplete: Flag unmet criteria as findings but distinguish between "the code does not implement this" and "the code implements this incorrectly."
- No convention baseline discoverable: If no surrounding code exists to establish conventions, evaluate against general best practices for the language and note the limitation. Do not invent conventions that may not apply.
1---2name: software-code-review3description: Evaluate source code for correctness, quality, security, style conformance, and maintainability, producing a structured review report with findings and recommendations. Use when the user wants to review, critique, audit, evaluate, or inspect source code — checking for bugs, logic errors, unhandled error paths, security vulnerabilities, naming and readability issues, complexity, duplication, coupling, testability, and API design. Discovers codebase conventions independently and produces an actionable report with severity-graded findings grouped by category, prioritized recommendations, and open questions.4---56## Overview78Review source code for correctness, quality, security, style conformance, and maintainability. This skill reads and evaluates code — it does not modify any files. The output is a structured review report with an overall assessment, strengths, severity-graded findings grouped by category, prioritized recommendations, and open questions.910Do not use this skill when the main task is to write code, refactor code, create tests, review tests, review a design, or review a delivery plan.1112## Required Inputs1314| Input | Required | Description |15|---------------------|----------|----------------------------------------------------------------------|16| Target files | Yes | Paths to the source code files to review |17| Review focus | No | Specific areas to prioritize (e.g., "security", "error handling", "API design") |18| Target packages | No | Packages, crates, modules, or directories involved |19| Acceptance criteria | No | Requirements or criteria the code should satisfy |2021When used standalone, these inputs come from the user or the agent's prompt. When used within a workflow, the workflow's stage prompt will specify how to obtain them.2223## Outputs2425| Output | Description |26|-----------------|-------------------------------------------------------------------------------|27| Overall verdict | Summary assessment of the code's quality and readiness |28| Review report | Structured report with strengths, findings, recommendations, and open questions |2930## Steps3132### 1. Gather inputs and context3334Ensure the required inputs are available:3536- If target files are missing, report the error — there is nothing to review37- If a review focus is specified, prioritize that area but still evaluate all categories38- If acceptance criteria are provided, check whether the code satisfies them3940### 2. Read the target files4142- Use `read_file` to load each target file43- If a file does not exist or cannot be read, flag it immediately as a finding44- Note the language, framework, and overall structure of each file4546### 3. Discover codebase conventions4748Independently discover the codebase's conventions to evaluate style conformance. Do not assume conventions from the target files themselves — those files may deviate from the codebase's norms.4950#### 3a. Identify the language and build system5152- Use `glob` to search for build and configuration files in the relevant packages:53 - `**/Cargo.toml`, `**/go.mod`, `**/package.json`, `**/tsconfig.json`, `**/pyproject.toml`, `**/setup.py`, `**/Gemfile`, `**/Makefile`, `**/CMakeLists.txt`54- Read relevant config files to understand the project structure, dependencies, and any linting or formatting tools configured5556#### 3b. Study surrounding source code5758- Use `glob` and `grep` to find source files in the target packages59- Use `read_file` to examine 2–3 representative source files (other than the target files) to learn:60 - **Naming conventions**: How are files, functions, types, constants, and variables named?61 - **Module layout**: How are files and directories organized?62 - **Import patterns**: How does code import from other modules?63 - **Error handling**: What error handling pattern does the codebase use?64 - **Coding style**: Indentation, line length, brace style, comment style, documentation patterns65 - **Common patterns**: Builder patterns, trait implementations, factory functions, dependency injection, etc.66 - **Idioms**: Language-specific idioms the codebase favors6768#### 3c. If no surrounding code is found6970- Broaden the search to sibling packages or the project root71- If still nothing is found, note this in the review — convention conformance will be assessed against general best practices for the language only7273### 4. Evaluate correctness7475Analyze the code for bugs, logic errors, and unhandled error paths:7677#### 4a. Logic errors7879- Off-by-one errors in loops, slices, or indexing80- Incorrect boolean logic (wrong operator, inverted condition, missing case)81- Unreachable code or dead branches that suggest a logic mistake82- Race conditions or incorrect ordering of operations83- Integer overflow, underflow, or truncation84- Null/None/nil dereferences or missing null checks where the type system does not prevent them8586#### 4b. Error handling8788- Unhandled error cases (swallowed errors, empty catch blocks, bare `unwrap()` in Rust, unchecked exceptions)89- Error messages that leak internal details or provide no useful information90- Missing validation of inputs, return values, or external data91- Resource leaks (unclosed files, connections, or handles)92- Inconsistent error handling strategy within the same module9394#### 4c. Behavioral correctness9596- Does the code do what its name, comments, and API contract suggest?97- Are there edge cases that would produce incorrect results (empty input, boundary values, large input, concurrent access)?98- Are type conversions safe, or could they lose precision or fail silently?99100### 5. Evaluate security101102Analyze the code for security vulnerabilities and unsafe patterns:103104#### 5a. Injection105106- SQL injection (string concatenation in queries instead of parameterized queries)107- Command injection (unsanitized input passed to shell commands)108- Path traversal (unsanitized file paths from user input)109- Cross-site scripting (XSS) if the code generates HTML or handles web content110- Template injection or format-string vulnerabilities111112#### 5b. Credential and secret exposure113114- Hardcoded secrets, API keys, tokens, or passwords115- Secrets logged to stdout, stderr, or log files116- Secrets passed as command-line arguments (visible in process listings)117- Sensitive data in error messages or stack traces118119#### 5c. Unsafe input handling120121- Missing input validation or sanitization122- Trusting user-supplied data for authorization decisions123- Deserialization of untrusted data without validation124- Buffer overflows or unbounded allocations from external input125126#### 5d. Cryptography and authentication127128- Use of weak or deprecated cryptographic algorithms129- Custom cryptography implementations instead of well-audited libraries130- Missing authentication or authorization checks131- Insecure default configurations132133Flag security findings with appropriate severity — a hardcoded secret or SQL injection is High; a missing input length check may be Medium or Low depending on context.134135### 6. Evaluate quality and style136137Assess code quality and adherence to codebase conventions:138139#### 6a. Naming140141- Are names descriptive and consistent with the codebase conventions discovered in Step 3?142- Do function names describe what they do? Do variable names describe what they hold?143- Are abbreviations avoided unless they are well-established in the codebase?144- Do boolean variables and functions read as predicates?145146#### 6b. Complexity147148- Are functions or methods excessively long or doing too many things?149- Are there deeply nested conditionals or loops that could be flattened?150- Are there complex boolean expressions that should be extracted into named variables or helper functions?151- Are there functions with too many parameters?152153#### 6c. Duplication154155- Is there repeated code that could be extracted into a shared function or method?156- Are there copy-pasted blocks with minor variations that could be parameterized?157- Is there duplication across the target files that suggests a missing abstraction?158159#### 6d. Readability160161- Is the code understandable without extensive context?162- Is the control flow clear and easy to follow?163- Are magic numbers or cryptic constants explained with named constants or comments?164- Are comments accurate and helpful, or are they stale, misleading, or restating the obvious?165166#### 6e. Convention alignment167168- Does the code follow the naming, formatting, import, and structural conventions discovered in Step 3?169- Does error handling follow the codebase's established pattern?170- Does the code use the codebase's preferred idioms?171172### 7. Evaluate maintainability173174Assess the code's long-term maintainability:175176#### 7a. Modularity177178- Are responsibilities clearly separated?179- Does each function, method, or class have a single, well-defined purpose?180- Could the code be tested, reused, or replaced independently?181182#### 7b. Coupling183184- Is the code tightly coupled to external systems, global state, or implementation details of other modules?185- Are dependencies explicit (via parameters or constructors) or hidden (via global access or side effects)?186- Would changing one part of the code require changes in many other places?187188#### 7c. Testability189190- Can the code be unit-tested without elaborate setup?191- Are dependencies injectable or mockable?192- Are side effects isolated from business logic?193- Is there logic that is difficult to test because it is buried inside a large function or tightly coupled to I/O?194195#### 7d. API design196197- Are public interfaces clear, minimal, and hard to misuse?198- Are parameters and return types appropriate? Would callers need to do unnecessary work?199- Are optional or configuration parameters handled cleanly (builder pattern, options struct, default values)?200- Are error types informative and actionable for callers?201202### 8. Check acceptance criteria (if provided)203204If acceptance criteria were provided:205206- For each criterion, assess whether the code satisfies it207- Flag criteria that appear unsatisfied or only partially satisfied208- Include a coverage matrix in the report209210| Acceptance Criterion | Status | Notes |211|---|---|---|212| Criterion text | ✅ Satisfied / ❌ Not satisfied / ⚠️ Partially satisfied | Brief explanation |213214### 9. Produce the structured review report215216Follow the Report Format below.217218## Report Format219220### Overall Assessment221222One to three sentences summarizing the code's quality and the most important findings. State the overall quality level and the primary area needing attention.223224### Strengths225226A short bullet list of what the code does well. Recognizing strengths helps the author know what to preserve.227228### Acceptance-Criteria Coverage229230Include this section only if acceptance criteria were provided. Use the coverage matrix from Step 8.231232### Findings233234Group findings under these headings when relevant (omit headings with no findings):235236- **Correctness** — bugs, logic errors, unhandled error paths, edge-case failures237- **Security** — injection, credential exposure, unsafe input handling, cryptographic issues238- **Quality and style** — naming, complexity, duplication, readability, convention violations239- **Maintainability** — modularity, coupling, testability, API design issues240241For each finding:242243- Indicate severity as **High**, **Medium**, or **Low**244- Describe the issue precisely, referencing the specific file, function, and line range245- Explain why it matters246247Severity guidelines:248249- **High**: Bugs that would produce incorrect results, security vulnerabilities exploitable by an attacker, crashes or data loss, completely missing error handling for critical paths250- **Medium**: Logic that works but is fragile or likely to break under edge cases, security issues that require specific conditions to exploit, significant convention violations, high complexity that materially hinders understanding, poor API design that makes misuse easy251- **Low**: Style inconsistencies, minor naming improvements, small duplication, opportunities to simplify, documentation gaps, minor readability improvements252253### Recommendations254255A numbered list of concrete improvements in priority order. Each recommendation should say what to change, where, and why. When useful, suggest specific approaches, patterns, or restructuring strategies.256257### Open Questions258259List questions that should be answered to improve confidence in the review. Include this section only when such questions remain — for example, when the reviewer cannot determine whether a pattern is intentional without more context, or when the review focus was too narrow to fully assess a concern.260261## Examples262263### Example 1: Small function with a bug and a security issue264265Target files: `src/auth/token.rs`266267Review:268269> ### Overall Assessment270>271> The token validation function has a critical logic error that accepts expired tokens and a hardcoded fallback secret. These must be fixed before the code is safe for production.272>273> ### Strengths274>275> - Clear function signature with appropriate error types276> - Good use of the codebase's `AuthError` enum for error reporting277> - Follows the module's existing import and naming conventions278>279> ### Findings280>281> **Correctness**282> - **High**: `validate_token` in `src/auth/token.rs:42-58` compares `token.exp > now` but should compare `token.exp < now` to detect expiration. Currently, all expired tokens are accepted and all valid tokens are rejected.283>284> **Security**285> - **High**: `src/auth/token.rs:15` contains a hardcoded fallback secret `"dev-secret-key"` used when the environment variable is not set. This would allow token forgery in any deployment that fails to set the variable.286> - **Medium**: `src/auth/token.rs:51` logs the full token payload at `debug` level, which could expose user claims in log files.287>288> **Quality and style**289> - **Low**: The function `validate_token` is 40 lines long. Extracting the claims-parsing logic into a helper would improve readability, consistent with how `parse_header` is structured in the same module.290>291> ### Recommendations292>293> 1. Fix the expiration check on line 45: change `token.exp > now` to `token.exp < now`294> 2. Remove the hardcoded fallback secret on line 15. Return an error when the environment variable is missing instead of falling back to an insecure default.295> 3. Redact or remove the debug log of the full token payload on line 51. Log only the token ID or a truncated hash if debugging information is needed.296> 4. Consider extracting the claims-parsing block (lines 30–45) into a `parse_claims` helper for consistency with the module's existing structure.297298### Example 2: Multi-file review with convention and maintainability issues299300Target files: `lib/handlers/user_handler.py`, `lib/handlers/order_handler.py`301Review focus: maintainability302303Review:304305> ### Overall Assessment306>307> Both handler files work correctly but share significant duplicated code and are tightly coupled to the database module through direct imports of internal functions. Refactoring the shared patterns into a base handler and using the public `db.query` API would substantially improve maintainability.308>309> ### Strengths310>311> - Both handlers follow the project's URL routing convention312> - Error responses use the standardized `ErrorResponse` format consistently313> - Input validation is present for all endpoints314>315> ### Findings316>317> **Quality and style**318> - **Medium**: `user_handler.py:12-35` and `order_handler.py:15-38` contain nearly identical authentication and permission-checking boilerplate. This pattern is repeated in both files and would need to be updated in multiple places if the auth logic changes.319> - **Low**: `order_handler.py:72` uses `camelCase` for the local variable `orderItems`, while the rest of the codebase uses `snake_case`. The codebase convention (confirmed in `lib/handlers/product_handler.py` and `lib/utils/helpers.py`) is `snake_case` throughout.320>321> **Maintainability**322> - **Medium**: Both handlers import `db._execute_raw_query` (a private function indicated by the underscore prefix) instead of using the public `db.query` interface. This creates tight coupling to the database module's internals and would break if the internal implementation changes.323> - **Medium**: `user_handler.py:88-120` contains a 32-line function `handle_update` that mixes validation, database access, cache invalidation, and response formatting. Separating these concerns would make each step independently testable.324> - **Low**: Neither handler has type annotations on function parameters or return values, while the three other handler files in `lib/handlers/` all use type annotations. Adding them would improve IDE support and catch type errors earlier.325>326> ### Recommendations327>328> 1. Extract the shared auth/permission boilerplate into a decorator or base handler class to eliminate duplication and centralize auth logic changes329> 2. Replace `db._execute_raw_query` imports with `db.query` in both handlers to depend on the public API330> 3. Break `handle_update` into smaller functions: `validate_update_request`, `apply_update`, `invalidate_user_cache`, to improve testability331> 4. Rename `orderItems` to `order_items` on line 72 of `order_handler.py` to match the codebase's `snake_case` convention332> 5. Add type annotations to function signatures in both handlers for consistency with the rest of `lib/handlers/`333334## Edge Cases335336- **Partial code or code snippets**: Review what is provided. Note any limitations caused by missing context (e.g., cannot assess error handling without seeing the caller, cannot assess security without seeing how input arrives). Do not refuse to review — provide the best assessment possible with available information.337- **Multi-file reviews**: Review each file against the same package's conventions. Produce a single unified report covering all files. Note cross-file issues such as duplicated patterns, inconsistent styles between files, or coupling between the reviewed files.338- **Code without tests**: Do not penalize the code for lacking tests in the correctness or quality findings — that is a testability observation under maintainability. Focus on the code itself. Note in the maintainability section whether the code's structure would make it easy or hard to test.339- **Generated code**: If the code appears to be generated (e.g., by a code generator, ORM, or protocol buffer compiler), note this and limit the review to correctness and security. Style, naming, and structural critiques are usually not actionable for generated code since the generator, not the code, should be changed.340- **Performance-sensitive code**: If code has comments indicating performance sensitivity (benchmarks, hot paths, optimization notes) or if the review focus includes performance, be conservative about recommending changes that could affect performance (e.g., adding function call overhead, changing data structures). Note performance concerns separately when the current code sacrifices readability for speed.341- **Very large files**: Focus on the highest-impact findings. Summarize patterns (e.g., "the same missing-null-check pattern appears in 12 functions") rather than listing every instance individually. Prioritize findings that affect correctness and security over style observations.342- **Code in unfamiliar languages**: If the language is not well-known, focus on universal concerns (logic errors, security, naming clarity, structural complexity) and note that language-specific idiom assessment may be limited.343- **Review focus specified**: When a specific focus is provided, give that area extra depth but still scan all categories. A security-focused review should still flag an obvious bug; a quality-focused review should still flag an obvious vulnerability.344- **Acceptance criteria provided but code is incomplete**: Flag unmet criteria as findings but distinguish between "the code does not implement this" and "the code implements this incorrectly."345- **No convention baseline discoverable**: If no surrounding code exists to establish conventions, evaluate against general best practices for the language and note the limitation. Do not invent conventions that may not apply.