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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# Directory Structure

Requiem is flexible about how you organize requirements on disk. This chapter explains directory organization options and best practices.

## Directory Structure Modes

Requiem supports two fundamental modes for organizing requirements, controlled by the `subfolders_are_namespaces` configuration option:

### 1. Filename-Based Mode (Default)

**Configuration**: `subfolders_are_namespaces = false` (or omitted)

In this mode, the full HRID is encoded in the filename, and directory structure is purely organizational:

```
my-requirements/
├── USR-001.md              → HRID: USR-001
├── SYS-002.md              → HRID: SYS-002
├── auth-USR-003.md         → HRID: auth-USR-003
└── custom/folder/
    └── system-REQ-004.md   → HRID: system-REQ-004
```

**Use when**: You want maximum flexibility in folder organization without affecting requirement namespaces.

### 2. Path-Based Mode

**Configuration**: `subfolders_are_namespaces = true`

In this mode, subfolders encode the namespace, and the filename contains only KIND-ID:

```
my-requirements/
├── REQ-001.md              → HRID: REQ-001 (no namespace)
├── system/
│   └── auth/
│       ├── REQ-002.md      → HRID: system-auth-REQ-002
│       └── USR/
│           └── 003.md      → HRID: system-auth-USR-003 (KIND from parent)
```

The filename format is automatically inferred:
- **Numeric only** (e.g., `003.md`) → KIND taken from parent folder
- **KIND-ID** (e.g., `REQ-002.md`) → KIND and ID from filename

**Use when**: You want folder structure to directly mirror requirement namespaces.

## Basic Structure

At minimum, you need a directory containing requirement markdown files:

```
my-requirements/
├── USR-001.md
├── USR-002.md
├── SYS-001.md
└── SYS-002.md
```

That's it! No initialization or hidden directories required.

## With Configuration

Add a `config.toml` for project-specific settings:

```
my-requirements/
├── config.toml      ← Configuration
├── USR-001.md
├── USR-002.md
├── SYS-001.md
└── SYS-002.md
```

The configuration file is optional but recommended for projects with specific needs.

## Using Subdirectories

Requiem recursively searches subdirectories, enabling hierarchical organization.

### Organize by Requirement Kind

```
requirements/
├── config.toml
├── user/
│   ├── USR-001.md
│   ├── USR-002.md
│   └── USR-003.md
├── system/
│   ├── SYS-001.md
│   ├── SYS-002.md
│   └── SYS-003.md
└── test/
    ├── TST-001.md
    └── TST-002.md
```

**Advantages**:
- Clear separation of requirement levels
- Easy to navigate
- Natural for large projects

**Note**: In filename-based mode (default), directory names don't affect requirement behavior. `user/USR-001.md` and `system/USR-001.md` would create a filename conflict (both have HRID `USR-001`), so use different kinds. In path-based mode, these would have different HRIDs: `user-USR-001` and `system-USR-001`.

### Organize by Feature

```
requirements/
├── config.toml
├── authentication/
│   ├── USR-001.md   # User login
│   ├── SYS-001.md   # Auth service
│   └── TST-001.md   # Auth tests
├── payment/
│   ├── USR-002.md   # Payment processing
│   ├── SYS-002.md   # Payment gateway
│   └── TST-002.md   # Payment tests
└── reporting/
    ├── USR-003.md   # Report generation
    └── SYS-003.md   # Report engine
```

**Advantages**:
- Groups related requirements
- Mirrors feature structure
- Good for feature-based development

### Organize by Component

```
requirements/
├── config.toml
├── frontend/
│   ├── WEB-USR-001.md
│   ├── WEB-SYS-001.md
│   ├── MOBILE-USR-001.md
│   └── MOBILE-SYS-001.md
└── backend/
    ├── API-SYS-001.md
    ├── DB-SYS-001.md
    └── CACHE-SYS-001.md
```

