Understand an Existing Codebase
Help me understand this part of a codebase. How the main pieces fit together.
This prompt
Help me understand this part of a codebase: [Paste code or describe module] Explain: - What it does - How the main pieces fit together - Where the important logic lives - What I should be careful about when changing it
Related prompt
# Task Write unit tests for the code below using [Test framework] in [Language]. # Code under test [Code under test] # Intended behavior [Intended behavior] # Dependencies to replace with test doubles [Dependencies to mock] # Existing test conventions [Existing test conventions] # Part A - Case inventory (write this first) Produce a table with the columns: ID, behavior being checked, input or setup, expected result, category. Cover these categories where they apply: - Typical: the main paths a caller relies on. - Boundary: empty, zero, one, maximum, first and last element, exact threshold values. - Invalid input: wrong type, missing field, out-of-range value. - Error paths: each exception or error return, and failures from each dependency. - State: repeated calls, ordering, anything that should or should not be mutated. Leave out cases that only re-test the language or a library. If the intended behavior does not say what should happen for a case, put "UNSPECIFIED" as the expected result and list the question for me instead of inventing an answer. # Part B - Tests Write the tests for every case that has a specified expected result. - One behavior per test. Name each test so that a failure reads as a sentence about the behavior, not about the function name. - Lay each test out as arrange, act, assert, and keep logic (loops, conditionals) out of test bodies. Use the framework's parameterized form for cases that differ only in data. - Assert on return values and observable effects. Do not assert on private helpers, internal call order or exact log text unless that is the behavior. - Replace only the dependencies listed above. Do not mock the code under test or plain data objects. - Take expected values from the intended behavior, never by copying what the current code would produce. If the code appears to disagree with the intended behavior, still write the test for the intended behavior and mark it with a comment starting SUSPECTED BUG. - Keep tests deterministic: fix the clock, random seeds and any ordering the code does not guarantee. No real network, file system or database access. - Use only assertion and mocking functions that exist in [Test framework]. If you are unsure of an API, say so in the notes. # Part C - Notes List: suspected bugs with the case ID, unspecified cases as questions, anything in the code that is hard to test and the smallest change that would make it testable, and the command to run the tests. # Output Part A as a table, Part B as one fenced code block per test file with the filename above it, Part C as short lists.
All Coding prompts
Bug Diagnosis Prompt
Give the model the error, the code and what you expected. It ranks likely causes by evidence, tells you how to confirm each, and proposes a minimal fix.
Add Defensive Checks
Suggest defensive checks and guards that would make this code safer.
Algorithmic Improvement
Suggest a more efficient approach for this code if appropriate.
Ask for Multiple Approaches
Propose 2–3 different implementation approaches for this problem.
Before / After Refactor Plan
Create a safe refactor plan for this code. Break the improvements into small steps I can apply and verify one at a time.
Behavior-Preserving Refactoring Prompt
Restructures code in small, named steps while holding its observable behavior fixed, and reports anything it could not prove equivalent.
Clear Spec to Code
Write clean and maintainable code for this requirement.
Code with Explicit Assumptions
Generate code for this task. Before writing the code, list your assumptions.
Constrain the Style
Generate code for this task using these style rules.
Debug a Specific Problem
I’m seeing this bug. Here is the relevant code.
Debug with Structure
I’m facing this bug. Here is the relevant code.
Dependency Review
Analyse the dependencies in this code and suggest ways to reduce unnecessary coupling.
Design Before Coding
Help me design a clean solution before writing code.
Design Review
Review the design decisions in this code. Comment on coupling, cohesion and separation of concerns.
Edge Case Analysis
Identify important edge cases this code may not handle well.
Error Handling Review
Review the error handling in this code. Suggest clearer and more reliable handling of failures.
Explain Code Clearly
Explain what this code does in plain language.
Explain Risk Areas
Identify the riskiest parts of this code and explain why they need careful attention.
Extract Functions / Modules
Refactor this code by extracting clearer functions or modules.
Fill in a Partial Implementation
Complete this partially written code. Keep the existing structure and style.
Find Likely Bugs
Analyse this code for likely bugs and edge-case failures.
Full Code Review
Review this code for correctness, readability, maintainability and potential bugs.
Generate + Explain
Write code for this task. How the solution works.
Generate Code + Tests Together
Write the code and useful tests for this requirement.
Generate Tests
Write useful tests for this code. Happy path tests.
Idiomatic Code
Refactor this code to be more idiomatic for your language.
Improve Comments
Suggest better comments for this code where they would actually help.
Improve Error Handling
Improve the error handling in this code. Make failures clearer, safer, and easier to debug.
Improve Naming
Suggest better names for variables, functions and classes in this code.
Input Validation
Suggest stronger input validation for this code.
Interface / API Clarity
Review this interface/API for clarity and ease of use.
JavaScript and TypeScript Function Prompt
A contract-first prompt: the model fixes the signature, types and error behavior of a function or module before it writes the implementation.
Memory / Resource Usage
Analyse this code for potential memory or resource usage problems.
Minimise Complexity
Write the simplest correct solution for this problem.
Missing Test Cases
Review this code and suggest the most important test cases that are likely missing.
Optimise Without Premature Complexity
Review this code for meaningful performance improvements.
Performance Review
Review this code for meaningful performance issues.
Prioritised Review Summary
Review this code and give me a prioritised summary.
Production-Minded Generation
Write production-minded code for. Clear structure.
Python Script and Module Prompt
Turns a plain-language spec into a complete, typed Python script or module, with assumptions, run commands and edge cases listed separately.
Race Conditions / Concurrency Issues
Analyse this code for concurrency or race condition risks.
Reduce Nesting
Refactor this code to reduce nesting and improve control flow.
Refactor for Clarity
Refactor this code to improve clarity and readability while preserving behaviour.
Refactor for Clarity (Productivity Version)
Refactor this code to make it cleaner and easier to maintain.
Remove Duplication
Identify duplication in this code and refactor to reduce it.
Replace Complex Logic with Clearer Structure
Propose a cleaner structure for this complex logic.
Review for Maintainability
Evaluate how maintainable this code is. Identify what would make it harder to change later and suggest improvements.
Review for Readability
Review this code purely from a readability perspective.
Review for Simplicity
Review this code and suggest ways to simplify it without changing behaviour.
Safe Defaults
Identify unsafe defaults or risky assumptions in this code and recommend safer alternatives.
Security Review
Review this code for common security issues. Focus on input validation, injection risks, secrets handling and unsafe defaults.
Simplify Conditional Logic
Refactor the conditional logic in this code to make it easier to understand.
Step-by-Step Implementation
Help me implement this feature in small steps.
Strengths and Weaknesses
Review this code and list. What’s done well.
Style Consistency
Review this code for style and consistency issues.
Testability Review
Evaluate how testable this code is and suggest changes that would make testing easier.
Turn Requirements into an Implementation Plan
Turn this feature request into a clear implementation plan.
Understand an Existing Codebase
Help me understand this part of a codebase. How the main pieces fit together.
Unit Test Writing Prompt
Produces a case inventory first, then readable tests that check behavior at the boundaries, with suspected bugs flagged instead of encoded as passing.
Write Clean Code from a Clear Spec
Write clean, readable, and production-minded code for this task.
Write a Clear Summary
Summarise what this code does in plain language.
Related guides
Technical guide
10 AI Prompts for Faster, Cleaner Coding
Practical prompts that help you write, debug, refactor, understand and ship code faster.