Code Review Expert

The Code Review Expert agent specializes in code review, best practices, code quality, identifying improvements, and ensuring maintainable, readable code.

Expertise Areas#

  • Functionality Review - Correctness, edge cases, error handling
  • Security Review - Input validation, SQL injection, XSS prevention
  • Performance Review - N+1 queries, memory leaks, optimization
  • Maintainability Review - Readability, single responsibility, DRY
  • Testing Review - Test coverage, meaningful tests
  • TypeScript Review - Type safety, proper typing patterns
  • React Review - Anti-patterns, hooks usage, rendering optimization
  • Database Review - Query efficiency, transactions, indexing

Usage Examples#

Code Quality Review#

Use the code-review-expert agent to review this React component for best practices and potential issues.

Response includes:

  • Functionality assessment
  • Anti-pattern identification
  • Performance suggestions
  • Refactoring recommendations

Security Review#

Use the code-review-expert agent to review this API route for security vulnerabilities.

Response includes:

  • Input validation check
  • SQL injection analysis
  • Authentication verification
  • Data exposure assessment

Performance Review#

Use the code-review-expert agent to identify performance issues in this database query code.

Response includes:

  • N+1 query detection
  • Index recommendations
  • Query optimization suggestions
  • Caching opportunities

Best Practices Applied#

1. Async/Await Patterns#

  • Parallel execution with Promise.all
  • Proper error handling
  • Avoiding sequential when parallel possible

2. React Patterns#

  • Avoiding useEffect for derived state
  • Proper dependency arrays
  • useCallback for stable references
  • useMemo for expensive computations

3. TypeScript Patterns#

  • Proper typing over 'any'
  • Safe null handling
  • Optional chaining with fallbacks

4. Database Patterns#

  • Include related data to avoid N+1
  • Select only needed fields
  • Use transactions for related operations

Common Patterns#

Async/Await Best Practice#

1// Bad: Sequential when could be parallel 2async function getBothUsers(id1: string, id2: string) { 3 const user1 = await getUser(id1); 4 const user2 = await getUser(id2); 5 return [user1, user2]; 6} 7 8// Good: Parallel execution 9async function getBothUsers(id1: string, id2: string) { 10 const [user1, user2] = await Promise.all([ 11 getUser(id1), 12 getUser(id2), 13 ]); 14 return [user1, user2]; 15}

React Anti-Pattern Fix#

1// Bad: useEffect for derived state 2function BadComponent({ items }) { 3 const [count, setCount] = useState(0); 4 useEffect(() => { 5 setCount(items.length); 6 }, [items]); 7 return <div>Count: {count}</div>; 8} 9 10// Good: Derive directly 11function GoodComponent({ items }) { 12 const count = items.length; 13 return <div>Count: {count}</div>; 14}

Database Query Optimization#

1// Bad: N+1 query problem 2const posts = await prisma.post.findMany(); 3for (const post of posts) { 4 post.author = await prisma.user.findUnique({ 5 where: { id: post.authorId } 6 }); 7} 8 9// Good: Include related data 10const posts = await prisma.post.findMany({ 11 include: { author: true } 12});

Early Returns for Clarity#

1// Bad: Deep nesting 2if (user) { 3 if (user.isActive) { 4 if (user.hasPermission) { 5 // do something 6 } 7 } 8} 9 10// Good: Early returns 11if (!user) return; 12if (!user.isActive) return; 13if (!user.hasPermission) return; 14// do something

Sample Prompts#

TaskPrompt
General review"Review this code for best practices and potential issues"
Security audit"Check this authentication code for security vulnerabilities"
Performance check"Identify performance bottlenecks in this data fetching code"
Refactoring"Suggest refactoring improvements for this component"
TypeScript review"Review the type safety of this module"

Configuration#

1// bootspring.config.js 2module.exports = { 3 agents: { 4 customInstructions: { 5 'code-review-expert': ` 6 - Focus on maintainability and readability 7 - Identify security vulnerabilities 8 - Check for performance issues 9 - Suggest TypeScript improvements 10 - Look for React anti-patterns 11 `, 12 }, 13 }, 14 linting: { 15 eslint: true, 16 typescript: 'strict', 17 }, 18};