**Advantages**:
- Aligns with system architecture
- Clear ownership boundaries
- Natural for microservices

**Note**: Consider using namespaces in HRIDs (e.g., `WEB-USR-001`) to avoid conflicts.

### Deep Hierarchies

Requiem supports arbitrary nesting:

```
requirements/
├── config.toml
└── product/
    ├── core/
    │   ├── auth/
    │   │   ├── USR-001.md
    │   │   └── SYS-001.md
    │   └── data/
    │       ├── USR-002.md
    │       └── SYS-002.md
    └── plugins/
        ├── export/
        │   └── USR-003.md
        └── import/
            └── USR-004.md
```

**Caution**: Deep hierarchies can be harder to navigate. Consider flat or shallow structures unless your project naturally requires depth.

## Flat vs. Hierarchical

### Flat Structure

```
requirements/
├── config.toml
├── USR-001.md
├── USR-002.md
├── ...
├── USR-050.md
├── SYS-001.md
├── SYS-002.md
├── ...
└── SYS-100.md
```

**Advantages**:
- Simple and straightforward
- Easy to understand
- Works well for small/medium projects (< 100 requirements)

**Disadvantages**:
- Directory listing can become unwieldy with many requirements
- Harder to navigate in file browser with 100+ files

**Best for**: Small to medium projects, single-component systems.

### Hierarchical Structure

```
requirements/
├── config.toml
├── user-requirements/
│   └── (50 files)
├── system-requirements/
│   └── (100 files)
└── test-requirements/
    └── (150 files)
```

**Advantages**:
- Scalable to large projects (1000+ requirements)
- Natural organization
- Easier to navigate

**Disadvantages**:
- Slightly more complex
- Must decide on hierarchy scheme

**Best for**: Large projects, multi-component systems.

## Best Practices

### 1. Start Flat, Refactor When Needed

Begin with a flat structure:

```
requirements/
├── config.toml
├── USR-001.md
└── SYS-001.md
```

Introduce subdirectories when you have 50+ requirements or natural groupings emerge.

### 2. Use Consistent Naming

If using subdirectories, name them consistently:

```
requirements/
├── 1-user-requirements/
├── 2-system-requirements/
├── 3-software-requirements/
└── 4-test-requirements/
```

Or:

```
requirements/
├── user/
├── system/
├── software/
└── test/
```

**Avoid**: Mixing naming schemes (`user_reqs/`, `system-requirements/`, `Tests/`).

### 3. Keep Shallow (2-3 Levels Max)

Prefer:
```
requirements/
└── user/
    └── USR-001.md
```

Over:
```
requirements/
└── level1/
    └── level2/
        └── level3/
            └── level4/
                └── USR-001.md
```

Deep hierarchies are hard to navigate and remember.

### 4. Align with Team Structure

Organize to match how your team works:

**Team by feature**:
```
requirements/
├── login-team/
├── payment-team/
└── reporting-team/
```

**Team by layer**:
```
requirements/
├── product-managers/  (USR requirements)
├── architects/        (SYS requirements)
└── developers/        (SWR requirements)
```

### 5. Don't Encode Information in Paths

**Bad**:
```
requirements/
└── high-priority/
    └── USR-001.md  # Priority encoded in directory
```

**Good**:
```
requirements/
└── USR-001.md

# USR-001.md content:
---
tags:
- high-priority
---
The requirement text...
```

Use tags or content for metadata, not directory structure. Directories are for organization only.

## Special Cases

### Mixed Content (Requirements + Documentation)

If requirements live alongside other documentation:

```
docs/
├── config.toml
├── introduction.md      ← Not a requirement
├── architecture.md      ← Not a requirement
├── requirements/
│   ├── USR-001.md      ← Requirement
│   └── SYS-001.md      ← Requirement
└── user-guide.md        ← Not a requirement
```

Set `allow_unrecognised = true` in `config.toml` to allow non-requirement markdown files.

