requirements-manager 0.1.1

Plain-text requirements management tool
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# Using with MdBook

[MdBook](https://github.com/rust-lang/mdBook) is a popular tool for creating documentation from Markdown files. Requiem integrates seamlessly with MdBook, allowing requirements to live alongside documentation.

## Overview

Requiem requirements are Markdown files, making them naturally compatible with MdBook. You can:

- Include requirements in your MdBook table of contents
- Embed requirements in documentation chapters
- Mix requirements with narrative documentation
- Generate complete documentation sites with embedded requirements

## Basic Setup

### Project Structure

```
my-book/
├── book.toml          ← MdBook configuration
└── src/
    ├── SUMMARY.md     ← Table of contents
    ├── config.toml    ← Requiem configuration
    ├── chapter1.md    ← Documentation
    ├── USR-001.md     ← Requirement
    └── USR-002.md     ← Requirement
```

### Requiem Configuration

Since the `src/` directory contains both requirements and documentation, configure Requiem to allow non-requirement files:

**src/config.toml**:
```toml
_version = "1"
allow_unrecognised = true  # Important: allows chapter1.md, SUMMARY.md, etc.
```

### MdBook Configuration

**book.toml**:
```toml
[book]
title = "My Project Documentation"
authors = ["Your Name"]
language = "en"
src = "src"

[build]
build-dir = "book"
```

No special MdBook configuration needed for Requiem requirements!

## Including Requirements in Table of Contents

Requirements can be listed in `SUMMARY.md` like any other chapter:

**src/SUMMARY.md**:
```markdown
# Summary

[Introduction](./introduction.md)

# Requirements

- [User Requirements]./user-requirements.md
  - [USR-001: User Authentication]./USR-001.md
  - [USR-002: Data Export]./USR-002.md
  - [USR-003: Email Validation]./USR-003.md

- [System Requirements]./system-requirements.md
  - [SYS-001: Authentication Service]./SYS-001.md
  - [SYS-002: Export API]./SYS-002.md

# User Guide

- [Getting Started]./getting-started.md
- [Features]./features.md
```

Requirements appear as chapters in the generated book. The HRID in the first heading (e.g., `# USR-001 User Authentication`) becomes the page title automatically.

## Embedding Requirements

Use MdBook's include feature to embed requirements in documentation chapters:

**src/user-guide.md**:
```markdown
# User Guide

## Authentication

Our authentication system satisfies the following requirement:

\{{#include USR-001.md}}

To log in, navigate to...
```

When MdBook builds, `USR-001.md` content is embedded directly.

### Selective Inclusion

Include only the requirement body (skip frontmatter but keep the heading):

```markdown
\{{#include USR-001.md:6:}}
```

This skips the YAML frontmatter and includes the heading and body.

**Line counting**:
```markdown
---                    ← Line 1
_version: '1'
uuid: ...
created: ...
---                    ← Line 5
# USR-001 Title        ← Line 6 (keep this!)

Requirement text...    ← Line 7 onwards
```

Adjust the line number based on your frontmatter length. The heading with the HRID should typically be kept as it provides context.

## Formatting Requirements

### Display Frontmatter

To show frontmatter in documentation:

**src/requirements-format.md**:
```markdown
# Requirement Format

Requirements include metadata in YAML frontmatter:

\{{#include USR-001.md}}
```

MdBook renders the entire file, including frontmatter as a code block.

### Hide Frontmatter

To show only the requirement text:

**Option 1: Use line ranges**
```markdown
\{{#include USR-001.md:7:}}
```

**Option 2: Create requirement summary files**

**src/usr-001-summary.md**:
```markdown
<!-- Manually maintained summary without frontmatter -->
The system shall validate user email addresses according to RFC 5322.
```

Then include the summary file in documentation.

### Custom Formatting with Preprocessors

For advanced formatting (e.g., extracting specific fields), use MdBook preprocessors:

- [mdbook-linkcheck]https://github.com/Michael-F-Bryan/mdbook-linkcheck - Validate links
- [mdbook-toc]https://github.com/badboy/mdbook-toc - Generate table of contents
- Custom preprocessor - Extract HRID, UUID, parent links from frontmatter

## Working Example

See the complete example in the Requiem repository:

```bash
git clone https://github.com/danieleades/requirements-manager
cd requirements-manager/examples/mdbook
```

### Example Structure

```
examples/mdbook/
├── book.toml
├── src/
│   ├── SUMMARY.md
│   ├── chapter_1.md
│   ├── USR-001.md
│   └── USR-002.md
└── README.md
```

### Build the Example

1. Install MdBook:
```bash
cargo install mdbook
```

2. Build the book:
```bash
mdbook build
```

3. View output:
```bash
mdbook serve --open
```

Your browser opens showing the documentation with requirements included.

## Best Practices

### 1. Organize by Type

Group requirements in `SUMMARY.md`:

```markdown
# Summary

# User Requirements
- [USR-001]./USR-001.md
- [USR-002]./USR-002.md

# System Requirements
- [SYS-001]./SYS-001.md
- [SYS-002]./SYS-002.md
```

### 2. Use Subdirectories

For large projects, organize requirements in subdirectories:

```
src/
├── SUMMARY.md
├── requirements/
│   ├── user/
│   │   ├── USR-001.md
│   │   └── USR-002.md
│   └── system/
│       ├── SYS-001.md
│       └── SYS-002.md
└── guides/
    └── user-guide.md
```

**SUMMARY.md**:
```markdown
# Summary

# Requirements
- [User Requirements](./requirements/user/USR-001.md)
- [System Requirements](./requirements/system/SYS-001.md)
```

### 3. Link Requirements

Link between requirements using standard Markdown links:

**USR-001.md**:
```markdown
This requirement is implemented by [SYS-001](./SYS-001.md).
```

MdBook generates clickable links in the output.

### 4. Embed in Context

Embed requirements in relevant documentation sections:

**user-guide.md**:
```markdown
# User Guide

## Email Validation

\{{#include requirements/USR-003.md:7:}}

To validate emails, the system checks...
```

Keeps requirements and documentation synchronized.

### 5. Separate Config

Use separate `config.toml` for Requiem:

```
src/
├── config.toml      ← Requiem config (allow_unrecognised = true)
├── book.toml        ← Don't confuse with MdBook config
└── ...
```

Note: MdBook's config is `book.toml` in the root, not in `src/`.

## Limitations

### Frontmatter Rendering

MdBook doesn't parse YAML frontmatter specially. It renders as:

```
---
_version: '1'
uuid: 4bfeb7d5-...
created: 2025-07-22T12:19:56.950194157Z
---

Requirement text...
```

The frontmatter appears as a code block (triple-dash markers).

**Workaround**: Use line ranges to skip frontmatter (see [Formatting Requirements](#formatting-requirements)).

### No Dynamic Traceability

MdBook doesn't generate traceability matrices or parent-child diagrams automatically.

**Workaround**: Generate diagrams with external tools and include as images:

```markdown
# Traceability

![Requirement Hierarchy](./diagrams/traceability.svg)
```

### No HRID Validation

MdBook doesn't validate requirement references.

**Workaround**: Use CI to validate:

```yaml
# .github/workflows/docs.yml
- name: Validate requirements
  run: req clean
  working-directory: ./src

- name: Build documentation
  run: mdbook build
```

## Advanced Techniques

### Generating Traceability Pages

Use scripts to generate traceability documentation:

**generate-traceability.sh**:
```bash
#!/bin/bash
# Generate a markdown page showing parent-child relationships

echo "# Requirement Traceability" > traceability.md
echo "" >> traceability.md

for req in USR-*.md; do
    hrid=$(basename "$req" .md)
    echo "## $hrid" >> traceability.md
    # Extract and format parent links
    # ...
done
```

Run before MdBook build:

```bash
./generate-traceability.sh
mdbook build
```

### Custom MdBook Preprocessor

Create a preprocessor to enhance requirement rendering:

**Rust preprocessor example**:
```rust
// Extract HRID and UUID from frontmatter
// Add custom formatting
// Generate cross-reference links
```

See [MdBook documentation](https://rust-lang.github.io/mdBook/format/configuration/preprocessors.html) for details.

### GitHub Pages Deployment

Host your requirements documentation:

```yaml
# .github/workflows/deploy.yml
name: Deploy Documentation

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install MdBook
        run: cargo install mdbook
      - name: Build book
        run: mdbook build
        working-directory: ./docs
      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./docs/book
```

## Example Documentation Structure

Comprehensive documentation with requirements:

```
docs/
├── book.toml
└── src/
    ├── SUMMARY.md
    ├── config.toml             ← Requiem config
    │
    ├── introduction.md          ← Narrative docs
    ├── architecture.md
    ├── getting-started.md
    │
    ├── requirements/            ← Requirements
    │   ├── user/
    │   │   ├── USR-001.md
    │   │   └── USR-002.md
    │   ├── system/
    │   │   ├── SYS-001.md
    │   │   └── SYS-002.md
    │   └── traceability.md      ← Generated
    │
    └── user-guide/              ← User guides
        ├── authentication.md    ← Embeds USR-001, SYS-001
        └── export.md            ← Embeds USR-002, SYS-002
```

## Troubleshooting

### Requirements Not Appearing in Book

**Problem**: Requirements listed in `SUMMARY.md` don't appear.

**Diagnosis**:
1. Check file paths in `SUMMARY.md` are correct
2. Ensure files exist at specified paths
3. Run `mdbook build -v` for verbose output

**Solution**: Verify paths match file structure exactly.

### Frontmatter Renders as Code Block

**Problem**: YAML frontmatter shows as markdown code block.

**Explanation**: Expected behavior. MdBook doesn't parse YAML frontmatter.

**Solution**: Use line ranges to skip frontmatter (see [Selective Inclusion](#selective-inclusion)).

### Requiem Validation Fails

**Problem**: `req clean` reports errors about non-requirement files.

**Solution**: Set `allow_unrecognised = true` in `config.toml`:

```toml
_version = "1"
allow_unrecognised = true
```

### Includes Don't Work

**Problem**: `\{{#include USR-001.md}}` doesn't embed content.

**Diagnosis**:
1. Check file path is correct relative to including file
2. Check MdBook version (includes supported in 0.3.0+)

**Solution**: Use correct relative paths:
```markdown
\{{#include ./USR-001.md}}  # If in same directory
\{{#include ../requirements/USR-001.md}}  # If in subdirectory
```

## Summary

**Key Points**:

- Requiem requirements are compatible with MdBook out of the box
- Set `allow_unrecognised = true` in Requiem config when mixing with docs
- Include requirements in `SUMMARY.md` or embed with `\{{#include}}`
- Use line ranges to skip frontmatter if desired
- Combine requirements with narrative documentation for comprehensive docs

**Benefits**:
- Single source of truth
- Requirements stay synchronized with docs
- Easy navigation and search
- Professional-looking documentation

**Limitations**:
- Frontmatter renders as code block
- No automatic traceability diagrams
- No HRID validation (use external tools)

## Next Steps

- See [Using with Sphinx]./sphinx.md for Python documentation
- Review [Version Control Best Practices]./version-control.md for managing requirements in Git