This project uses JSDoc for generating comprehensive API documentation from code comments.
After running the documentation generation, open docs/index.html in your browser to view the complete API documentation.
# Generate documentation
npm run docs
# Generate documentation and watch for changes
npm run docs:watch
# Serve documentation locally
npm run docs:serve
# Check documentation coverage and quality
node scripts/check-docs-coverage.js
# Version documentation for releases
npm run docs:version
# Complete release workflow (build + version)
npm run release:docs# Local viewing (after generation)
open docs/index.html # macOS
xdg-open docs/index.html # Linux
# Local server (recommended for development)
npm run docs:serve # Serves at http://localhost:8080The generated documentation includes:
- Classes: All major classes with detailed method documentation
- Global: API routes and standalone functions (see explanation below)
- Examples: Code examples showing how to use the API
- Type Information: Parameter and return types for all methods
- Error Handling: Information about exceptions that methods can throw
The Global section contains:
- All REST API endpoints (
GET /notes,POST /notes, etc.) - Complete with request/response examples
- HTTP status codes and error conditions
- Perfect reference for API consumers
createNotesRouter- Factory function for Express routes- Utility functions not tied to specific classes
Why are API routes in Global?
- JSDoc treats
@nametagged route documentation as standalone items - This creates a centralized API reference that's easy to navigate
- Alternative to having routes scattered across different module sections
NotesServer- Main server class for managing the application lifecycleNote- Data model representing a noteNoteRepository- Abstract base class for data access
CouchDbNoteRepository- CouchDB implementationMongoDbNoteRepository- MongoDB implementation
- Global Section - Complete REST API documentation with examples
/**
* Brief description of the function/class
*
* @param {type} paramName - Parameter description
* @returns {type} Return value description
* @throws {Error} When error conditions occur
* @example
* // Usage example
* const result = functionName(param);
*/@param {type} name - description- Documents parameters@returns {type} description- Documents return values@throws {Error} condition- Documents exceptions@example- Provides usage examples@class- Marks a constructor function as a class@extends- Documents class inheritance@name- Creates named documentation entries (used for API routes)
For API endpoints, we use a special pattern:
/**
* @name GET /notes
* @description Retrieve all active notes from the database
* @route GET /
* @returns {Object[]} 200 - Array of active note objects
* @returns {Object} 500 - Error response
* @example
* // Response format:
* [
* {
* "id": "note_123",
* "title": "Sample Note",
* "content": "This is a sample note content",
* "status": "active",
* "deletedAt": null,
* "createdAt": "2023-01-01T00:00:00.000Z",
* "updatedAt": "2023-01-02T00:00:00.000Z"
* }
* ]
*/The application now includes comprehensive recycle bin functionality with the following endpoints:
/**
* @name GET /notes/recycle-bin
* @description Retrieve all deleted notes from the recycle bin
* @route GET /recycle-bin
* @returns {Object[]} 200 - Array of deleted note objects
*/
/**
* @name GET /notes/recycle-bin/count
* @description Get the count of notes in recycle bin
* @route GET /recycle-bin/count
* @returns {Object} 200 - Count response with format { "count": 5 }
*/
/**
* @name DELETE /notes/recycle-bin
* @description Empty the recycle bin by permanently deleting all deleted notes
* @route DELETE /recycle-bin
* @returns {Object} 200 - Success response with count of deleted notes
*/
/**
* @name POST /notes/recycle-bin/restore-all
* @description Restore all notes from recycle bin
* @route POST /recycle-bin/restore-all
* @returns {Object} 200 - Success response with count of restored notes
*/
/**
* @name POST /notes/:id/restore
* @description Restore a note from recycle bin
* @route POST /:id/restore
* @returns {void} 204 - No content (successful restoration)
*/
/**
* @name DELETE /notes/:id
* @description Move a note to recycle bin (soft delete)
* @route DELETE /:id
* @returns {void} 204 - No content (successful move to recycle bin)
*/
/**
* @name DELETE /notes/:id/permanent
* @description Permanently delete a note
* @route DELETE /:id/permanent
* @returns {void} 204 - No content (successful permanent deletion)
*/Note: The /notes/trash endpoint is still available for backward compatibility but is deprecated. Use /notes/recycle-bin instead.
This creates comprehensive API documentation in the Global section.
- Keep documentation up to date with code changes
- Include practical examples for complex methods
- Document error conditions with
@throwstags - Use consistent terminology across all documentation
- Document all API endpoints with complete examples
Documentation should be regenerated whenever:
- New methods or classes are added
- Method signatures change
- JSDoc comments are updated
- API endpoints are modified
# Regenerate documentation
npm run docsFor active development, use the watch mode:
# Auto-regenerate on file changes
npm run docs:watchThe project includes automated quality checking with coverage analysis:
# Run comprehensive quality check
node scripts/check-docs-coverage.jsQuality Report Includes:
- 📊 Function Coverage: Percentage of documented functions
- 📊 Class Coverage: Percentage of documented classes
- ❌ Missing Documentation: List of undocumented code
⚠️ Quality Issues: Missing @returns, @example tags- 🎯 Overall Score: Combined documentation score
- Minimum threshold: 80% documentation coverage
- CI/CD enforcement: Builds fail below threshold
- Quality gates: Link checking and syntax validation
📊 Documentation Coverage Report
=====================================
📊 Functions: 12/15 (80.0%)
📊 Classes: 4/4 (100.0%)
✅ All functions and classes are documented!
⚠️ Documentation Quality Issues:
src/routes/notes-routes.js:45 - Missing: @example
🎯 Overall Documentation Score: 87.5%
✅ Documentation coverage meets 80% threshold
The JSDoc configuration is in jsdoc.config.json:
{
"source": {
"include": ["./src/", "./README.md"],
"includePattern": "\\.(js|jsx)$",
"exclude": ["node_modules/", "__tests__/"]
},
"opts": {
"destination": "./docs/",
"recurse": true,
"readme": "./README.md"
}
}The documentation system supports Node.js 20, 22, and 24 LTS:
{
"engines": {
"node": ">=20.0.0",
"npm": ">=10.0.0"
}
}Supported LTS Versions:
- ✅ Node.js 24: Primary development and CI version
- ✅ Node.js 22: Supported LTS
- ✅ Node.js 20: Supported LTS
The docs/ folder is added to .gitignore since documentation is generated from source code.
This project includes an optimized single-job workflow for documentation that provides:
- ✅ Fast execution (~2-3 minutes vs 4-5 minutes for multi-job)
- ✅ Quality gates with link checking and coverage validation
- ✅ Automatic deployment to GitHub Pages on main branch
- ✅ Resource efficiency (single checkout, Node.js setup, and npm install)
# Optimized single-job pipeline (.github/workflows/docs.yml)
jobs:
docs-pipeline:
steps:
# 1. Setup (once)
- Checkout code
- Setup Node.js 24 (LTS)
- Install dependencies
# 2. Build
- Generate documentation
# 3. Quality checks
- Check for broken links
- Validate JSDoc coverage
# 4. Deploy (main branch only)
- Deploy to GitHub Pages- Pull Requests: Build + Quality checks (no deployment)
- Main branch pushes: Build + Quality checks + GitHub Pages deployment
- Releases: Full pipeline with deployment
- Link validation using linkinator
- Documentation coverage analysis
- JSDoc syntax validation
- Deployment only after all checks pass
- Single job design eliminates redundant setups
- Conditional deployment (main branch only)
- Artifact upload only on failure or PRs (for debugging)
- Node.js 24 LTS for stability and performance
- Missing documentation: Ensure JSDoc comments follow proper syntax
- Items in Global section: Check if functions/routes need proper module assignment
- Missing examples: Add
@exampletags for better usability
Review generated documentation in docs/index.html to ensure:
- All classes and methods appear
- Examples render correctly
- Links between modules work
- Type information is accurate
- Start with Classes for understanding the code structure
- Use Global section for quick API reference
- Check individual source files for implementation details
- Follow cross-references between related components
Documentation is automatically deployed to GitHub Pages on every push to the main branch:
- 🌐 Live URL:
https://username.github.io/repository-name/ - 🔄 Auto-updates: Reflects latest code changes automatically
- 🛡️ Quality-gated: Only deploys after passing all checks
- ⚡ Fast deployment: ~2-3 minutes from push to live
For other hosting platforms:
# Generate documentation
npm run docs
# Deploy docs/ folder to your preferred hosting:
# - Netlify: Connect to repository with build command "npm run docs"
# - Vercel: Same approach with "npm run docs"
# - AWS S3: Upload docs/ folder contents
# - Custom server: Serve docs/ as static filesOnce deployed, users can access:
- 📖 Main documentation:
/index.html - 🌐 API reference:
/global.html - 📦 Class documentation:
/ClassName.html - 📄 Source code:
/filename.js.html
The generated documentation is optimized for:
- ✅ Fast loading: Minified CSS/JS, optimized assets
- ✅ SEO friendly: Semantic HTML structure
- ✅ Mobile responsive: Works on all device sizes
- ✅ Search indexable: Proper meta tags and structure