Skip to content

Documentation Generation

Documentation is often neglected because it’s tedious. ralph makes it systematic—iterate until everything is documented.

Add JSDoc comments to all exported functions.

Terminal window
ralph init

Edit .ralph/config.toml:

adapter = "claude"
maxIterations = 40
# Add JSDoc Documentation
Add JSDoc comments to all exported functions, classes, and types.
## JSDoc Format
### Functions
```typescript
/**
* Brief description of what the function does.
*
* @param paramName - Description of parameter
* @returns Description of return value
* @throws {ErrorType} When this error occurs
*
* @example
* ```typescript
* const result = myFunction('input');
* ```
*/
export function myFunction(paramName: string): ReturnType {
/**
* Brief description of the class purpose.
*
* @example
* ```typescript
* const instance = new MyClass();
* instance.doSomething();
* ```
*/
export class MyClass {
/**
* Describes what this type represents.
*/
export interface MyInterface {
/** Description of property */
propertyName: string;
}
  • Document ALL exports (functions, classes, interfaces, types)
  • Include @param for every parameter
  • Include @returns for non-void functions
  • Include @throws for functions that throw
  • Include @example for complex functions
  • Keep descriptions concise but complete

Track completed files in progress.txt

  1. Run ESLint to find undocumented exports
  2. Document one file at a time
  3. Run ESLint again to verify
  4. Commit: “docs(file): add JSDoc comments”

When npx eslint src/ --rule 'jsdoc/require-jsdoc: error' shows 0 errors, output: COMPLETE

## Example: README Generation
Generate README files for each package in a monorepo.
### Prompt
```markdown
# Generate Package READMEs
Create README.md files for each package in the monorepo.
## README Template
```markdown
# package-name
Brief description from package.json.
## Installation
\`\`\`bash
npm install package-name
\`\`\`
## Usage
\`\`\`typescript
import { mainExport } from 'package-name';
// Basic usage example
\`\`\`
## API
### `functionName(params): ReturnType`
Description of function.
**Parameters:**
- `param1` - Description
**Returns:** Description
## License
MIT

Track completed packages in progress.txt

  1. Find packages without README: find packages -maxdepth 2 -name 'package.json' -exec dirname {} \;
  2. Read package.json and source code
  3. Generate README following template
  4. Commit: “docs(package): add README”

When every package directory has a README.md, output: COMPLETE

## Example: API Documentation
Generate OpenAPI/Swagger documentation from code.
### Prompt
```markdown
# Generate API Documentation
Add OpenAPI annotations to all API routes.
## Annotation Format (using tsoa)
```typescript
/**
* @summary Get user by ID
* @param userId The user's unique identifier
* @returns User object
*/
@Get('{userId}')
@Response<NotFoundError>(404, 'User not found')
@Response<ValidationError>(400, 'Invalid user ID')
public async getUser(
@Path() userId: string
): Promise<User> {
  • Every route must have @summary
  • All parameters documented with @param
  • Response types documented with @Response
  • Error responses documented
  • Request body types defined
  1. Find undocumented routes
  2. Add annotations
  3. Run npm run docs:generate
  4. Validate with npm run docs:validate
  5. Commit

When npm run docs:validate passes, output: COMPLETE

## Tips for Documentation Tasks
### 1. Provide Examples
Include examples of good documentation:
```markdown
## Good JSDoc Example
[Include a well-documented function from your codebase]

Be explicit about style:

## Style Guidelines
- Use present tense ("Returns" not "Will return")
- Start with verb ("Gets the user" not "This function gets")
- Keep first line under 80 characters
- Use @example for anything non-obvious

Give the AI a way to check its work:

## Validation
Run `npm run lint:docs` to check documentation completeness.

Document how to handle tricky situations:

## Edge Cases
- Private methods: Don't document unless complex
- Generated code: Skip files in src/generated/
- Deprecated functions: Include @deprecated tag