Coding Web Dev Advanced ✓ Verified

Senior Software Engineer Code Review and Refactoring Prompt

Conduct rigorous staff-engineer code reviews, identifying performance bottlenecks, security vulnerabilities, edge cases, and clean refactoring plans.

Act as a Principal Software Engineer and Staff System Architect. Perform a rigorous, production-grade code review and refactoring plan for the provided {{programming_language}} code snippet targeting {{system_environment}}. Code Under Review: ```{{programming_language}} {{source_code_snippet}} ``` Primary Review Objectives: Identify architectural deficiencies and optimize for {{primary_optimization_goal}} (e.g., runtime latency, memory footprint, concurrency safety, maintainability, type safety). Review Deliverables: 1. Critical Findings & Security Audit: - Vulnerabilities & Risks: Check for injection flaws, race conditions, memory leaks, unhandled exceptions, and OWASP Top 10 risks. - Complexity Analysis: Current Big-O Time and Space complexity evaluation. - Anti-Patterns: Identification of code smells, tight coupling, and violation of SOLID / Clean Code principles. 2. Edge Cases & Silent Failure Modes: - Pinpoint at least 3 edge cases (e.g., null/undefined inputs, network timeouts, race conditions, extreme payloads) where this code could fail in production. 3. Complete Refactored Implementation: - Provide the full, clean, production-ready replacement code. - Apply modern language idioms, strict type annotations, robust error boundaries, and defensive programming. - Include clear, inline documentation explaining non-obvious optimizations. 4. Performance & Benchmark Comparison: - Explain why the refactored code outperforms the original in terms of CPU execution cycles, memory allocation, and maintainability. - Suggest 2 automated unit/integration test cases (including mock assertions) to verify the fix.
🛠 Customize Prompt
👁 4 ⎘ 0 ★ 0 🕒 Oct 15, 2026
Customize this prompt (fill variables)
Your values are inserted locally in your browser — nothing is stored.
How to use this prompt
1. What to replace:
Replace each {{placeholder}} with your language of choice, deployment context, code snippet, and your primary engineering priority.

2. How to customize variables:
- programming_language: Works with Python, TypeScript, Go, Rust, Java, C++, or SQL.
- system_environment: Specify environment (e.g., AWS Lambda, embedded IoT, Kubernetes cluster, browser client).
- source_code_snippet: Paste any function, class, or API endpoint that needs review.
- primary_optimization_goal: Target memory usage, thread safety, testability, algorithmic efficiency, or database performance.

3. Compatible AI Tools:
Claude 3.5 Sonnet, ChatGPT (GPT-4o), Cursor, GitHub Copilot.

4. Expected Result:
A senior-level code review breakdown with edge-case detection, complexity analysis, and a drop-in refactored code block with automated unit tests.
Example: what to expect

Example input

programming_language: Python 3.12 system_environment: FastAPI asynchronous backend service processing real-time analytics source_code_snippet: def process_events(events): output = {} for e in events: if e['user_id'] not in output: output[e['user_id']] = [] output[e['user_id']].append(e['value']) return {k: sum(v)/len(v) for k, v in output.items() if len(v) > 0} primary_optimization_goal: vectorized memory efficiency, typing annotations, handling zero-division edge cases, and parallel batching

Example output

A comprehensive code review identifying missing type hints, lack of error handling for missing dictionary keys, and suboptimal list allocations. Provides an optimized version using collections.defaultdict and math/itertools with O(N) single-pass aggregation, robust typing annotations, comprehensive docstrings, and pytest test fixtures covering empty lists, malformed event payloads, and zero values.
Variables explained
VariableWhat to enter
{{programming_language}} Specify language (e.g. TypeScript, Python 3.12, Go, Rust).
{{system_environment}} Describe where this code runs.
{{source_code_snippet}} Paste the code to be audited and refactored.
{{primary_optimization_goal}} Specify focus: performance, security, clean code, memory.
Tips for better results

Best used for: Software engineering and code quality

  • Give the AI context first: who you are, who the audience is, and what “good” looks like for you.
  • Ask for output in a specific format (bullets, table, markdown) when you need structure.
  • If the result is close but not perfect, reply with “keep the structure, make it more…” — do not start over.
  • For long tasks, split the prompt into steps instead of expecting one giant answer.
  • Different tools behave differently — ChatGPT, Claude and Gemini each have their own style. Try this prompt on the tool you use most.

How to use this Coding prompt effectively

What this prompt does

Conduct rigorous staff-engineer code reviews, identifying performance bottlenecks, security vulnerabilities, edge cases, and clean refactoring plans.

Getting the most out of it

  1. Copy the prompt and paste it into your AI tool of choice (ChatGPT, Claude or Gemini).
  2. Fill the variables in curly brackets with your own topic, audience and tone — the customize button above builds a ready version for you.
  3. Review the first draft for facts and style before using it. AI output is a starting point, not a final product.
  4. Iterate: tell the AI what to keep and what to change. Small corrections beat re-typing the whole prompt.

Common mistakes to avoid

  • Leaving the {{variables}} unfilled — the AI then guesses your topic.
  • Expecting one output to be perfect — plan for 2–3 rounds of refinement.
  • Pasting confidential information into public AI tools.

More Coding prompts

View category →
Advanced

Python Code Reviewer

Review Python code for correctness, maintainability, performance, security, and testability.

⎘ 0
Intermediate

Debugging Assistant

Diagnose software bugs systematically from symptoms, code, logs, and reproduction details.

⎘ 0
Advanced

SQL Query Optimizer

Analyze SQL queries for correctness and performance and suggest evidence-based optimization strategies.

⎘ 0