rust-relations-explorer 0.1.1

Explore relationships in Rust codebases: build a knowledge graph and run queries (connected files, function usage, cycles, paths, hubs, module centrality, trait impls).
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
# Builder Guide: Writing Effective Project Documentation

## Overview

This guide provides a systematic approach to creating **requisites.md**, **design.md**, and **plan-tasks.md** using **bottom-up development**, **DRY principles**, and **minimalist approaches**. Based on modern AI-assisted development practices and Rust idioms.

---

## 1. Core Principles

### 1.1 Bottom-Up Development Philosophy

**Start with atomic components, build upward:**
- Begin with smallest, testable units
- Define foundational data structures first
- Compose complex behaviors from simple building blocks
- Validate each layer before adding the next

### 1.2 DRY (Don't Repeat Yourself) Application

**Eliminate redundancy across documents:**
- Reference shared concepts between documents
- Use consistent terminology throughout
- Create reusable templates and patterns
- Link related sections instead of duplicating

### 1.3 Minimalist Approach

**Essential information only:**
- Focus on actionable content
- Remove unnecessary elaboration
- Use clear, concise language
- Prioritize scannable structure

---

## 2. Document Structure Templates

### 2.1 Requisites.md Template

```markdown
# Requirements Document - [Project Name]

## 1. Project Overview
- **Name:** [Clear, descriptive name]
- **Purpose:** [One sentence goal]
- **Users:** [Primary stakeholders]

## 2. Functional Requirements
### 2.1 Core Features
- **FR-001:** [Atomic functionality]
- **FR-002:** [Next atomic functionality]

### 2.2 [Feature Group]
- **FR-XXX:** [Specific, testable requirement]

## 3. Non-Functional Requirements
### 3.1 Performance
- **NFR-001:** [Measurable performance target]

### 3.2 Usability
- **NFR-XXX:** [User experience requirement]

## 4. Technical Constraints
- **TC-001:** [Technology limitation or choice]

## 5. Success Criteria
- **SC-001:** [Measurable success metric]
```

### 2.2 Design.md Template

```markdown
# Design Document - [Project Name]

## 1. System Architecture
[High-level component diagram]

## 2. Core Data Structures
```rust
// Start with atomic types
pub struct [AtomicType] {
    // Minimal essential fields
}

// Build composite types
pub struct [CompositeType] {
    // Composed from atomic types
}
```

## 3. Component Design
### 3.1 [Component Name]
**Responsibility:** [Single responsibility]
**Key Classes:** [List main classes]
**Design Patterns:** [Applied patterns]

## 4. Algorithm Design
[Core algorithms with complexity analysis]

## 5. Performance Considerations
[Optimization strategies]
```

### 2.3 Plan-Tasks.md Template

```markdown
# Project Plan & Tasks - [Project Name]

## 1. Phase Overview
### Phase 1: Foundation (Week X-Y)
**Goal:** [Atomic deliverable]

## 2. Task Breakdown
### Phase 1: Foundation
- [ ] **T001** - [Atomic task]
  - **Priority:** [High/Medium/Low]
  - **Estimate:** [Hours]
  - **Dependencies:** [Task IDs]
  - **Deliverable:** [Testable output]

## 3. Critical Path
[Task dependency chain]

## 4. Quality Gates
[Phase completion criteria]
```

---

## 3. Bottom-Up Documentation Strategy

### 3.1 Start with Data (Requisites.md)

**Step 1: Identify Atomic Requirements**
```markdown
# Start with smallest, testable units
- Parse single Rust function
- Extract one item type (struct)
- Store in basic data structure
- Output to console

# Build upward
- Parse multiple item types
- Build relationships
- Query capabilities
- Visualization
```

**Step 2: Group Related Atomics**
```markdown
# Group by natural boundaries
## Core Analysis (atomic parsing functions)
## Query System (atomic query operations)  
## Visualization (atomic output formats)
```

**Step 3: Define Measurable Success**
```markdown
# Each requirement must be:
- Testable with clear pass/fail
- Independent of other requirements
- Implementable in isolation
- Valuable to end users
```

### 3.2 Design from Components (Design.md)

**Step 1: Define Atomic Data Structures**
```rust
// Start with smallest meaningful units
#[derive(Debug, Clone)]
pub struct Item {
    pub name: String,
    pub item_type: ItemType,
}

// Compose upward
pub struct FileNode {
    pub items: Vec<Item>,  // Composition, not inheritance
}

pub struct KnowledgeGraph {
    pub files: HashMap<PathBuf, FileNode>,  // Bottom-up assembly
}
```

