| name | code-reviewer |
| description | Automated code review for security, quality, and performance. Catches bugs, vulnerabilities, and anti-patterns before they ship. Use when: reviewing PRs, auditing code before release, or checking your own work. |
| version | 1.0.0 |
| level | advanced |
| category | code-quality |
Code Reviewer
Review code systematically for bugs, security issues, and quality problems.
When to Use
- Before merging a pull request
- After finishing a feature (self-review)
- Auditing code for security or compliance
- Onboarding to an unfamiliar codebase
- Before deploying to production
How It Works
1. Review Checklist
Go through these categories in order:
Priority 1 — Security
├── SQL injection (raw queries, string concatenation)
├── XSS (unescaped user input in HTML/JSX)
├── Auth bypass (missing middleware, broken checks)
├── Secrets in code (API keys, passwords, tokens)
├── Insecure dependencies (known CVEs)
└── CSRF / CORS misconfiguration
Priority 2 — Correctness
├── Logic errors (off-by-one, wrong operator, inverted condition)
├── Null/undefined access without checks
├── Race conditions (async operations, shared state)
├── Error handling (uncaught exceptions, silent failures)
├── Edge cases (empty arrays, zero values, large inputs)
└── Type safety (any casts, missing types)
Priority 3 — Performance
├── N+1 queries (loop with DB call inside)
├── Missing pagination on list endpoints
├── Unnecessary re-renders (React)
├── Large bundle imports (import entire library for one function)
├── Missing indexes on queried columns
└── Memory leaks (uncleared intervals, listeners, subscriptions)
Priority 4 — Maintainability
├── Function length (> 30 lines = too long)
├── Naming clarity (can you understand it without context?)
├── Duplication (same logic in 2+ places)
├── Dead code (unused imports, unreachable branches)
├── Missing tests for new logic
└── Consistent patterns with rest of codebase
2. Security Deep Dive
SQL Injection:
const users = await db.query(`SELECT * FROM users WHERE name = '${name}'`)
const users = await db.query('SELECT * FROM users WHERE name = $1', [name])
const users = await db.user.findMany({ where: { name } })
XSS:
<div dangerouslySetInnerHTML={{ __html: userComment }} />
<div>{userComment}</div>
import DOMPurify from 'dompurify'
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(userComment) }} />
Auth Checks:
export async function DELETE(req: Request, { params }: { params: { id: string } }) {
await db.user.delete({ where: { id: params.id } })
return NextResponse.json({ ok: true })
}
export async function DELETE(req: Request, { params }: { params: { id: string } }) {
const session = await getServerSession()
if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
if (session.user.id !== params.id && session.user.role !== 'admin') {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
}
await db.user.delete({ where: { id: params.id } })
return NextResponse.json({ ok: true })
}
3. Performance Checks
N+1 Query:
const posts = await db.post.findMany()
for (const post of posts) {
post.author = await db.user.findUnique({ where: { id: post.authorId } })
}
const posts = await db.post.findMany({
include: { author: { select: { name: true, email: true } } }
})
React Re-renders:
<UserCard style={{ padding: 16 }} />
const cardStyle = { padding: 16 }
const cardStyle = useMemo(() => ({ padding: 16 }), [])
4. Review Output Format
For each issue found:
### [SEVERITY] Issue title
**File:** `src/api/users/route.ts:24`
**Category:** Security / Correctness / Performance / Maintainability
**Problem:** Description of what's wrong and why it matters.
**Fix:**
\`\`\`typescript
// suggested fix
\`\`\`
Severity levels:
- CRITICAL — Must fix before merge (security vulnerability, data loss)
- WARNING — Should fix (bug risk, performance issue)
- INFO — Consider improving (readability, convention)
5. Quick Commands
npm audit
grep -rn "TODO\|FIXME\|HACK" src/
npx tsc --noEmit
npx eslint src/
npx knip
Quality Checklist
Examples
> Review all uncommitted changes for security issues
> Do a full code review of the /api directory
> Check this PR for performance problems