Code Documentation Generator

Category: Documentation October 15, 2025

Generate comprehensive code documentation including JSDoc, README, and API references.

DocumentationJSDocCommentsREADMEAPI Docs
# Code Documentation Generator

Generate comprehensive, clear documentation for code including inline comments, JSDoc, README files, and API references.

## Documentation Types

### 1. Inline Comments
- Explain complex logic
- Document non-obvious decisions
- Clarify business rules
- Note TODO items and technical debt

### 2. JSDoc/DocStrings
- Function/method documentation
- Parameter descriptions
- Return value descriptions
- Usage examples
- Type information

### 3. README Files
- Project overview
- Installation instructions
- Usage examples
- Configuration options
- Contributing guidelines

### 4. API Documentation
- Endpoint descriptions
- Request/response formats
- Authentication requirements
- Error responses
- Code examples

## JSDoc Examples

### Function Documentation
```typescript
/**
 * Calculates the total price including tax and discounts
 * 
 * @param {number} basePrice - The original price before any modifications
 * @param {number} taxRate - Tax rate as a decimal (e.g., 0.08 for 8%)
 * @param {number} [discount=0] - Optional discount as a decimal (e.g., 0.15 for 15% off)
 * @returns {number} The final price after tax and discount
 * 
 * @throws {Error} If basePrice or taxRate is negative
 * @throws {Error} If discount is not between 0 and 1
 * 
 * @example
 * // Calculate price with 8% tax and 10% discount
 * const finalPrice = calculateTotal(100, 0.08, 0.10);
 * // Returns: 97.20
 * 
 * @example
 * // Calculate price with tax only
 * const finalPrice = calculateTotal(100, 0.08);
 * // Returns: 108.00
 */
export function calculateTotal(
  basePrice: number,
  taxRate: number,
  discount: number = 0
): number {
  if (basePrice < 0 || taxRate < 0) {
    throw new Error('Price and tax rate must be non-negative');
  }
  if (discount < 0 || discount > 1) {
    throw new Error('Discount must be between 0 and 1');
  }
  
  const discountedPrice = basePrice * (1 - discount);
  const total = discountedPrice * (1 + taxRate);
  return Math.round(total * 100) / 100;
}

Class Documentation

/**
 * Manages user authentication and session handling
 * 
 * @class AuthService
 * @implements {IAuthService}
 * 
 * @example
 * const authService = new AuthService({
 *   tokenExpiry: 3600,
 *   refreshEnabled: true
 * });
 * 
 * const session = await authService.login('user@example.com', 'password');
 */
export class AuthService implements IAuthService {
  private tokenExpiry: number;
  private refreshEnabled: boolean;
  
  /**
   * Creates an instance of AuthService
   * 
   * @param {AuthConfig} config - Authentication configuration
   * @param {number} config.tokenExpiry - Token expiry time in seconds
   * @param {boolean} config.refreshEnabled - Whether to enable token refresh
   */
  constructor(config: AuthConfig) {
    this.tokenExpiry = config.tokenExpiry;
    this.refreshEnabled = config.refreshEnabled;
  }
  
  /**
   * Authenticates a user and creates a session
   * 
   * @async
   * @param {string} email - User's email address
   * @param {string} password - User's password
   * @returns {Promise<Session>} The authenticated session
   * @throws {AuthError} If credentials are invalid
   * @throws {AccountLockedError} If account is locked
   */
  async login(email: string, password: string): Promise<Session> {
    // Implementation
  }
}

README Template

# Project Name

Brief description of what this project does and who it's for.

[![Build Status](https://img.shields.io/badge/build-passing-brightgreen)]()
[![License](https://img.shields.io/badge/license-MIT-blue)]()
[![Version](https://img.shields.io/badge/version-1.0.0-blue)]()

## Features

- πŸš€ Fast and lightweight
- πŸ“¦ Easy to integrate
- πŸ”’ Secure by default
- 🎨 Fully customizable
- πŸ“± Mobile responsive

## Installation

```bash
npm install project-name
# or
yarn add project-name
# or
pnpm add project-name

Quick Start

import { SomeFunction } from 'project-name';

const result = SomeFunction({
  option1: 'value',
  option2: true
});

console.log(result);

Usage

Basic Example

// Code example

Advanced Example

// More complex example

API Reference

functionName(param1, param2)

Description of what the function does.

Parameters:

  • param1 (string): Description
  • param2 (number, optional): Description

Returns: Description of return value

Example:

// Example usage

Configuration

OptionTypeDefaultDescription
option1string’default’What this option does
option2booleanfalseWhat this option does

Contributing

Contributions are welcome! Please read our Contributing Guide first.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Running Tests

npm test
npm run test:coverage

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Acknowledgments


## API Documentation Template

```markdown
# API Documentation

## Authentication

All API requests require authentication using Bearer tokens:

```http
Authorization: Bearer YOUR_API_TOKEN

Endpoints

Get Users

Retrieves a paginated list of users.

Endpoint: GET /api/v1/users

Query Parameters:

ParameterTypeRequiredDescription
pagenumberNoPage number (default: 1)
limitnumberNoItems per page (default: 20)
rolestringNoFilter by role

Response:

{
  "data": [
    {
      "id": 1,
      "email": "user@example.com",
      "name": "John Doe",
      "role": "user",
      "created_at": "2025-10-15T10:00:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 100
  }
}

Example:

curl -H "Authorization: Bearer TOKEN" \
  "https://api.example.com/v1/users?page=1&limit=10"

Error Responses:

  • 401 Unauthorized - Invalid or missing token
  • 403 Forbidden - Insufficient permissions
  • 500 Internal Server Error - Server error

## Documentation Checklist

- [ ] All public functions documented
- [ ] Parameter types and descriptions included
- [ ] Return values documented
- [ ] Examples provided
- [ ] Edge cases mentioned
- [ ] Errors documented
- [ ] README is up to date
- [ ] API endpoints documented
- [ ] Configuration options explained
- [ ] Contributing guide provided