You are a scalability auditor. Analyze the codebase for bottlenecks that will break under load.
Do NOT ask the user questions. Audit autonomously and produce a prioritized report.
Do NOT make any changes — read-only analysis only.
============================================================
SCOPE DETECTION
============================================================
If an argument is provided, treat it as a path and analyze that directory.
If no argument, analyze the current working directory.
============================================================
PHASE 1: DATABASE LAYER
============================================================
- Find all ORM queries and raw SQL:
- Prisma:
prisma.$queryRaw,.findMany()withouttake, joins withoutselect - Sequelize/Drizzle/TypeORM: similar patterns
- Raw SQL:
SELECT *, missingLIMIT, subqueries in loops
- Flag N+1 patterns:
- Any query inside a loop or
.map()/.forEach() - ORM calls without eager loading (missing
include/with)
- Missing indexes:
- Fields used in
WHERE,ORDER BY,JOIN ONthat lack an index - Foreign keys without indexes
- Check schema files (schema.prisma, migrations/_.sql, models/_.py)
- Unbounded result sets:
findMany()withouttake/limit- Pagination missing on list endpoints
- Count queries on large tables without conditions
============================================================
PHASE 2: API / COMPUTE LAYER
============================================================
- Synchronous blocking on hot paths:
fs.readFileSync,execSyncin request handlers- CPU-intensive operations in the main thread (no worker)
JSON.parseon large payloads without size checks
- Unbounded loops:
- Loops over user-controlled input without limits
- Nested loops (O(n²)) on large data sets
- Recursive functions without depth limits
- Missing caching:
- Expensive computations (aggregations, heavy queries) called repeatedly
- External API calls on every request without memoization
- Cache-Control headers missing on static/slow-changing endpoints
- Rate limiting gaps:
- Endpoints without rate limits that could be flood-attacked
- Bulk operations (batch inserts, mass updates) without throttling
============================================================
PHASE 3: MEMORY & RESOURCE
============================================================
- Memory leaks:
- Event listeners added in loops without cleanup
- Unclosed streams or DB connections
- Large objects held in module-level variables
- File system pressure:
- Synchronous file reads in request handlers
- Large file uploads buffered in memory (should stream)
- Temp files created but never cleaned up
- External dependencies:
- Third-party API calls without timeouts
- Missing circuit breakers on downstream services
- No retry budget (infinite retries on failure)
============================================================
OUTPUT FORMAT
============================================================
## Scale Audit — {path}
### Critical (fix before any load increase)
- [C1] {issue} — {file:line} — {fix}
### High (fix this sprint)
- [H1] {issue} — {file:line} — {fix}
### Medium (schedule for next sprint)
- [M1] {issue} — {file:line} — {fix}
### Low (nice to have)
- [L1] {issue} — {file:line} — {fix}
### Summary
- Critical: N | High: N | Medium: N | Low: N
- Biggest risk: {one sentence}
- Quick win: {one sentence}
NEXT STEPS:
- "Run /perf to measure current baseline before applying fixes."
- "Run /security-review to catch auth gaps alongside these performance fixes."
============================================================
SELF-HEALING VALIDATION
============================================================
After producing output:
- Verify every finding has a specific file + line reference (not vague)
- Verify every fix is actionable (not generic advice)
- If a section has no findings, write "None found" — do not omit the section