|
| 1 | +# WRT Documentation Standards |
| 2 | + |
| 3 | +This document defines the documentation standards for the WebAssembly Runtime (WRT) project to ensure consistency, safety compliance, and maintainability across all modules. |
| 4 | + |
| 5 | +## Module Documentation Template |
| 6 | + |
| 7 | +All modules should follow this comprehensive documentation template: |
| 8 | + |
| 9 | +```rust |
| 10 | +// WRT - {crate-name} |
| 11 | +// Module: {Module Description} |
| 12 | +// SW-REQ-ID: {requirement-ids} |
| 13 | +// |
| 14 | +// Copyright (c) 2025 Ralf Anton Beier |
| 15 | +// Licensed under the MIT license. |
| 16 | +// SPDX-License-Identifier: MIT |
| 17 | + |
| 18 | +//! {Module Name} for {Purpose} |
| 19 | +//! |
| 20 | +//! {Brief description of what this module provides} |
| 21 | +//! |
| 22 | +//! ⚠️ **{SAFETY/SECURITY WARNINGS IF APPLICABLE}** ⚠️ |
| 23 | +//! |
| 24 | +//! {Detailed description including safety implications} |
| 25 | +//! |
| 26 | +//! # Architecture |
| 27 | +//! |
| 28 | +//! {System design, hierarchy, and component relationships} |
| 29 | +//! |
| 30 | +//! # Design Principles |
| 31 | +//! |
| 32 | +//! - **{Principle 1}**: {Description} |
| 33 | +//! - **{Principle 2}**: {Description} |
| 34 | +//! - **{Principle 3}**: {Description} |
| 35 | +//! |
| 36 | +//! # Safety Considerations |
| 37 | +//! |
| 38 | +//! {For safety-critical modules, detailed safety implications and requirements} |
| 39 | +//! |
| 40 | +//! # Usage |
| 41 | +//! |
| 42 | +//! ```rust |
| 43 | +//! {Comprehensive example showing typical usage patterns} |
| 44 | +//! ``` |
| 45 | +//! |
| 46 | +//! # Cross-References |
| 47 | +//! |
| 48 | +//! - [`related_module`]: {Relationship description} |
| 49 | +//! - [`another_module`]: {How they interact} |
| 50 | +//! |
| 51 | +//! # REQ Traceability |
| 52 | +//! |
| 53 | +//! - REQ_{ID}: {How this module satisfies the requirement} |
| 54 | +//! - REQ_{ID}: {Another requirement satisfaction} |
| 55 | +``` |
| 56 | + |
| 57 | +## Function Documentation Template |
| 58 | + |
| 59 | +All public functions should follow this documentation pattern: |
| 60 | + |
| 61 | +```rust |
| 62 | +/// {Brief description of what the function does} |
| 63 | +/// |
| 64 | +/// {Detailed description including safety implications and behavior} |
| 65 | +/// |
| 66 | +/// # Arguments |
| 67 | +/// |
| 68 | +/// * `param1` - {Description with safety notes if applicable} |
| 69 | +/// * `param2` - {Description with constraints and validation requirements} |
| 70 | +/// |
| 71 | +/// # Returns |
| 72 | +/// |
| 73 | +/// {Description of return value, including success and error conditions} |
| 74 | +/// |
| 75 | +/// # Errors |
| 76 | +/// |
| 77 | +/// - [`ErrorCategory::Category`] if {specific condition} |
| 78 | +/// - [`ErrorCategory::Another`] if {another condition} |
| 79 | +/// |
| 80 | +/// # Safety |
| 81 | +/// |
| 82 | +/// {Safety requirements and rationale - MANDATORY for safety-critical functions} |
| 83 | +/// |
| 84 | +/// {Conservative behavior explanations for safety functions} |
| 85 | +/// |
| 86 | +/// # Examples |
| 87 | +/// |
| 88 | +/// ```rust |
| 89 | +/// {Basic usage example} |
| 90 | +/// ``` |
| 91 | +/// |
| 92 | +/// ```rust |
| 93 | +/// {Advanced or safety-critical usage example if applicable} |
| 94 | +/// ``` |
| 95 | +/// |
| 96 | +/// # REQ Traceability |
| 97 | +/// |
| 98 | +/// - REQ_{ID}: {How this function satisfies specific requirements} |
| 99 | +fn example_function(param1: Type1, param2: Type2) -> Result<ReturnType> { |
| 100 | + // Implementation |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +## Documentation Categories |
| 105 | + |
| 106 | +### Safety-Critical Modules |
| 107 | + |
| 108 | +Modules dealing with safety (safety_system, memory_system, resource management) **MUST** include: |
| 109 | + |
| 110 | +1. **Safety Warnings**: Prominent warnings about preliminary status, validation requirements |
| 111 | +2. **Safety Considerations**: Detailed section on safety implications |
| 112 | +3. **Conservative Behavior**: Explanation of conservative design decisions |
| 113 | +4. **REQ Traceability**: Complete traceability to safety requirements |
| 114 | +5. **Cross-References**: Links to related safety modules |
| 115 | + |
| 116 | +### Performance-Critical Modules |
| 117 | + |
| 118 | +Modules affecting performance **SHOULD** include: |
| 119 | + |
| 120 | +1. **Performance Characteristics**: Time/space complexity documentation |
| 121 | +2. **Memory Usage**: Memory allocation patterns and bounds |
| 122 | +3. **Benchmarks**: Performance expectations and constraints |
| 123 | + |
| 124 | +### Integration Modules |
| 125 | + |
| 126 | +Modules providing integration between components **MUST** include: |
| 127 | + |
| 128 | +1. **Architecture Diagrams**: Clear component relationships |
| 129 | +2. **Integration Examples**: End-to-end usage scenarios |
| 130 | +3. **Cross-References**: Comprehensive linking to integrated modules |
| 131 | + |
| 132 | +## Documentation Quality Requirements |
| 133 | + |
| 134 | +### Mandatory Elements |
| 135 | + |
| 136 | +- [x] Module header with WRT identification |
| 137 | +- [x] Copyright and license information |
| 138 | +- [x] SW-REQ-ID traceability (where applicable) |
| 139 | +- [x] Brief module description |
| 140 | +- [x] Usage examples |
| 141 | +- [x] Error documentation for all fallible functions |
| 142 | +- [x] Cross-references to related modules |
| 143 | + |
| 144 | +### Safety-Critical Additional Requirements |
| 145 | + |
| 146 | +- [x] Safety warnings and considerations |
| 147 | +- [x] Conservative behavior explanations |
| 148 | +- [x] Safety requirement traceability |
| 149 | +- [x] Validation guidance references |
| 150 | + |
| 151 | +### Quality Standards |
| 152 | + |
| 153 | +1. **Clarity**: Documentation must be understandable by safety engineers |
| 154 | +2. **Completeness**: All public APIs documented with examples |
| 155 | +3. **Accuracy**: Documentation must match implementation behavior |
| 156 | +4. **Consistency**: Follow standard templates and formatting |
| 157 | +5. **Traceability**: Clear links to requirements and related modules |
| 158 | + |
| 159 | +## Cross-Reference Guidelines |
| 160 | + |
| 161 | +### Module Cross-References |
| 162 | + |
| 163 | +Use this format for linking related modules: |
| 164 | + |
| 165 | +```rust |
| 166 | +//! # Cross-References |
| 167 | +//! |
| 168 | +//! - [`crate::module_name`]: {Relationship description} |
| 169 | +//! - [`other_crate::module`]: {Integration details} |
| 170 | +``` |
| 171 | + |
| 172 | +### Function Cross-References |
| 173 | + |
| 174 | +Link to related functions and types: |
| 175 | + |
| 176 | +```rust |
| 177 | +/// See also [`related_function`] for {related functionality}. |
| 178 | +/// |
| 179 | +/// This function works with [`StructName`] to provide {combined functionality}. |
| 180 | +``` |
| 181 | + |
| 182 | +## REQ Traceability Standards |
| 183 | + |
| 184 | +### Format |
| 185 | + |
| 186 | +```rust |
| 187 | +//! # REQ Traceability |
| 188 | +//! |
| 189 | +//! - REQ_CATEGORY_ID_001: {Requirement description and how satisfied} |
| 190 | +//! - REQ_CATEGORY_ID_002: {Another requirement} |
| 191 | +``` |
| 192 | + |
| 193 | +### Categories |
| 194 | + |
| 195 | +- `REQ_SAFETY_*`: Safety-related requirements |
| 196 | +- `REQ_MEM_*`: Memory management requirements |
| 197 | +- `REQ_RESOURCE_*`: Resource management requirements |
| 198 | +- `REQ_HOST_*`: Host integration requirements |
| 199 | +- `REQ_COMPONENT_*`: Component model requirements |
| 200 | +- `REQ_PLATFORM_*`: Platform-specific requirements |
| 201 | + |
| 202 | +## Example Implementations |
| 203 | + |
| 204 | +### Excellent Example: `safety_system.rs` |
| 205 | + |
| 206 | +The safety system module demonstrates all documentation best practices: |
| 207 | +- Comprehensive module documentation with warnings |
| 208 | +- Detailed safety considerations and conservative behavior explanation |
| 209 | +- Rich cross-references and requirement traceability |
| 210 | +- Multiple usage examples with safety implications |
| 211 | + |
| 212 | +### Good Example: `memory_system.rs` |
| 213 | + |
| 214 | +The memory system module shows strong documentation with: |
| 215 | +- Clear architecture documentation |
| 216 | +- Safety considerations for memory allocation |
| 217 | +- Cross-references to safety and bounded collection modules |
| 218 | +- Complete requirement traceability |
| 219 | + |
| 220 | +## Automated Checks |
| 221 | + |
| 222 | +### Documentation Completeness |
| 223 | + |
| 224 | +```bash |
| 225 | +# Check for missing module documentation |
| 226 | +cargo doc --no-deps --document-private-items |
| 227 | + |
| 228 | +# Validate documentation examples compile |
| 229 | +cargo test --doc |
| 230 | + |
| 231 | +# Check for missing cross-references |
| 232 | +scripts/check-cross-references.sh |
| 233 | +``` |
| 234 | + |
| 235 | +### REQ Traceability Validation |
| 236 | + |
| 237 | +```bash |
| 238 | +# Validate requirement traceability matrix |
| 239 | +scripts/validate-req-traceability.sh |
| 240 | + |
| 241 | +# Generate traceability report |
| 242 | +scripts/generate-traceability-report.sh |
| 243 | +``` |
| 244 | + |
| 245 | +## Review Checklist |
| 246 | + |
| 247 | +### Module Documentation Review |
| 248 | + |
| 249 | +- [ ] Header follows standard format with correct crate name |
| 250 | +- [ ] SW-REQ-ID traceability included (if applicable) |
| 251 | +- [ ] Architecture section describes module design |
| 252 | +- [ ] Design principles clearly stated |
| 253 | +- [ ] Safety considerations documented (for safety-critical modules) |
| 254 | +- [ ] Usage examples provided and tested |
| 255 | +- [ ] Cross-references to related modules included |
| 256 | +- [ ] REQ traceability complete and accurate |
| 257 | + |
| 258 | +### Function Documentation Review |
| 259 | + |
| 260 | +- [ ] Brief description clear and accurate |
| 261 | +- [ ] All parameters documented with constraints |
| 262 | +- [ ] Return value and error conditions documented |
| 263 | +- [ ] Safety section included (for safety-critical functions) |
| 264 | +- [ ] Examples provided for complex functions |
| 265 | +- [ ] REQ traceability for requirement-satisfying functions |
| 266 | + |
| 267 | +### Safety Documentation Review |
| 268 | + |
| 269 | +- [ ] Safety warnings prominently displayed |
| 270 | +- [ ] Conservative behavior rationale explained |
| 271 | +- [ ] Safety requirements clearly linked |
| 272 | +- [ ] Validation guidance referenced |
| 273 | +- [ ] Cross-references to safety standards included |
| 274 | + |
| 275 | +## Documentation Tools |
| 276 | + |
| 277 | +### VS Code Snippets |
| 278 | + |
| 279 | +Create documentation snippets for consistent formatting: |
| 280 | + |
| 281 | +- `wrt-module-doc`: Module documentation template |
| 282 | +- `wrt-function-doc`: Function documentation template |
| 283 | +- `wrt-safety-doc`: Safety-critical function documentation |
| 284 | + |
| 285 | +### Documentation Generation |
| 286 | + |
| 287 | +```bash |
| 288 | +# Generate complete documentation |
| 289 | +just docs |
| 290 | + |
| 291 | +# Generate documentation with safety analysis |
| 292 | +just docs-safety |
| 293 | + |
| 294 | +# Validate documentation consistency |
| 295 | +just check-docs-consistency |
| 296 | +``` |
| 297 | + |
| 298 | +This documentation standard ensures that WRT maintains world-class documentation quality appropriate for safety-critical software development while providing clear guidance for developers and safety engineers. |
0 commit comments