Code Documentation Standards

This document defines the documentation standards for inline code comments, JSDoc annotations, module documentation, and API reference formatting across the MiningOS ecosystem.

For code style and linting requirements, see Testing & Linting Guidelines.


Overview

Well-documented code is essential for maintaining a complex distributed system like MiningOS. Documentation serves multiple audiences: contributors, future maintainers, API consumers, and operators configuring deployments.

Documentation Philosophy

MiningOS follows these documentation principles:

Principle
Description

Self-documenting code first

Clear naming and structure reduce comment needs

Document the "why"

Code shows "what" and "how"; comments explain "why"

Keep it current

Outdated documentation is worse than none

Audience-aware

Match detail level to the reader's needs

When to Document

Always Document

Consider Documenting

  • Complex algorithms

  • Non-obvious decisions

  • Performance optimizations

  • Workarounds and edge cases

Skip Documentation

  • Obvious operations

  • Self-explanatory getters or setters

  • Standard patterns

  • Trivial utility functions

File Headers

Every JavaScript file begins with 'use strict' followed by appropriate header documentation. For the complete file structure, see Repository Structure — Standard Directory Structure.

Standard Header Pattern

Worker File Headers

Worker entry points include operational context:

For supported power meter models and specifications, see Supported Devices — Power Meters.

Library File Headers

Library modules document their exports and dependencies:


JSDoc Annotations

MiningOS uses JSDocarrow-up-right for function and class documentation. While Standard.jsarrow-up-right doesn't enforce JSDoc, consistent usage improves code navigation and IDE support.

Function Documentation

For error code conventions, see Contribution Workflow — Error Handling.

Class Documentation

For Whatsminer specifications, see Supported Devices — MicroBT Whatsminer.

Type Definitions

Define complex types for reuse across documentation:

For pool configuration in production, see Operator Manual — Pool Manager Module.

Common JSDoc Tags

Tag
Usage
Example

@async*

Async functions

@async

@param

Function parameters

@param {string} id - Device ID

@returns

Return value

@returns {Promise<Object>}

@throws

Possible errors

@throws {Error} ERR_INVALID_SOMETHING

@example

Usage examples

See above

@private

Internal methods

@private

@deprecated

Deprecated features

@deprecated Use newMethod instead

@see

Related resources

@see {@link otherFunction}

@since

Version introduced

@since 1.2.0

*Available in JSDoc 3.5.0 and later

For more information and to learn about custom tags, check out the JSDoc official websitearrow-up-right.


Inline Comments

Inline comments explain non-obvious code behavior. They should add value beyond what the code already communicates.

When to Use Inline Comments

Use comments for:

The examples below highlight application of doctrine stated in Overview:

Comment Style Guidelines

Section Markers

Use section markers for long files to improve navigation:

Anti-Patterns to Avoid

Anti-Pattern
Example
Problem

Commented-out code

// await oldMethod()

Use version control instead

Journal comments

// Fixed bug - John 2024-01-15

Use git history (see Branching & PR Conventions)

Noise comments

// End of function

Adds no value

Lying comments

Comment says X, code does Y

Misleads readers

Excessive comments

Every line commented

Obscures the code


Constants Documentation

Constants files serve as authoritative references for magic values throughout the codebase.

Constant Object Documentation

For the complete list of supported models and specifications, see Supported Devices.

Enumeration-Style Constants

For how these statuses appear in the UI, see Operator Manual — Explorer.

Configuration Constants


README Documentation

Every repository requires a README.md with standardized sections. For the complete repository structure, see Repository Structure.

README Structure

API Reference Sections

Structure RPC documentation consistently. Example with a single method:

Code Examples in README

Provide practical, copy-paste-ready examples:

For complete RPC registration examples, see Installation Guide — Register Workers.

Above, an example of Markdown syntax for copy-paste-ready excerpt for code in bash (for convenience, the example itself is in copy-paste-ready format).

License Section

All MiningOS repositories must include a License section and be released under the Apache License 2.0. This is mandatory for ecosystem consistency and legal clarity.

Required License Section Format

Note: The Apache 2.0 licensearrow-up-right was chosen for MiningOS to enable broad adoption while providing patent protection and requiring attribution. All contributions to MiningOS repositories are subject to this license.


Error Message Documentation

Consistent error documentation helps operators diagnose issues quickly. For error handling patterns in code, see Contribution Workflow — Error Handling.

Error Code Registry

Maintain a central error code reference:

For how errors appear in the operator interface, see Operator Manual — Alerts Manual.

Error Context

When throwing errors, include helpful context:


Documentation Maintenance

Documentation Review Checklist

Before submitting a PR (see Branching & PR Conventions — PR Checklist), verify documentation is complete:

Last updated