Last Updated: 2025-12-21
Version: 1.7.1
This guide explains how to generate, view, and maintain API documentation for CGN-Bot.
Location: docs/COMMANDS.md
Generator: scripts/generate-command-docs.js
Automatically generated from command files with JSDoc comments.
Generate:
npm run docs:commandsCommand File Format:
/**
* @description Displays server information
* @example !serverinfo
* @example !si
*/
module.exports = class ServerInfoCommand {
constructor() {
this.name = 'serverinfo';
this.aliases = ['si'];
this.permissions = ['VIEW_CHANNEL'];
this.cooldown = 5;
}
async run(message, args) {
// Command logic
}
};Location: docs/api/
Generator: JSDoc
Configuration: jsdoc.json
Generated from JSDoc comments in source code.
Generate:
npm run docs:apiView Locally:
npm run docs:serve
# Open http://localhost:8080Individual module documentation with examples and usage guides.
Key Modules:
Modules/CacheEvents.js- Cache invalidation systemInternals/CommandExecutor.js- Command execution logicInternals/CommandMiddleware.js- Middleware frameworkModules/TierManager.js- Subscription/tier managementModules/ConfigManager.js- Configuration management
/**
* @fileoverview Brief description of the file
* Longer description with details about what this module does.
*
* @module Path/To/Module
* @requires dependency1
* @requires dependency2
*
* @example
* const MyModule = require('./Path/To/Module');
* const instance = new MyModule();
*//**
* Brief class description.
* Detailed explanation of what the class does and when to use it.
*
* @class ClassName
* @extends BaseClass
*
* @example
* const obj = new ClassName(param);
* obj.method();
*/
class ClassName {
/**
* Creates a new instance.
*
* @constructor
* @param {Type} param - Parameter description
*/
constructor(param) {
/**
* Instance property description
* @type {Type}
* @private
*/
this.property = param;
}
}/**
* Brief method description.
* Detailed explanation of what the method does.
*
* @param {string} param1 - First parameter description
* @param {Object} [param2] - Optional second parameter
* @param {number} [param2.value=10] - Nested property with default
* @returns {Promise<Object>} Description of return value
* @returns {boolean} return.success - Success flag
* @returns {string} [return.error] - Optional error message
*
* @throws {Error} When validation fails
*
* @example
* const result = await obj.method('value', { value: 20 });
* if (result.success) {
* console.log('Success!');
* }
*/
async method(param1, param2 = {}) {
// Implementation
}/**
* Brief function description.
*
* @function functionName
* @param {Type} param - Parameter description
* @returns {Type} Return description
*
* @example
* const result = functionName('input');
*/
function functionName(param) {
// Implementation
}| Tag | Usage | Example |
|---|---|---|
@param |
Function/method parameter | @param {string} name - User name |
@returns |
Return value | @returns {boolean} True if valid |
@throws |
Thrown exceptions | @throws {Error} When input invalid |
@example |
Usage example | @example const x = fn(); |
@type |
Variable type | @type {string} |
@private |
Private member | @private |
@deprecated |
Deprecated API | @deprecated Use newMethod instead |
@see |
Related docs | @see {@link OtherClass} |
@fires |
Emitted events | @fires MyClass#event |
@async |
Async function | @async |
/**
* @typedef {Object} UserProfile
* @property {string} id - User ID
* @property {string} username - Username
* @property {number} points - User points
* @property {Date} joinedAt - Join timestamp
*/
/**
* Get user profile
* @param {string} userId - User ID
* @returns {Promise<UserProfile>} User profile data
*/
async function getUserProfile(userId) {
// Implementation
}/**
* @param {string|number} id - String or number ID
* @param {Array<string>} tags - Array of strings
* @param {Object.<string, number>} map - String to number map
* @param {Function} callback - Callback function
* @param {(error: Error, result: Object) => void} callback - Typed callback
*/Add JSDoc comments while writing code:
/**
* New feature description
* @param {Type} param - Description
* @returns {Type} Description
* @example
* // Usage example
*/
function newFeature(param) {
// Implementation
}Generate and verify documentation:
# Generate all documentation
npm run docs:all
# Check for JSDoc errors
npm run docs:api 2>&1 | grep -i error
# Review generated docs
npm run docs:serve- Include updated documentation
- Add examples for new features
- Update CHANGELOG.md
- Verify API docs render correctly
- ✅ Document all public APIs
- ✅ Include practical examples
- ✅ Specify parameter types
- ✅ Document return values
- ✅ Note thrown exceptions
- ✅ Mark deprecated methods
- ✅ Use clear descriptions
- ❌ Document implementation details
- ❌ Leave examples without context
- ❌ Use vague descriptions
- ❌ Forget to update docs when code changes
- ❌ Document obvious getters/setters
- ❌ Use technical jargon without explanation
/**
* @fileoverview Message Create Event Handler
* Processes new messages and triggers command execution.
*
* @module Internals/Events/messageCreate
* @fires Client#commandExecuted
*/
/**
* Handle message creation event
* @param {Message} message - Discord message object
* @fires Client#commandExecuted
* @example
* // Automatically called by Discord.js
*/
async function handleMessageCreate(message) {
// Implementation
}/**
* @fileoverview User Database Model
* Handles user data persistence and queries.
*
* @module Database/Schemas/userSchema
*/
/**
* User schema definition
* @typedef {Object} UserSchema
* @property {string} _id - User Discord ID
* @property {string} username - Discord username
* @property {number} points - User economy points
* @property {Date} created_at - Account creation timestamp
*//**
* Format a number with thousand separators
*
* @function formatNumber
* @param {number} num - Number to format
* @param {string} [locale='en-US'] - Locale for formatting
* @returns {string} Formatted number string
*
* @example
* formatNumber(1234567);
* // Returns: '1,234,567'
*
* @example
* formatNumber(1234.56, 'de-DE');
* // Returns: '1.234,56'
*/
function formatNumber(num, locale = 'en-US') {
return num.toLocaleString(locale);
}Error: "Unable to parse a tag's type expression"
// ❌ Invalid
@param {string|number|} value
// ✅ Valid
@param {string|number} valueError: "Missing parameter name"
// ❌ Invalid
@param {string}
// ✅ Valid
@param {string} value- Clear old docs:
rm -rf docs/api - Regenerate:
npm run docs:api - Clear browser cache
- Check JSDoc warnings in console
Run audit to find undocumented code:
# Find files without @fileoverview
grep -r "^const\|^class\|^function" --include="*.js" Modules/ Internals/ | \
grep -v "@fileoverview"- Review new modules for documentation
- Update examples if APIs change
- Check for broken links
- Regenerate all documentation
- Update COMMANDS.md with new commands
- Review and update API examples
- Update version numbers
- Generate complete documentation
- Verify all examples work
- Update CHANGELOG.md
- Command Docs:
npm run docs:commands - API Docs:
npm run docs:api - All Docs:
npm run docs:all - View API Docs:
npm run docs:serve
Always document public APIs, include examples, and keep documentation up-to-date with code changes.