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.
[]()
[]()
[]()
## 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): Descriptionparam2(number, optional): Description
Returns: Description of return value
Example:
// Example usage
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
| option1 | string | βdefaultβ | What this option does |
| option2 | boolean | false | What this option does |
Contributing
Contributions are welcome! Please read our Contributing Guide first.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
- π§ Email: support@example.com
- π¬ Discord: Join our server
- π Issues: GitHub Issues
Acknowledgments
- Thanks to contributor
- Inspired by project
## 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
| page | number | No | Page number (default: 1) |
| limit | number | No | Items per page (default: 20) |
| role | string | No | Filter 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 token403 Forbidden- Insufficient permissions500 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