Process Documentation: Industry Standards & Best Practices
This guide covers industry-standard approaches for documenting backend processes and how to automate documentation generation from code comments.
đ¯ Overviewâ
Process documentation helps non-developer teams understand what happens when they trigger actions in the system. This is especially important for:
- Transparency - Non-dev teams need to see what happens behind the scenes
- Troubleshooting - Understanding the full flow helps diagnose issues
- Onboarding - New team members can understand complex workflows
- Compliance - Documented processes support audit requirements
đ Industry Standard Approachesâ
1. Code-First Documentation (â What We Use)â
Description: Structured comments in code that are automatically extracted and converted to documentation.
Pros:
- â Documentation lives with code (single source of truth)
- â Version-controlled alongside code changes
- â Developer-friendly workflow
- â Can be validated in CI/CD
- â Stays close to implementation
Cons:
- â ī¸ Requires developer discipline
- â ī¸ Can get out of sync if not maintained
- â ī¸ Requires custom tooling
Tools:
- JSDoc/TSDoc with custom tags
- YAML manifests for process definitions
- Custom documentation generators
Best For: Teams that want documentation tightly coupled with code.
2. OpenAPI/Swagger (â What We Use for APIs)â
Description: Standard specification for REST API documentation, auto-generated from code annotations.
Pros:
- â Industry standard
- â Interactive documentation (try endpoints)
- â Auto-generated from code
- â Tooling ecosystem (Redoc, Swagger UI)
- â Client code generation
Cons:
- â ī¸ Only covers API endpoints
- â ī¸ Doesn't document internal processes
- â ī¸ Limited to request/response flows
Best For: API documentation and external integrations.
3. Architecture Decision Records (ADRs)â
Description: Markdown files documenting why architectural decisions were made.
Structure:
docs/adr/
0001-use-strapi-for-cms.md
0002-postgresql-database-choice.md
0003-process-documentation-system.md
Pros:
- â Captures decision context
- â Historical record
- â Helps future developers understand "why"
Cons:
- â ī¸ Not process-focused
- â ī¸ More about decisions than workflows
Best For: Documenting architectural choices and their rationale.
4. Sequence Diagrams from Codeâ
Description: Visual flow diagrams generated from code annotations (Mermaid, PlantUML).
Example:
/**
* @sequence-diagram
* User->Frontend: Click button
* Frontend->Backend: API call
* Backend->Database: Save data
* Backend->Email: Send notification
*/
Pros:
- â Visual representation
- â Easy to understand flow
- â Can be auto-generated
Cons:
- â ī¸ Can be verbose
- â ī¸ Requires diagram syntax knowledge
- â ī¸ May not capture all details
Best For: Visual process flows and team presentations.
5. Documentation-as-Code (Markdown in Repo)â
Description: Markdown files in repository that are manually maintained.
Pros:
- â Version-controlled
- â Easy to edit
- â Collaborative (PRs)
Cons:
- â ī¸ Can drift from code
- â ī¸ Manual maintenance burden
- â ī¸ Often outdated
Best For: High-level documentation, guides, tutorials.
6. External Documentation Platformsâ
Description: Tools like Confluence, Notion, GitBook, or dedicated wikis.
Pros:
- â Rich formatting
- â Easy for non-devs
- â Search capabilities
- â Comments and collaboration
Cons:
- â ī¸ Separate from code
- â ī¸ Often becomes outdated
- â ī¸ No automatic sync
- â ī¸ Additional tooling cost
Best For: High-level business documentation, not technical processes.
đ Recommended Approach: Hybrid Systemâ
Best Practice: Combine multiple approaches for comprehensive coverage:
- Code Comments â Process documentation (what we have)
- OpenAPI â API reference (what we have)
- ADRs â Architecture decisions (optional)
- Markdown Guides â High-level overviews (what we have)
đ Our Current Systemâ
We use a three-layer approach:
Layer 1: Code Commentsâ
Structured JSDoc-style comments in source code:
/**
* @process-id PROGRAM-CONFIGURATION-HANDOVER
* @process-step 2.1
* @repo strapi-docker
* @description Automatically tracks configuration changes before save
* @implicit Automatic Strapi lifecycle hook
* @triggers PROGRAM-CONFIGURATION-HANDOVER:2.2
*/
Layer 2: Process Manifestsâ
YAML files defining complete workflows:
process:
id: PROGRAM-CONFIGURATION-HANDOVER
name: Program Configuration Handover
description: |
Complete workflow for transferring program configuration
from Sales team to Learning team
owner:
- team-sales
- team-learning
repositories:
- platform
- strapi-docker
steps:
- id: "1.0"
type: user-action
repo: platform
description: User clicks "Handover Configuration" button
explicit: true
Layer 3: Generated Documentationâ
Auto-generated Docusaurus pages with:
- Step-by-step breakdowns
- Mermaid sequence diagrams
- Code references
- Side effects documentation
- Error handling
đ Automating Documentation Generationâ
Current Stateâ
â Manual Generation:
cd documentation
node scripts/generate-process-docs.js
Recommended: Automatic on Mergeâ
Add CI/CD automation to generate and commit documentation automatically when code changes.
đ Implementation: Auto-Generate on Mergeâ
Option 1: Backend Repository Workflow (Recommended)â
Create a workflow in strapi-docker/.github/workflows/update-process-docs.yml:
name: Update Process Documentation
on:
push:
branches:
- main
- develop
paths:
- 'src/**/*.js'
- 'src/**/*.ts'
- 'documentation/process-registry/**/*.yml'
jobs:
update-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout Backend Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Checkout Documentation Repository
uses: actions/checkout@v4
with:
repository: DeepSkill/documentation
token: ${{ secrets.DOCUMENTATION_REPO_TOKEN }}
path: documentation
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: documentation/package-lock.json
- name: Install Documentation Dependencies
run: |
cd documentation
npm ci
- name: Detect Changed Process Files
id: detect
run: |
cd documentation
# Find changed YAML files in process-registry
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD | grep 'process-registry/.*\.yml$' || true)
if [ -z "$CHANGED_FILES" ]; then
# Check if any code files changed that might have process comments
CODE_CHANGES=$(git diff --name-only HEAD~1 HEAD | grep -E '\.(js|ts|jsx|tsx)$' || true)
if [ -n "$CODE_CHANGES" ]; then
echo "Code files changed - regenerating all process docs"
echo "regenerate_all=true" >> $GITHUB_OUTPUT
else
echo "No process-related changes detected"
echo "regenerate_all=false" >> $GITHUB_OUTPUT
fi
else
echo "Process manifest files changed"
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "regenerate_all=false" >> $GITHUB_OUTPUT
fi
- name: Generate Process Documentation
id: generate
run: |
cd documentation
if [ "${{ steps.detect.outputs.regenerate_all }}" = "true" ]; then
echo "đ Regenerating all process documentation..."
node scripts/generate-process-docs.js
echo "regenerated=true" >> $GITHUB_OUTPUT
else
# Extract process IDs from changed files
CHANGED_FILES="${{ steps.detect.outputs.changed_files }}"
if [ -n "$CHANGED_FILES" ]; then
for file in $CHANGED_FILES; do
PROCESS_ID=$(basename "$file" .yml | tr '[:lower:]' '[:upper:]')
echo "đ Regenerating documentation for: $PROCESS_ID"
node scripts/generate-process-docs.js "$PROCESS_ID"
done
echo "regenerated=true" >> $GITHUB_OUTPUT
else
echo "No documentation to regenerate"
echo "regenerated=false" >> $GITHUB_OUTPUT
fi
fi
- name: Commit and Push Documentation
if: steps.generate.outputs.regenerated == 'true'
run: |
cd documentation
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add docs/internal/processes/detailed/
if git diff --staged --quiet; then
echo "âšī¸ No documentation changes to commit"
else
git commit -m "docs: auto-update process documentation
Source: ${{ github.repository }}@${{ github.sha }}
Branch: ${{ github.ref_name }}
Auto-generated from process manifests and code comments."
git push
echo "â
Documentation updated"
fi
- name: Create Job Summary
if: always()
run: |
echo "## đ Process Documentation Update" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Source:** ${{ github.repository }}@${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "**Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.generate.outputs.regenerated }}" = "true" ]; then
echo "â
Process documentation regenerated" >> $GITHUB_STEP_SUMMARY
else
echo "âšī¸ No documentation changes needed" >> $GITHUB_STEP_SUMMARY
fi
Option 2: Documentation Repository Workflowâ
Alternatively, trigger from documentation repository when process manifests change:
name: Generate Process Documentation
on:
push:
branches:
- main
paths:
- 'process-registry/**/*.yml'
- 'scripts/generate-process-docs.js'
jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- name: Generate All Process Docs
run: node scripts/generate-process-docs.js
- name: Commit Generated Docs
run: |
git config user.name "GitHub Action"
git config user.email "action@github.com"
git add docs/internal/processes/detailed/
git diff --staged --quiet || git commit -m "docs: auto-update process documentation"
git push
đ Process Comment Extraction (Advanced)â
For even more automation, extract process comments directly from code:
Script: Extract Process Commentsâ
// scripts/extract-process-comments.js
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
/**
* Extracts @process-* comments from code files
*/
function extractProcessComments(repoPath) {
const processComments = [];
// Find all JS/TS files
const files = execSync(
`find ${repoPath} -type f \\( -name "*.js" -o -name "*.ts" -o -name "*.jsx" -o -name "*.tsx" \\)`,
{ encoding: 'utf-8' }
).trim().split('\n');
files.forEach(file => {
const content = fs.readFileSync(file, 'utf-8');
const lines = content.split('\n');
let inProcessComment = false;
let commentBlock = [];
let lineNumber = 0;
lines.forEach((line, idx) => {
if (line.includes('@process-id')) {
inProcessComment = true;
lineNumber = idx + 1;
commentBlock = [line];
} else if (inProcessComment) {
commentBlock.push(line);
if (line.includes('*/')) {
// Parse comment block
const processInfo = parseProcessComment(commentBlock.join('\n'));
if (processInfo) {
processComments.push({
...processInfo,
file: path.relative(repoPath, file),
line: lineNumber
});
}
inProcessComment = false;
commentBlock = [];
}
}
});
});
return processComments;
}
function parseProcessComment(comment) {
const processId = comment.match(/@process-id\s+(\S+)/)?.[1];
const step = comment.match(/@process-step\s+(\S+)/)?.[1];
const repo = comment.match(/@repo\s+(\S+)/)?.[1];
const description = comment.match(/@description\s+(.+?)(?:\n|@|$)/s)?.[1]?.trim();
if (!processId || !step) return null;
return {
processId,
step,
repo,
description
};
}
// Usage
if (require.main === module) {
const repoPath = process.argv[2] || process.cwd();
const comments = extractProcessComments(repoPath);
console.log(JSON.stringify(comments, null, 2));
}
module.exports = { extractProcessComments };
â Best Practicesâ
1. Keep Comments Close to Codeâ
- Document processes where they happen
- Use consistent process IDs across repos
- Link steps with
@triggersand@triggered-by
2. Automate Everythingâ
- Generate docs on merge (CI/CD)
- Validate process IDs in PR checks
- Alert when docs are outdated
3. Make It Visibleâ
- Include in PR descriptions
- Link from error messages
- Add to team dashboards
4. Keep It Simpleâ
- Don't document every function
- Focus on multi-step processes
- Document implicit actions (they're the most important)
5. Regular Maintenanceâ
- Quarterly review of all process docs
- Remove outdated processes
- Update when code changes
đ ī¸ Validation & Quality Checksâ
Pre-commit Hookâ
Add validation to ensure process comments are valid:
#!/bin/bash
# .husky/pre-commit
# Check for process comments without manifests
node scripts/validate-process-docs.js
PR Checksâ
Validate in CI/CD:
- name: Validate Process Documentation
run: |
node scripts/validate-process-docs.js
node scripts/check-process-ids.js
đ Related Documentationâ
đ Industry Examplesâ
Companies Using Similar Approachesâ
- Stripe - Extensive API documentation with code examples
- GitHub - OpenAPI specs for all APIs
- Shopify - Comprehensive process documentation
- Atlassian - ADRs for architecture decisions
Open Source Projectsâ
- Kubernetes - Extensive process documentation
- React - RFC process with detailed documentation
- Rust - Comprehensive internal process docs
đ Additional Resourcesâ
â Questions?â
Contact the platform team or documentation maintainers for guidance on process documentation.