### Integration with MdBook

MdBook projects:

```
docs/
├── book.toml           ← MdBook config
├── src/
│   ├── SUMMARY.md      ← MdBook table of contents
│   ├── chapter1.md     ← Documentation
│   ├── USR-001.md      ← Requirement (can be in SUMMARY.md)
│   └── USR-002.md      ← Requirement
└── config.toml         ← Requiem config (allow_unrecognised = true)
```

See [Integration > Using with MdBook](../integration/mdbook.md) for details.

### Integration with Sphinx

Sphinx projects:

```
docs/
├── conf.py             ← Sphinx config
├── index.md
├── requirements/
│   ├── config.toml     ← Requiem config
│   ├── USR-001.md      ← Requirement
│   └── SYS-001.md      ← Requirement
└── other-content.md
```

See [Integration > Using with Sphinx](../integration/sphinx.md) for details.

### Monorepo Structure

Large monorepos with multiple products:

```
monorepo/
├── products/
│   ├── web-app/
│   │   └── requirements/
│   │       ├── config.toml
│   │       └── WEB-USR-001.md
│   └── mobile-app/
│       └── requirements/
│           ├── config.toml
│           └── MOBILE-USR-001.md
└── shared/
    └── requirements/
        ├── config.toml
        └── CORE-SYS-001.md
```

Each product/component has its own independent requirements directory with separate `config.toml`.

## File System Considerations

### Case Sensitivity

**Linux/Mac**: Filenames are case-sensitive
- `USR-001.md` and `usr-001.md` are different files
- Requiem only recognizes `USR-001.md` (uppercase HRID)

**Windows**: Filenames are case-insensitive
- `USR-001.md` and `usr-001.md` refer to the same file
- Use consistent casing to avoid issues

**Recommendation**: Always use uppercase HRIDs to avoid cross-platform issues.

### Symbolic Links

Requiem follows symbolic links when scanning for requirements:

```
requirements/
├── current -> v2.0/     ← Symlink
├── v1.0/
│   └── USR-001.md
└── v2.0/
    └── USR-001.md
```

**Caution**: Ensure symlinks don't create cycles or duplicate requirements.

### Hidden Files and Directories

Files and directories starting with `.` are typically ignored by Requiem (following standard Unix convention):

```
requirements/
├── .git/               ← Ignored
├── .DS_Store           ← Ignored (Mac)
├── config.toml
└── USR-001.md
```

## Performance Considerations

### Large Directories

Requiem uses parallel loading for performance:

```
requirements/
├── USR-001.md
├── USR-002.md
├── ...
└── USR-5000.md  # 5000 files loads quickly due to parallelism
```

**Performance**: Requiem can handle thousands of requirements efficiently. Directory structure has minimal performance impact.

### Network File Systems

If requirements are on a network drive:
- Initial loading may be slower
- Consider using subdirectories to localize access patterns
- Parallel loading helps mitigate network latency

## Choosing Between Modes

### When to Use Filename-Based Mode (Default)

**Advantages**:
- Maximum flexibility - organize folders however you want
- Easy to move files between folders without changing HRIDs
- Works well with arbitrary organizational schemes (by feature, by team, etc.)
- Explicit namespaces visible in every filename

**Best for**:
- Projects where folder structure is organizational, not semantic
- Teams that reorganize folders frequently
- Mixed organizational schemes
- When you want full control over namespaces

**Example**:
```
requirements/
├── team-a/
│   └── auth-USR-001.md      → HRID: auth-USR-001
└── team-b/
    └── auth-SYS-002.md      → HRID: auth-SYS-002
```

### When to Use Path-Based Mode

**Advantages**:
- Cleaner filenames (shorter, less redundant)
- Folder structure enforces namespace consistency
- Natural for hierarchical component structures
- Automatic namespace creation from folders

**Best for**:
- Projects with stable, hierarchical component structures
- When folder structure mirrors system architecture
- Microservices or multi-component systems
- When you want enforced namespace-folder alignment