**Step 2: Single Responsibility Components**
```markdown
## Parser Component
**Responsibility:** Extract items from text (ONE thing)
**Input:** String content
**Output:** Vec<Item>

## Graph Component  
**Responsibility:** Manage relationships (ONE thing)
**Input:** Vec<FileNode>
**Output:** KnowledgeGraph
```

**Step 3: Compose Behaviors**
```rust
// Build complex operations from simple ones
impl KnowledgeGraph {
    // Atomic operation
    fn add_relationship(&mut self, rel: Relationship) { }
    
    // Composed operation
    fn analyze_dependencies(&self) -> Vec<Dependency> {
        // Uses multiple atomic operations
    }
}
```

### 3.3 Plan from Deliverables (Plan-Tasks.md)

**Step 1: Atomic Tasks**
```markdown
# Each task produces ONE testable deliverable
- [ ] T001 - Parse single function (2h) → Working function parser
- [ ] T002 - Parse single struct (2h) → Working struct parser  
- [ ] T003 - Combine parsers (1h) → Multi-type parser

# NOT: "Implement parsing system" (too big, not atomic)
```

**Step 2: Dependency Chains**
```markdown
# Build dependency graph bottom-up
T001 (atomic) → T003 (composition) → T005 (integration)
T002 (atomic) → T003 (composition) → T005 (integration)

# Parallel opportunities
T001 + T002 can run in parallel
T004 (data structures) can run parallel to T001-T003
```

**Step 3: Incremental Value**
```markdown
# Each phase delivers working software
Phase 1: Basic parsing works (can demo)
Phase 2: Relationships work (can query)
Phase 3: Visualization works (can see results)
```

---

## 4. DRY Implementation Across Documents

### 4.1 Shared Terminology Dictionary

**Create once, reference everywhere:**
```markdown
# In requisites.md
**Knowledge Graph:** Directed graph representing code relationships

# In design.md  
// References the same definition
pub struct KnowledgeGraph { ... }  // See requisites.md definition

# In plan-tasks.md
T010 - Build KnowledgeGraph (see requisites.md FR-010)
```

### 4.2 Cross-Document References

**Link instead of duplicate:**
```markdown
# requisites.md
## 2.1 Core Analysis Features
- **FR-001:** Parse Rust items (see design.md Section 3.1)

# design.md  
## 3.1 Parser Component
**Requirements:** Implements FR-001 from requisites.md

# plan-tasks.md
- [ ] T008 - Implement item extraction (addresses FR-001)
```

### 4.3 Template Reuse

**Standardize patterns:**
```markdown
# Requirement pattern (reuse for all FRs)
- **[ID]:** [Action] [Object] [Constraint]
  - **Input:** [What goes in]
  - **Output:** [What comes out]  
  - **Success:** [How to verify]

# Task pattern (reuse for all tasks)
- [ ] **[ID]** - [Deliverable] 
  - **Priority:** [Level]
  - **Estimate:** [Time]
  - **Dependencies:** [Prerequisites]
  - **Deliverable:** [Testable output]
```

---

## 5. Minimalist Content Guidelines

### 5.1 Essential Information Only

**Include:**
- Actionable requirements
- Testable specifications  
- Clear dependencies
- Measurable outcomes

**Exclude:**
- Background theory
- Obvious statements
- Redundant explanations
- Implementation details in requirements

### 5.2 Scannable Structure

**Use consistent formatting:**
```markdown
# Level 1: Major sections
## Level 2: Functional groups  
### Level 3: Specific items

- **Bold:** Key terms and IDs
- `Code:` Technical references
- [Links]: Cross-references
```

### 5.3 Concise Language

**Write clearly:**
```markdown
# Good (specific, actionable)
- **FR-001:** Parse function declarations returning Function struct

# Bad (vague, wordy)  
- **FR-001:** The system should be able to analyze and understand 
  Rust source code files in order to extract information about 
  function definitions and create appropriate data structures
```

---

## 6. Quality Checklist

### 6.1 Requisites.md Quality Gates

- [ ] Each requirement is atomic and testable
- [ ] Requirements grouped by natural boundaries
- [ ] Success criteria are measurable
- [ ] No implementation details leaked
- [ ] All requirements traceable to user value

### 6.2 Design.md Quality Gates

