Skip to main content

Claude/ChatGPT Prompt to Generate Code Documentation

Code documentation generator: PHPDoc/JSDoc comments, READMEs, API docs, and architecture decision records tailored to your audience.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
You are a senior engineer who writes documentation other developers actually keep open. Document the code accurately and return copy-ready output, not summaries of what docs should say.

Context:
- Code to document: <paste class or module>
- Language: PHP
- Doc comment format: PHPDoc
- Audience: mid-level developer joining the team

Deliver:
1) Doc comments in the chosen format for every public method and class.
2) Parameter descriptions with types and a realistic example value each.
3) Return-value documentation, including error or null cases.
4) Usage examples for the methods whose behaviour is non-obvious.
5) An architecture overview that explains the key design decisions, not just the structure.
6) A README section and a matching changelog entry.

Follow PSR-5 / standard conventions for the language, and write it clearly enough for the stated audience to onboard from it alone.

What this prompt does

This prompt instructs ChatGPT to produce a full documentation pass on a specific target — a class, module, API surface, or entire codebase — in one structured request. It works because the template forces six distinct documentation layers simultaneously: inline comments, type-annotated parameters, return value specs, usage examples, an architecture overview, and any additional doc type you define. That last slot ([additional_docs]) is what separates it from a generic "add comments" request — you can ask for an ADR, OpenAPI stub, or Postman description block in the same pass.

The [audience] variable is the most underrated part. Telling ChatGPT to write "clear enough for a junior Laravel developer" versus "a DevOps engineer reading an API contract" tends to produce structurally different output: one leans toward inline narrative explanation, the other toward tighter type contracts and HTTP status tables. The [style_guide] variable enforces house conventions — phpDocumentor-style PHPDoc for PHP, JSDoc or TSDoc for TypeScript, NumPy style for Python — so output slots into your codebase without a reformatting pass.

When to use it

  • You have a legacy class with zero comments and a code review coming up — feed the whole class as [target] and get PHPDoc blocks ready to paste.
  • You are open-sourcing a Laravel package and need a README plus docblock pass before the first public tag.
  • Your team's API grew organically and the front-end team is guessing at parameter types — use [additional_docs] = OpenAPI 3.0 YAML stub for each endpoint.
  • You onboarded a contractor who needs architecture context fast — set [audience] to "external contractor unfamiliar with the system" and [additional_docs] to "architecture decision record for the authentication flow."
  • You are writing a course or tutorial and need clean, illustrative docblocks as teaching examples.

Example output

For [target] = PostRepository, [language] = PHP, [doc_format] = PHPDoc, [audience] = mid-level developer:

/**
 * Retrieves published blog posts paginated by creation date.
 *
 * Applies Scout-based full-text filtering when $search is provided.
 * Falls back to Eloquent scope when Scout is unavailable.
 *
 * @param  int         $perPage  Posts per page. Default: 15. Range: 1–100.
 * @param  string|null $search   Optional Algolia search query.
 * @return LengthAwarePaginator<Post>
 *
 * @example
 *   $posts = $repo->getPaginated(perPage: 10, search: 'laravel queues');
 */
public function getPaginated(int $perPage = 15, ?string $search = null): LengthAwarePaginator

Pro tips

  • Be specific with [target] — paste the actual class name or file path, not "my code." ChatGPT documents what it can see; vague targets produce vague docs.
  • Set [additional_docs] = architecture decision record when the class has non-obvious design choices (e.g., why you used a Repository pattern over direct Eloquent). ADRs age far better than inline comments.
  • Chain requests by domain — run the prompt once per domain folder (Blog, Shop, Website) rather than dumping an entire codebase. Output stays coherent and token-efficient.
  • Use [style_guide] = PHPDoc with PHPStan generics if your project runs static analysis. Ask ChatGPT to use @return Collection<int, Post> and @template tags in the PHPStan dialect — these are consumed directly by PHPStan's type inference. If you run Psalm instead, specify [style_guide] = Psalm annotations to get @psalm-return and @psalm-template tags, which are distinct from PHPStan's syntax.
  • Paste the output into your IDE before accepting it — ChatGPT occasionally documents what a method should do rather than what it does. A 30-second diff against the actual implementation catches drift before it ships.

Frequently Asked Questions

Can I use this prompt for JavaScript or TypeScript projects, not just PHP?
Yes — set [language] to TypeScript and [doc_format] to JSDoc or TSDoc. TSDoc is the TypeScript-native standard (used by API Extractor and TypeDoc), while JSDoc works fine for plain JavaScript. The template is language-agnostic; the style guide variable does the heavy lifting for format-specific conventions.
What should I put in [additional_docs] for a REST API?
Try 'OpenAPI 3.0 YAML stub for each endpoint' or 'Postman collection description block.' The prompt already covers parameter types and return values inline, so [additional_docs] is the slot for the contract format your consumers actually import into their tools. Avoid asking for a CHANGELOG here — that requires git history the model cannot infer from source code alone.
The generated PHPDoc doesn't match what the method actually does — how do I fix that?
Paste the full method body into your message alongside the prompt. ChatGPT documents from source; if it only sees a method signature or a high-level description, it fills gaps with assumptions about intended behavior rather than actual behavior. Always include real implementation code when accuracy matters.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in ChatGPT Prompts for Developers

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support