**Example**:
```
requirements/
├── auth/
│   ├── USR-001.md           → HRID: auth-USR-001
│   └── SYS-002.md           → HRID: auth-SYS-002
└── payment/
    ├── USR-001.md           → HRID: payment-USR-001
    └── SYS-002.md           → HRID: payment-SYS-002
```

### Comparison Table

| Aspect | Filename-Based | Path-Based |
|--------|----------------|------------|
| **Filename contains** | Full HRID | KIND-ID only |
| **Namespace from** | Filename | Folder path |
| **Folder flexibility** | High | Low (tied to namespace) |
| **File move impact** | None | Changes HRID |
| **Filename length** | Longer | Shorter |
| **Default mode** | Yes | No |

## Migration Between Modes

### Converting from Filename-Based to Path-Based

1. **Update configuration**:
```toml
# config.toml
_version = "1"
subfolders_are_namespaces = true
```

2. **Reorganize files** to match namespace structure:

```bash
# Before (filename-based):
# requirements/
# ├── auth-USR-001.md
# └── payment-USR-002.md

# Create namespace folders
mkdir -p auth payment

# Move and rename files
mv auth-USR-001.md auth/USR-001.md
mv payment-USR-002.md payment/USR-002.md

# After (path-based):
# requirements/
# ├── auth/
# │   └── USR-001.md
# └── payment/
#     └── USR-002.md
```

3. **Verify**:
```bash
req clean
```

### Converting from Path-Based to Filename-Based

1. **Flatten files** and encode namespace in filename:

```bash
# Before (path-based):
# requirements/
# ├── auth/
# │   └── USR-001.md        (HRID: auth-USR-001)
# └── payment/
#     └── USR-002.md        (HRID: payment-USR-002)

# Move and rename with full HRID
mv auth/USR-001.md auth-USR-001.md
mv payment/USR-002.md payment-USR-002.md

# Remove now-empty folders
rmdir auth payment

# After (filename-based):
# requirements/
# ├── auth-USR-001.md
# └── payment-USR-002.md
```

2. **Update configuration**:
```toml
# config.toml
_version = "1"
subfolders_are_namespaces = false
```

3. **Verify**:
```bash
req clean
```

**Note**: When converting between modes, the HRID (and thus UUID) remains the same, preserving all links and history.

## Migration and Refactoring

### Reorganizing Files

To reorganize directory structure in filename-based mode:

1. Move requirement files:
```bash
mkdir system
mv SYS-*.md system/
```

2. Verify:
```bash
req clean
```

3. Commit:
```bash
git add -A
git commit -m "Organize system requirements into subdirectory"
```

**Safe because**: Requirements are identified by HRID (filename), not path. Moving files doesn't break links.

### Splitting Directories

To split a large flat directory:

```bash
# Before
requirements/
├── USR-001.md (100 files)

# After
requirements/
├── user/
│   └── USR-001.md (100 files)
└── system/
    └── SYS-001.md (100 files)
```

Steps:
```bash
mkdir user system test
mv USR-*.md user/
mv SYS-*.md system/
mv TST-*.md test/
req clean  # Verify
```

## Summary

**Key Takeaways**:

1. **Flexible**: Flat or hierarchical, your choice
2. **Recursive**: Subdirectories are automatically scanned
3. **Simple**: Directory names don't affect requirement behavior
4. **Scalable**: Supports small projects (10s) to large (1000s)
5. **Reorganizable**: Safe to move files (links use UUIDs, not paths)

**Recommendations**:
- Start flat, add structure as needed
- Keep shallow (2-3 levels max)
- Organize by kind, feature, or component
- Use consistent naming conventions
- Align with team structure

## Next Steps

- Understand [Namespaces]./namespaces.md for large multi-component projects
- Learn about [Version Control Best Practices]../integration/version-control.md