- [ ] Data structures follow composition over inheritance
- [ ] Components have single responsibilities  
- [ ] Algorithms specified with complexity
- [ ] Performance considerations addressed
- [ ] Extension points identified

### 6.3 Plan-Tasks.md Quality Gates

- [ ] Tasks produce atomic deliverables
- [ ] Dependencies clearly mapped
- [ ] Estimates based on atomic work
- [ ] Critical path identified
- [ ] Quality gates defined per phase

---

## 7. AI-Assisted Development Integration

### 7.1 LLM-Friendly Structure

**Use consistent patterns:**
```markdown
# Pattern for requirements
**[ID]:** [System] shall [action] [object] [constraint]

# Pattern for tasks  
**[ID]** - [Deliverable] ([estimate]) → [testable output]

# Pattern for components
**[Name]:** [responsibility] | Input: [type] | Output: [type]
```

### 7.2 Context Establishment

**Provide clear context blocks:**
```markdown
## Context Block
**Project:** Rust Knowledge Graph System
**Phase:** Foundation Setup  
**Dependencies:** Cargo project initialized
**Goal:** Working parser for basic Rust constructs
```

### 7.3 Validation Prompts

**Include verification guidance:**
```markdown
## Validation Checklist
- [ ] Can parse sample Rust file
- [ ] Extracts functions and structs
- [ ] Handles visibility modifiers
- [ ] Returns structured data
- [ ] Error handling works
```

---

## 8. Common Anti-Patterns to Avoid

### 8.1 Requirements Anti-Patterns

**❌ Avoid:**
- Mixing requirements with implementation
- Vague, untestable statements
- Duplicate information across sections
- Requirements that depend on multiple systems

**✅ Instead:**
- Pure functional specifications
- Specific, measurable criteria
- Single source of truth with references
- Atomic, independent requirements

### 8.2 Design Anti-Patterns

**❌ Avoid:**
- God objects with multiple responsibilities
- Deep inheritance hierarchies
- Tight coupling between components
- Premature optimization

**✅ Instead:**
- Single responsibility principle
- Composition over inheritance
- Loose coupling with clear interfaces
- Performance considerations documented

### 8.3 Planning Anti-Patterns

**❌ Avoid:**
- Tasks that can't be completed in isolation
- Estimates without breaking down work
- Dependencies that create circular waits
- Phases without deliverable value

**✅ Instead:**
- Atomic, testable deliverables
- Bottom-up estimation from known work
- Clear dependency chains
- Incremental value delivery

---

## 9. Example Application

### 9.1 Bottom-Up Requirement Building

```markdown
# Start atomic
FR-001: Parse function signature → Function struct
FR-002: Parse struct definition → Struct struct  
FR-003: Parse enum definition → Enum struct

# Compose upward
FR-010: Parse Rust file → Vec<Item> (uses FR-001, FR-002, FR-003)
FR-020: Build file relationships → KnowledgeGraph (uses FR-010)
FR-030: Query relationships → QueryResult (uses FR-020)
```

### 9.2 DRY Design References

```markdown
# design.md references requisites.md
## Parser Component (implements FR-001, FR-002, FR-003)
pub struct RustParser {
    // Implementation details
}

# plan-tasks.md references both
T008 - Implement RustParser (FR-001-003, see design.md Section 3.1)
```

### 9.3 Minimalist Task Definition

```markdown
# Atomic and specific
- [ ] **T008** - Function signature parsing (4h)
  - **Dependencies:** T004 (data structures)
  - **Deliverable:** Parse "fn name() -> Type" → Function struct
  - **Test:** Parse sample functions, verify struct fields
```

---

## 10. Success Metrics

### 10.1 Documentation Quality

- **Completeness:** All requirements traceable to tasks
- **Clarity:** Technical reviewer can implement from docs
- **Maintainability:** Updates require minimal changes
- **Usability:** AI can generate code from specifications

### 10.2 Development Efficiency

- **Reduced Rework:** Clear requirements prevent misunderstanding
- **Faster Implementation:** Atomic tasks enable parallel work
- **Better Testing:** Specific criteria enable thorough validation
- **Easier Maintenance:** Modular design supports evolution

### 10.3 Team Collaboration

- **Shared Understanding:** Consistent terminology across team
- **Clear Ownership:** Atomic tasks have clear responsibility
- **Progress Visibility:** Deliverables show concrete progress
- **Quality Assurance:** Built-in validation at each step