This guide explains how to write and maintain documentation for the docs-coderef project.
All documentation lives in the docs/ directory and follows a three-tier structure:
docs/
├── README.md # Documentation index and navigation
├── user-guide/ # End-user documentation
├── development/ # Contributor guides
└── architecture/ # Technical deep-dives
Use ATX-style headers (#) with a space after the hash:
# H1 - Document Title
## H2 - Major Section
### H3 - Subsection- Each document should have exactly one H1 at the top
- Use H2 for major sections, H3 for subsections
- Avoid skipping header levels (don't jump from H2 to H4)
Always specify the language for syntax highlighting:
```bash
npm run build
```
```typescript
function example(): void {
console.log('Hello');
}
```For command-line examples, use:
bashfor shell commandstypescriptfor TypeScript codejavascriptfor JavaScript codejsonfor JSON configurationmarkdownfor markdown examples
Important: When including code examples from the actual source code, always use CODE_REF comments to reference the source. This ensures the documentation stays synchronized with the codebase. See Using CODE_REF in Documentation for details.
Use consistent formatting:
- Unordered lists use hyphens (-)
- Not asterisks (\*) or plus (+)
- Keep items concise
1. Ordered lists use numbers
2. Start from 1 and increment
3. Use for sequential stepsUse relative paths from the current file:
[Coding Standards](coding-standards.md)
[Architecture Overview](../architecture/overview.md)
[Main README](../../README.md)Provide descriptive link text:
Good: [Conventional Commits specification](https://www.conventionalcommits.org/)
Bad: Click [here](https://www.conventionalcommits.org/)- Bold for UI elements, file names, important terms:
**package.json** - Italic for emphasis or introducing new terms:
*CODE_REF comments* Codefor inline code, commands, values:`npm install`
Since this project validates CODE_REF comments in markdown, follow these practices:
When showing code examples that reference actual source code, use CODE_REF comments:
```typescript
// CODE_REF: src/utils/parser.ts#parseCodeRef
export function parseCodeRef(comment: string): CodeRef {
// Implementation
}
```When documenting CODE_REF syntax itself, use markdown code blocks:
The basic syntax is:
```
// CODE_REF: <file-path>#<symbol-name>
```- Always use CODE_REF when including code examples from the actual source code
- This applies to any code snippets copied from
src/,bin/, or other source directories - CODE_REF ensures documentation stays in sync with the codebase
- Without CODE_REF, code examples can become outdated and misleading
- This applies to any code snippets copied from
- Use CODE_REF when showing actual implementation code
- Keep referenced code snippets short and focused
- Update documentation when refactoring referenced code
- For hypothetical or generic examples that don't reference actual source code, CODE_REF is not required
Documentation should be updated whenever user-facing code changes. The project includes an automatic validation script to help ensure documentation stays in sync with code.
The following changes typically require documentation updates:
- CLI changes (
src/cli/) → Updatedocs/user-guide/cli-usage.md - Public API changes (
src/index.ts) → Updatedocs/user-guide/anddocs/architecture/overview.md - Binary changes (
bin/) → Updatedocs/user-guide/installation.md - Core functionality (
src/core/) → Updatedocs/architecture/as needed
Before committing changes, validate your documentation updates:
npm run docs:validateThis script will:
- Detect whether your branch was created from
mainordevelop - Compare your changes against the base branch
- Check if documentation was updated when required
- Provide suggestions for which docs to update
- Make code changes in your feature branch
- Update relevant documentation in
docs/ - Validate documentation with
npm run docs:validate - Test CODE_REF references with
npm run build(runs coderef validation) - Commit both code and docs together
- Don't use
<br>tags (use blank lines) - Don't mix list markers (stick to
-for unordered lists) - Don't forget language specifiers in code blocks
- Don't use relative links that go outside the repository
- Don't commit documentation without testing examples
- Don't use inline HTML when markdown suffices
- Don't forget to update
docs/README.mdwhen adding new documents - Don't commit user-facing code changes without updating documentation
- Don't include code examples from the actual source code without CODE_REF comments