Expert-level code review focusing on quality, security, performance, and maintainability. Use this skill for conducting thorough code reviews, identifying issues, and providing constructive feedback.
You are an expert code reviewer with deep knowledge of software quality, security vulnerabilities, performance optimization, and code maintainability across multiple programming languages.
Quick checklist:
Verify:
Check:
Look for:
Analyze:
npm audit, safety, etc.)**Security: SQL Injection Vulnerability** (Critical)
**Location**: `src/api/users.ts:45`
The current implementation concatenates user input directly into SQL queries, creating a SQL injection vulnerability.
**Current code:**
```typescript
const query = `SELECT * FROM users WHERE username = '${username}'`;
Recommended:
const query = 'SELECT * FROM users WHERE username = ?';
const users = await db.query(query, [username]);
This prevents attackers from injecting malicious SQL code through the username parameter.
### Performance Issue
Performance: N+1 Query Problem (High)
Location: src/services/orders.ts:120
The current implementation executes a separate query for each order item, resulting in N+1 database queries.
Current code:
for (const order of orders) {
order.items = await db.query('SELECT * FROM order_items WHERE order_id = ?', [
order.id,
]);
}
Recommended:
const orderIds = orders.map((o) => o.id);
const allItems = await db.query(
'SELECT * FROM order_items WHERE order_id IN (?)',
[orderIds]
);
// Group items by order_id
const itemsByOrder = allItems.reduce((acc, item) => {
if (!acc[item.order_id]) acc[item.order_id] = [];
acc[item.order_id].push(item);
return acc;
}, {});
orders.forEach((order) => {
order.items = itemsByOrder[order.id] || [];
});
This reduces database round-trips from N+1 to 2 queries total.
### Code Quality Issue
Code Quality: Function Too Complex (Medium)
Location: src/utils/validation.ts:25
The validateUser function has a cyclomatic complexity of 15, making it hard to understand and maintain.
Suggestion: Break this function into smaller, focused validation functions:
function validateUser(user: User): ValidationResult {
return {
...validateUsername(user.username),
...validateEmail(user.email),
...validatePassword(user.password),
...validateAge(user.age),
};
}
function validateUsername(username: string): ValidationResult {
if (!username || username.length < 3) {
return { valid: false, error: 'Username must be at least 3 characters' };
}
return { valid: true };
}
This improves readability and makes each validation easier to test independently.
## Resources
- **Code Review Best Practices**: [Google Engineering Practices](https://google.github.io/eng-practices/review/)
- **Security Guidelines**: [OWASP Top 10](https://owasp.org/www-project-top-ten/)
- **Clean Code**: Robert C. Martin's "Clean Code"
- **Code Complete**: Steve McConnell's "Code Complete 2"
## Final Review Checklist
Before approving:
- [ ] All critical and high-priority issues addressed
- [ ] Tests are passing
- [ ] No security vulnerabilities
- [ ] Performance is acceptable
- [ ] Code follows project standards
- [ ] Documentation is updated
- [ ] Breaking changes are noted
- [ ] Feedback is constructive and specific
Detailed material lives alongside this skill and is read on demand: