workspace_tools 0.12.0

Reliable workspace-relative path resolution for Rust projects. Automatically finds your workspace root and provides consistent file path handling regardless of execution context. Features memory-safe secret management, configuration loading with validation, and resource discovery.
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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
# Task 015: Documentation Ecosystem

**Priority**: 📚 High Impact  
**Phase**: 3-4 (Content & Community)  
**Estimated Effort**: 5-6 weeks  
**Dependencies**: Core features stable, Task 010 (CLI Tool)  

## **Objective**
Create a comprehensive documentation ecosystem that transforms workspace_tools from a useful library into a widely adopted standard by providing exceptional learning resources, best practices, and community-driven content that makes workspace management accessible to all Rust developers.

## **Strategic Documentation Goals**

### **Educational Impact**
- **Rust Book Integration**: Get workspace_tools patterns included as recommended practices
- **Learning Path**: From beginner to expert workspace management
- **Best Practices**: Establish industry standards for Rust workspace organization
- **Community Authority**: Become the definitive resource for workspace management

### **Adoption Acceleration**
- **Zero Barrier to Entry**: Anyone can understand and implement in 5 minutes
- **Progressive Disclosure**: Simple start, advanced features available when needed
- **Framework Integration**: Clear guides for every popular Rust framework
- **Enterprise Ready**: Documentation that satisfies corporate evaluation criteria

## **Technical Requirements**

### **Documentation Infrastructure**
1. **Multi-Platform Publishing**
   - docs.rs integration with custom styling
   - Standalone documentation website with search
   - PDF/ePub generation for offline reading
   - Mobile-optimized responsive design

2. **Interactive Learning**
   - Executable code examples in documentation
   - Interactive playground for testing concepts
   - Step-by-step tutorials with validation
   - Video content integration

3. **Community Contributions**
   - Easy contribution workflow for community examples
   - Translation support for non-English speakers
   - Versioned documentation with migration guides
   - Community-driven cookbook and patterns

## **Implementation Steps**

### **Phase 1: Foundation Documentation** (Weeks 1-2)

#### **Week 1: Core Documentation Structure**
```markdown
# Documentation Site Architecture

docs/
├── README.md                    # Main landing page
├── SUMMARY.md                   # mdBook table of contents
├── book/                        # Main documentation book
│   ├── introduction.md
│   ├── quickstart/
│   │   ├── installation.md
│   │   ├── first-workspace.md
│   │   └── basic-usage.md
│   ├── concepts/
│   │   ├── workspace-structure.md
│   │   ├── path-resolution.md
│   │   └── standard-directories.md
│   ├── guides/
│   │   ├── cli-applications.md
│   │   ├── web-services.md
│   │   ├── desktop-apps.md
│   │   └── libraries.md
│   ├── features/
│   │   ├── configuration.md
│   │   ├── templates.md
│   │   ├── secrets.md
│   │   └── async-operations.md
│   ├── integrations/
│   │   ├── frameworks/
│   │   │   ├── axum.md
│   │   │   ├── bevy.md
│   │   │   ├── tauri.md
│   │   │   └── leptos.md
│   │   ├── tools/
│   │   │   ├── docker.md
│   │   │   ├── ci-cd.md
│   │   │   └── ide-setup.md
│   │   └── deployment/
│   │       ├── cloud-platforms.md
│   │       └── containers.md
│   ├── cookbook/
│   │   ├── common-patterns.md
│   │   ├── testing-strategies.md
│   │   └── troubleshooting.md
│   ├── api/
│   │   ├── workspace.md
│   │   ├── configuration.md
│   │   └── utilities.md
│   └── contributing/
│       ├── development.md
│       ├── documentation.md
│       └── community.md
├── examples/                    # Comprehensive example projects
│   ├── hello-world/
│   ├── web-api-complete/
│   ├── desktop-app/
│   ├── cli-tool-advanced/
│   └── monorepo-enterprise/
└── assets/                      # Images, diagrams, videos
    ├── images/
    ├── diagrams/
    └── videos/
```

#### **Core Documentation Content**
```markdown
<!-- book/introduction.md -->
# Introduction to workspace_tools

Welcome to **workspace_tools** — the definitive solution for workspace-relative path resolution in Rust. 

## What is workspace_tools?

workspace_tools solves a fundamental problem that every Rust developer encounters: **reliable path resolution that works regardless of where your code runs**.

### The Problem

```rust
// ❌ These approaches are fragile and break easily:

// Relative paths break when execution context changes
let config = std::fs::read_to_string("../config/app.toml")?;

// Hardcoded paths aren't portable
let data = std::fs::read_to_string("/home/user/project/data/cache.db")?;

// Environment-dependent solutions require manual setup
let base = std::env::var("PROJECT_ROOT")?;
let config = std::fs::read_to_string(format!("{}/config/app.toml", base))?;
```

### The Solution

```rust
// ✅ workspace_tools provides reliable, context-independent paths:

use workspace_tools::workspace;

let ws = workspace()?;
let config = std::fs::read_to_string(ws.join("config/app.toml"))?;
let data = std::fs::read_to_string(ws.data_dir().join("cache.db"))?;

// Works perfectly whether called from:
// - Project root: cargo run
// - Subdirectory: cd src && cargo run  
// - IDE debug session
// - CI/CD pipeline
// - Container deployment
```

## Why workspace_tools?

### 🎯 **Zero Configuration** 
Works immediately with Cargo workspaces. No setup files needed.

### 🏗️ **Standard Layout**
Promotes consistent, predictable project structures across the Rust ecosystem.

### 🔒 **Security First**
Built-in secrets management with environment fallbacks.

### ⚡ **High Performance**
Optimized for minimal overhead, scales to large monorepos.

### 🧪 **Testing Ready**
Isolated workspace utilities make testing straightforward.

### 🌍 **Cross-Platform**
Handles Windows/macOS/Linux path differences automatically.

### 📦 **Framework Agnostic**
Works seamlessly with any Rust framework or architecture.

## Who Should Use This?

- **Application Developers**: CLI tools, web services, desktop apps
- **Library Authors**: Need reliable resource loading
- **DevOps Engineers**: Container and CI/CD deployments  
- **Team Leads**: Standardizing project structure across teams
- **Students & Educators**: Learning Rust best practices

## Quick Preview

Here's what a typical workspace_tools project looks like:

```
my-project/
├── Cargo.toml
├── src/
│   └── main.rs
├── config/                 # ← ws.config_dir()
│   ├── app.toml
│   └── database.yaml
├── data/                   # ← ws.data_dir()
│   └── cache.db
├── logs/                   # ← ws.logs_dir()
└── tests/                  # ← ws.tests_dir()
    └── integration_tests.rs
```

```rust
// src/main.rs
use workspace_tools::workspace;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ws = workspace()?;
    
    // Load configuration
    let config_content = std::fs::read_to_string(
        ws.config_dir().join("app.toml")
    )?;
    
    // Initialize logging
    let log_path = ws.logs_dir().join("app.log");
    
    // Access data directory
    let cache_path = ws.data_dir().join("cache.db");
    
    println!("✅ Workspace initialized at: {}", ws.root().display());
    Ok(())
}
```

## What's Next?

Ready to get started? The [Quick Start Guide](./quickstart/installation.md) will have you up and running in 5 minutes.

Want to understand the concepts first? Check out [Core Concepts](./concepts/workspace-structure.md).

Looking for specific use cases? Browse our [Integration Guides](./integrations/frameworks/).

---

*💡 **Pro Tip**: workspace_tools follows the principle of "Convention over Configuration" — it works great with zero setup, but provides extensive customization when you need it.*
```

#### **Week 2: Interactive Examples System**
```rust
// docs/interactive_examples.rs - System for runnable documentation examples

use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::process::Command;
use tempfile::TempDir;

pub struct InteractiveExample {
    pub id: String,
    pub title: String,
    pub description: String,
    pub setup_files: Vec<(PathBuf, String)>,
    pub main_code: String,
    pub expected_output: String,
    pub cleanup: bool,
}

impl InteractiveExample {
    pub fn new(id: impl Into<String>, title: impl Into<String>) -> Self {
        Self {
            id: id.into(),
            title: title.into(),
            description: String::new(),
            setup_files: Vec::new(),
            main_code: String::new(),
            expected_output: String::new(),
            cleanup: true,
        }
    }
    
    pub fn with_description(mut self, desc: impl Into<String>) -> Self {
        self.description = desc.into();
        self
    }
    
    pub fn with_file(mut self, path: impl Into<PathBuf>, content: impl Into<String>) -> Self {
        self.setup_files.push((path.into(), content.into()));
        self
    }
    
    pub fn with_main_code(mut self, code: impl Into<String>) -> Self {
        self.main_code = code.into();
        self
    }
    
    pub fn with_expected_output(mut self, output: impl Into<String>) -> Self {
        self.expected_output = output.into();
        self
    }
    
    /// Execute the example in an isolated environment
    pub fn execute(&self) -> Result<ExecutionResult, Box<dyn std::error::Error>> {
        let temp_dir = TempDir::new()?;
        let workspace_root = temp_dir.path();
        
        // Set up workspace structure
        self.setup_workspace(&workspace_root)?;
        
        // Create main.rs with the example code
        let main_rs = workspace_root.join("src/main.rs");
        std::fs::create_dir_all(main_rs.parent().unwrap())?;
        std::fs::write(&main_rs, &self.main_code)?;
        
        // Run the example
        let output = Command::new("cargo")
            .args(&["run", "--quiet"])
            .current_dir(&workspace_root)
            .output()?;
        
        let result = ExecutionResult {
            success: output.status.success(),
            stdout: String::from_utf8_lossy(&output.stdout).to_string(),
            stderr: String::from_utf8_lossy(&output.stderr).to_string(),
            expected_output: self.expected_output.clone(),
        };
        
        Ok(result)
    }
    
    fn setup_workspace(&self, root: &Path) -> Result<(), Box<dyn std::error::Error>> {
        // Create Cargo.toml
        let cargo_toml = r#"[package]
name = "workspace-tools-example"
version = "0.1.0"
edition = "2021"

[dependencies]
workspace_tools = { path = "../../../../" }
"#;
        std::fs::write(root.join("Cargo.toml"), cargo_toml)?;
        
        // Create setup files
        for (file_path, content) in &self.setup_files {
            let full_path = root.join(file_path);
            if let Some(parent) = full_path.parent() {
                std::fs::create_dir_all(parent)?;
            }
            std::fs::write(full_path, content)?;
        }
        
        Ok(())
    }
}

#[derive(Debug)]
pub struct ExecutionResult {
    pub success: bool,
    pub stdout: String,
    pub stderr: String,
    pub expected_output: String,
}

impl ExecutionResult {
    pub fn matches_expected(&self) -> bool {
        if self.expected_output.is_empty() {
            self.success
        } else {
            self.success && self.stdout.trim() == self.expected_output.trim()
        }
    }
}

// Example definitions for documentation
pub fn create_basic_examples() -> Vec<InteractiveExample> {
    vec![
        InteractiveExample::new("hello_workspace", "Hello Workspace")
            .with_description("Basic workspace_tools usage - your first workspace-aware application")
            .with_file("config/greeting.toml", r#"message = "Hello from workspace_tools!"
name = "Developer""#)
            .with_main_code(r#"use workspace_tools::workspace;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ws = workspace()?;
    
    println!("🚀 Workspace root: {}", ws.root().display());
    println!("📁 Config directory: {}", ws.config_dir().display());
    
    // Read configuration
    let config_path = ws.config_dir().join("greeting.toml");
    if config_path.exists() {
        let config = std::fs::read_to_string(config_path)?;
        println!("📄 Config content:\n{}", config);
    }
    
    println!("✅ Successfully accessed workspace!");
    Ok(())
}"#)
            .with_expected_output("✅ Successfully accessed workspace!"),
            
        InteractiveExample::new("standard_directories", "Standard Directories")
            .with_description("Using workspace_tools standard directory layout")
            .with_file("data/users.json", r#"{"users": [{"name": "Alice"}, {"name": "Bob"}]}"#)
            .with_file("logs/.gitkeep", "")
            .with_main_code(r#"use workspace_tools::workspace;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ws = workspace()?;
    
    // Demonstrate all standard directories
    println!("📂 Standard Directories:");
    println!("  Config: {}", ws.config_dir().display());
    println!("  Data: {}", ws.data_dir().display());
    println!("  Logs: {}", ws.logs_dir().display());
    println!("  Docs: {}", ws.docs_dir().display());
    println!("  Tests: {}", ws.tests_dir().display());
    
    // Check which directories exist
    let directories = [
        ("config", ws.config_dir()),
        ("data", ws.data_dir()),
        ("logs", ws.logs_dir()),
        ("docs", ws.docs_dir()),
        ("tests", ws.tests_dir()),
    ];
    
    println!("\n📊 Directory Status:");
    for (name, path) in directories {
        let exists = path.exists();
        let status = if exists { "✅" } else { "❌" };
        println!("  {} {}: {}", status, name, path.display());
    }
    
    // Read data file
    let data_file = ws.data_dir().join("users.json");
    if data_file.exists() {
        let users = std::fs::read_to_string(data_file)?;
        println!("\n📄 Data file content:\n{}", users);
    }
    
    Ok(())
}"#),
            
        InteractiveExample::new("configuration_loading", "Configuration Loading")
            .with_description("Loading and validating configuration files")
            .with_file("config/app.toml", r#"[application]
name = "MyApp"
version = "1.0.0"
debug = true

[database]
host = "localhost"
port = 5432
name = "myapp_db"

[server]
port = 8080
workers = 4"#)
            .with_main_code(r#"use workspace_tools::workspace;
use std::collections::HashMap;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ws = workspace()?;
    
    // Find configuration file (supports .toml, .yaml, .json)
    match ws.find_config("app") {
        Ok(config_path) => {
            println!("📄 Found config: {}", config_path.display());
            
            let content = std::fs::read_to_string(config_path)?;
            println!("\n📋 Configuration content:");
            println!("{}", content);
            
            // In a real application, you'd deserialize this with serde
            println!("✅ Configuration loaded successfully!");
        }
        Err(e) => {
            println!("❌ No configuration found: {}", e);
            println!("💡 Expected files: config/app.{{toml,yaml,json}} or .app.toml");
        }
    }
    
    Ok(())
}"#),
    ]
}

// Test runner for all examples
pub fn test_all_examples() -> Result<(), Box<dyn std::error::Error>> {
    let examples = create_basic_examples();
    let mut passed = 0;
    let mut failed = 0;
    
    println!("🧪 Running interactive examples...\n");
    
    for example in &examples {
        print!("Testing '{}': ", example.title);
        
        match example.execute() {
            Ok(result) => {
                if result.matches_expected() {
                    println!("✅ PASSED");
                    passed += 1;
                } else {
                    println!("❌ FAILED");
                    println!("  Expected: {}", result.expected_output);
                    println!("  Got: {}", result.stdout);
                    if !result.stderr.is_empty() {
                        println!("  Error: {}", result.stderr);
                    }
                    failed += 1;
                }
            }
            Err(e) => {
                println!("❌ ERROR: {}", e);
                failed += 1;
            }
        }
    }
    
    println!("\n📊 Results: {} passed, {} failed", passed, failed);
    
    if failed > 0 {
        Err("Some examples failed".into())
    } else {
        Ok(())
    }
}
```

### **Phase 2: Comprehensive Guides** (Weeks 3-4)

#### **Week 3: Framework Integration Guides**
```markdown
<!-- book/integrations/frameworks/axum.md -->
# Axum Web Service Integration

This guide shows you how to build a production-ready web service using [Axum](https://github.com/tokio-rs/axum) and workspace_tools for reliable configuration and asset management.

## Overview

By the end of this guide, you'll have a complete web service that:
- ✅ Uses workspace_tools for all path operations
- ✅ Loads configuration from multiple environments
- ✅ Serves static assets reliably
- ✅ Implements structured logging
- ✅ Handles secrets securely
- ✅ Works consistently across development, testing, and production

## Project Setup

Let's create a new Axum project with workspace_tools:

```bash
cargo new --bin my-web-service
cd my-web-service
```

Add dependencies to `Cargo.toml`:

```toml
[dependencies]
axum = "0.7"
tokio = { version = "1.0", features = ["full"] }
tower = "0.4"
serde = { version = "1.0", features = ["derive"] }
toml = "0.8"
workspace_tools = { version = "0.2", features = ["serde_integration"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["json"] }
```

## Workspace Structure

Create the standard workspace structure:

```bash
mkdir -p config data logs assets/static
```

Your project should now look like:

```
my-web-service/
├── Cargo.toml
├── src/
│   └── main.rs
├── config/              # Configuration files
├── data/               # Application data
├── logs/               # Application logs  
├── assets/
│   └── static/         # Static web assets
└── tests/              # Integration tests
```

## Configuration Management

Create configuration files for different environments:

**`config/app.toml`** (base configuration):
```toml
[server]
host = "127.0.0.1"
port = 3000
workers = 4

[database]
url = "postgresql://localhost/myapp_dev"
max_connections = 10
timeout_seconds = 30

[logging]
level = "info"
format = "json"

[assets]
static_dir = "assets/static"
```

**`config/app.production.toml`** (production overrides):
```toml
[server]
host = "0.0.0.0"
port = 8080
workers = 8

[database]
url = "${DATABASE_URL}"
max_connections = 20

[logging]
level = "warn"
```

## Application Code

Here's the complete application implementation:

**`src/config.rs`**:
```rust
use serde::{Deserialize, Serialize};
use workspace_tools::Workspace;

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct AppConfig {
    pub server: ServerConfig,
    pub database: DatabaseConfig,
    pub logging: LoggingConfig,
    pub assets: AssetsConfig,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ServerConfig {
    pub host: String,
    pub port: u16,
    pub workers: usize,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct DatabaseConfig {
    pub url: String,
    pub max_connections: u32,
    pub timeout_seconds: u64,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct LoggingConfig {
    pub level: String,
    pub format: String,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct AssetsConfig {
    pub static_dir: String,
}

impl AppConfig {
    pub fn load(workspace: &Workspace) -> Result<Self, Box<dyn std::error::Error>> {
        // Determine environment
        let env = std::env::var("APP_ENV").unwrap_or_else(|_| "development".to_string());
        
        // Load base config
        let base_config_path = workspace.find_config("app")?;
        let mut config: AppConfig = {
            let content = std::fs::read_to_string(&base_config_path)?;
            toml::from_str(&content)?
        };
        
        // Load environment-specific overrides
        let env_config_path = workspace.join(format!("config/app.{}.toml", env));
        if env_config_path.exists() {
            let env_content = std::fs::read_to_string(&env_config_path)?;
            let env_config: AppConfig = toml::from_str(&env_content)?;
            
            // Simple merge (in production, you'd want more sophisticated merging)
            config.server = env_config.server;
            if !env_config.database.url.is_empty() {
                config.database = env_config.database;
            }
            config.logging = env_config.logging;
        }
        
        // Substitute environment variables
        config.database.url = substitute_env_vars(&config.database.url);
        
        Ok(config)
    }
}

fn substitute_env_vars(input: &str) -> String {
    let mut result = input.to_string();
    
    // Simple ${VAR} substitution
    while let Some(start) = result.find("${") {
        if let Some(end) = result[start..].find('}') {
            let var_name = &result[start + 2..start + end];
            if let Ok(var_value) = std::env::var(var_name) {
                result.replace_range(start..start + end + 1, &var_value);
            } else {
                break; // Avoid infinite loop on missing vars
            }
        } else {
            break;
        }
    }
    
    result
}
```

**`src/main.rs`**:
```rust
mod config;

use axum::{
    extract::State,
    http::StatusCode,
    response::Json,
    routing::get,
    Router,
};
use serde_json::{json, Value};
use std::sync::Arc;
use tower::ServiceBuilder;
use tower_http::services::ServeDir;
use tracing::{info, instrument};
use workspace_tools::workspace;

use config::AppConfig;

#[derive(Clone)]
pub struct AppState {
    config: Arc<AppConfig>,
    workspace: Arc<workspace_tools::Workspace>,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize workspace
    let ws = workspace()?;
    info!("🚀 Initializing web service at: {}", ws.root().display());
    
    // Load configuration
    let config = Arc::new(AppConfig::load(&ws)?);
    info!("📄 Configuration loaded for environment: {}", 
          std::env::var("APP_ENV").unwrap_or_else(|_| "development".to_string()));
    
    // Initialize logging
    initialize_logging(&ws, &config)?;
    
    // Create application state
    let state = AppState {
        config: config.clone(),
        workspace: Arc::new(ws),
    };
    
    // Create static file service
    let static_assets = ServeDir::new(state.workspace.join(&config.assets.static_dir));
    
    // Build router
    let app = Router::new()
        .route("/", get(root_handler))
        .route("/health", get(health_handler))
        .route("/config", get(config_handler))
        .nest_service("/static", static_assets)
        .with_state(state)
        .layer(
            ServiceBuilder::new()
                .layer(tower_http::trace::TraceLayer::new_for_http())
        );
    
    // Start server
    let addr = format!("{}:{}", config.server.host, config.server.port);
    info!("🌐 Starting server on {}", addr);
    
    let listener = tokio::net::TcpListener::bind(&addr).await?;
    axum::serve(listener, app).await?;
    
    Ok(())
}

#[instrument(skip(state))]
async fn root_handler(State(state): State<AppState>) -> Json<Value> {
    Json(json!({
        "message": "Hello from workspace_tools + Axum!",
        "workspace_root": state.workspace.root().display().to_string(),
        "config_dir": state.workspace.config_dir().display().to_string(),
        "status": "ok"
    }))
}

#[instrument(skip(state))]
async fn health_handler(State(state): State<AppState>) -> (StatusCode, Json<Value>) {
    // Check workspace accessibility
    if !state.workspace.root().exists() {
        return (
            StatusCode::SERVICE_UNAVAILABLE,
            Json(json!({"status": "error", "message": "Workspace not accessible"}))
        );
    }
    
    // Check config directory
    if !state.workspace.config_dir().exists() {
        return (
            StatusCode::SERVICE_UNAVAILABLE,
            Json(json!({"status": "error", "message": "Config directory missing"}))
        );
    }
    
    (
        StatusCode::OK,
        Json(json!({
            "status": "healthy",
            "workspace": {
                "root": state.workspace.root().display().to_string(),
                "config_accessible": state.workspace.config_dir().exists(),
                "data_accessible": state.workspace.data_dir().exists(),
                "logs_accessible": state.workspace.logs_dir().exists(),
            }
        }))
    )
}

#[instrument(skip(state))]
async fn config_handler(State(state): State<AppState>) -> Json<Value> {
    Json(json!({
        "server": {
            "host": state.config.server.host,
            "port": state.config.server.port,
            "workers": state.config.server.workers
        },
        "logging": {
            "level": state.config.logging.level,
            "format": state.config.logging.format
        },
        "workspace": {
            "root": state.workspace.root().display().to_string(),
            "directories": {
                "config": state.workspace.config_dir().display().to_string(),
                "data": state.workspace.data_dir().display().to_string(),
                "logs": state.workspace.logs_dir().display().to_string(),
            }
        }
    }))
}

fn initialize_logging(ws: &workspace_tools::Workspace, config: &AppConfig) -> Result<(), Box<dyn std::error::Error>> {
    // Ensure logs directory exists
    std::fs::create_dir_all(ws.logs_dir())?;
    
    // Configure tracing based on config
    let subscriber = tracing_subscriber::FmtSubscriber::builder()
        .with_max_level(match config.logging.level.as_str() {
            "trace" => tracing::Level::TRACE,
            "debug" => tracing::Level::DEBUG,
            "info" => tracing::Level::INFO,
            "warn" => tracing::Level::WARN,
            "error" => tracing::Level::ERROR,
            _ => tracing::Level::INFO,
        })
        .finish();
    
    tracing::subscriber::set_global_default(subscriber)?;
    
    Ok(())
}
```

## Running the Application

### Development
```bash
cargo run
```

Visit:
- http://localhost:3000/ - Main endpoint
- http://localhost:3000/health - Health check
- http://localhost:3000/config - Configuration info

### Production
```bash
APP_ENV=production DATABASE_URL=postgresql://prod-server/myapp cargo run
```

## Testing

Create integration tests using workspace_tools:

**`tests/integration_test.rs`**:
```rust
use workspace_tools::testing::create_test_workspace_with_structure;

#[tokio::test]
async fn test_web_service_startup() {
    let (_temp_dir, ws) = create_test_workspace_with_structure();
    
    // Create test configuration
    let config_content = r#"
[server]
host = "127.0.0.1"
port = 0

[database]
url = "sqlite::memory:"
max_connections = 1
timeout_seconds = 5

[logging]
level = "debug"
format = "json"

[assets]
static_dir = "assets/static"
    "#;
    
    std::fs::write(ws.config_dir().join("app.toml"), config_content).unwrap();
    
    // Test configuration loading
    let config = my_web_service::config::AppConfig::load(&ws).unwrap();
    assert_eq!(config.server.host, "127.0.0.1");
    assert_eq!(config.database.max_connections, 1);
}
```

## Deployment with Docker

**`Dockerfile`**:
```dockerfile
FROM rust:1.70 as builder

WORKDIR /app
COPY . .
RUN cargo build --release

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy binary
COPY --from=builder /app/target/release/my-web-service /app/

# Copy workspace structure
COPY config/ ./config/
COPY assets/ ./assets/
RUN mkdir -p data logs

# Set environment
ENV WORKSPACE_PATH=/app
ENV APP_ENV=production

EXPOSE 8080
CMD ["./my-web-service"]
```

## Best Practices Summary

✅ **Configuration Management**
- Use layered configuration (base + environment)
- Environment variable substitution for secrets
- Validate configuration on startup

✅ **Static Assets**
- Use workspace-relative paths for assets
- Leverage Axum's `ServeDir` for static files
- Version assets in production

✅ **Logging**
- Initialize logs directory with workspace_tools
- Use structured logging (JSON in production)
- Configure log levels per environment

✅ **Health Checks**
- Verify workspace accessibility
- Check critical directories exist
- Return meaningful error messages

✅ **Testing**
- Use workspace_tools test utilities
- Test with isolated workspace environments
- Validate configuration loading

This integration shows how workspace_tools eliminates path-related issues in web services while promoting clean, maintainable architecture patterns.
```

#### **Week 4: Advanced Use Cases and Patterns**
```markdown
<!-- book/cookbook/common-patterns.md -->
# Common Patterns and Recipes

This cookbook contains battle-tested patterns for using workspace_tools in real-world scenarios. Each pattern includes complete code examples, explanations, and variations.

## Pattern 1: Configuration Hierarchies

**Problem**: You need different configurations for development, testing, staging, and production environments, with shared base settings and environment-specific overrides.

**Solution**: Use layered configuration files with workspace_tools:

```rust
use workspace_tools::Workspace;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Config {
    pub app: AppSettings,
    pub database: DatabaseSettings,
    pub cache: CacheSettings,
    pub features: FeatureFlags,
}

impl Config {
    pub fn load_for_environment(ws: &Workspace, env: &str) -> Result<Self, ConfigError> {
        let mut config_layers = Vec::new();
        
        // 1. Base configuration (always loaded)
        config_layers.push("base");
        
        // 2. Environment-specific configuration
        config_layers.push(env);
        
        // 3. Local overrides (for development)
        if env == "development" {
            config_layers.push("local");
        }
        
        // 4. Secret configuration (if exists)
        config_layers.push("secrets");
        
        Self::load_layered(ws, &config_layers)
    }
    
    fn load_layered(ws: &Workspace, layers: &[&str]) -> Result<Self, ConfigError> {
        let mut final_config: Option<Config> = None;
        
        for layer in layers {
            let config_name = if *layer == "base" { "config" } else { &format!("config.{}", layer) };
            
            match Self::load_single_config(ws, config_name) {
                Ok(layer_config) => {
                    final_config = Some(match final_config {
                        None => layer_config,
                        Some(base) => base.merge_with(layer_config)?,
                    });
                }
                Err(ConfigError::NotFound(_)) if *layer != "base" => {
                    // Optional layers can be missing
                    continue;
                }
                Err(e) => return Err(e),
            }
        }
        
        final_config.ok_or(ConfigError::NotFound("base configuration".to_string()))
    }
    
    fn load_single_config(ws: &Workspace, name: &str) -> Result<Self, ConfigError> {
        let config_path = ws.find_config(name)
            .map_err(|_| ConfigError::NotFound(name.to_string()))?;
        
        let content = std::fs::read_to_string(&config_path)
            .map_err(|e| ConfigError::ReadError(e.to_string()))?;
        
        // Support multiple formats
        let config = if config_path.extension().map_or(false, |ext| ext == "toml") {
            toml::from_str(&content)
        } else if config_path.extension().map_or(false, |ext| ext == "yaml" || ext == "yml") {
            serde_yaml::from_str(&content)
        } else {
            serde_json::from_str(&content)
        }.map_err(|e| ConfigError::ParseError(e.to_string()))?;
        
        Ok(config)
    }
    
    fn merge_with(mut self, other: Config) -> Result<Self, ConfigError> {
        // Merge strategies for different fields
        self.app = other.app; // Replace
        self.database = self.database.merge_with(other.database); // Selective merge
        self.cache = other.cache; // Replace
        self.features.merge_with(&other.features); // Additive merge
        
        Ok(self)
    }
}

// Usage example
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ws = workspace_tools::workspace()?;
    let env = std::env::var("APP_ENV").unwrap_or_else(|_| "development".to_string());
    
    let config = Config::load_for_environment(&ws, &env)?;
    println!("Loaded configuration for environment: {}", env);
    
    Ok(())
}
```

**File Structure**:
```
config/
├── config.toml              # Base configuration
├── config.development.toml  # Development overrides  
├── config.testing.toml      # Testing overrides
├── config.staging.toml      # Staging overrides
├── config.production.toml   # Production overrides
├── config.local.toml        # Local developer overrides (git-ignored)
└── config.secret.toml       # Secrets (git-ignored)
```

## Pattern 2: Plugin Architecture

**Problem**: You want to build an extensible application where plugins can be loaded dynamically and have access to workspace resources.

**Solution**: Create a plugin system that provides workspace context:

```rust
use workspace_tools::Workspace;
use std::collections::HashMap;
use std::sync::Arc;

pub trait Plugin: Send + Sync {
    fn name(&self) -> &str;
    fn version(&self) -> &str;
    fn initialize(&mut self, workspace: Arc<Workspace>) -> Result<(), PluginError>;
    fn execute(&self, context: &PluginContext) -> Result<PluginResult, PluginError>;
    fn shutdown(&mut self) -> Result<(), PluginError>;
}

pub struct PluginManager {
    plugins: HashMap<String, Box<dyn Plugin>>,
    workspace: Arc<Workspace>,
}

impl PluginManager {
    pub fn new(workspace: Workspace) -> Self {
        Self {
            plugins: HashMap::new(),
            workspace: Arc::new(workspace),
        }
    }
    
    pub fn load_plugins_from_directory(&mut self, plugin_dir: &str) -> Result<usize, PluginError> {
        let plugins_path = self.workspace.join(plugin_dir);
        
        if !plugins_path.exists() {
            std::fs::create_dir_all(&plugins_path)
                .map_err(|e| PluginError::IoError(e.to_string()))?;
            return Ok(0);
        }
        
        let mut loaded_count = 0;
        
        // Scan for plugin configuration files
        for entry in std::fs::read_dir(&plugins_path)
            .map_err(|e| PluginError::IoError(e.to_string()))? {
            
            let entry = entry.map_err(|e| PluginError::IoError(e.to_string()))?;
            let path = entry.path();
            
            if path.extension().map_or(false, |ext| ext == "toml") {
                if let Ok(plugin) = self.load_plugin_from_config(&path) {
                    self.register_plugin(plugin)?;
                    loaded_count += 1;
                }
            }
        }
        
        Ok(loaded_count)
    }
    
    fn load_plugin_from_config(&self, config_path: &std::path::Path) -> Result<Box<dyn Plugin>, PluginError> {
        let config_content = std::fs::read_to_string(config_path)
            .map_err(|e| PluginError::IoError(e.to_string()))?;
        
        let plugin_config: PluginConfig = toml::from_str(&config_content)
            .map_err(|e| PluginError::ConfigError(e.to_string()))?;
        
        // Create plugin based on type
        match plugin_config.plugin_type.as_str() {
            "data_processor" => Ok(Box::new(DataProcessorPlugin::new(plugin_config)?)),
            "notification" => Ok(Box::new(NotificationPlugin::new(plugin_config)?)),
            "backup" => Ok(Box::new(BackupPlugin::new(plugin_config)?)),
            _ => Err(PluginError::UnknownPluginType(plugin_config.plugin_type))
        }
    }
    
    pub fn register_plugin(&mut self, mut plugin: Box<dyn Plugin>) -> Result<(), PluginError> {
        let name = plugin.name().to_string();
        
        // Initialize plugin with workspace context
        plugin.initialize(self.workspace.clone())?;
        
        self.plugins.insert(name, plugin);
        Ok(())
    }
    
    pub fn execute_plugin(&self, name: &str, context: &PluginContext) -> Result<PluginResult, PluginError> {
        let plugin = self.plugins.get(name)
            .ok_or_else(|| PluginError::PluginNotFound(name.to_string()))?;
        
        plugin.execute(context)
    }
    
    pub fn shutdown_all(&mut self) -> Result<(), PluginError> {
        for (name, plugin) in &mut self.plugins {
            if let Err(e) = plugin.shutdown() {
                eprintln!("Warning: Failed to shutdown plugin '{}': {}", name, e);
            }
        }
        self.plugins.clear();
        Ok(())
    }
}

// Example plugin implementation
pub struct DataProcessorPlugin {
    name: String,
    version: String,
    config: PluginConfig,
    workspace: Option<Arc<Workspace>>,
    input_dir: Option<std::path::PathBuf>,
    output_dir: Option<std::path::PathBuf>,
}

impl DataProcessorPlugin {
    fn new(config: PluginConfig) -> Result<Self, PluginError> {
        Ok(Self {
            name: config.name.clone(),
            version: config.version.clone(),
            config,
            workspace: None,
            input_dir: None,
            output_dir: None,
        })
    }
}

impl Plugin for DataProcessorPlugin {
    fn name(&self) -> &str {
        &self.name
    }
    
    fn version(&self) -> &str {
        &self.version
    }
    
    fn initialize(&mut self, workspace: Arc<Workspace>) -> Result<(), PluginError> {
        // Set up plugin-specific directories using workspace
        self.input_dir = Some(workspace.data_dir().join("input"));
        self.output_dir = Some(workspace.data_dir().join("output"));
        
        // Create directories if they don't exist
        if let Some(input_dir) = &self.input_dir {
            std::fs::create_dir_all(input_dir)
                .map_err(|e| PluginError::IoError(e.to_string()))?;
        }
        
        if let Some(output_dir) = &self.output_dir {
            std::fs::create_dir_all(output_dir)
                .map_err(|e| PluginError::IoError(e.to_string()))?;
        }
        
        self.workspace = Some(workspace);
        Ok(())
    }
    
    fn execute(&self, context: &PluginContext) -> Result<PluginResult, PluginError> {
        let workspace = self.workspace.as_ref()
            .ok_or(PluginError::NotInitialized)?;
        
        let input_dir = self.input_dir.as_ref().unwrap();
        let output_dir = self.output_dir.as_ref().unwrap();
        
        // Process files from input directory
        let mut processed_files = Vec::new();
        
        for entry in std::fs::read_dir(input_dir)
            .map_err(|e| PluginError::IoError(e.to_string()))? {
            
            let entry = entry.map_err(|e| PluginError::IoError(e.to_string()))?;
            let input_path = entry.path();
            
            if input_path.is_file() {
                let file_name = input_path.file_name().unwrap().to_string_lossy();
                let output_path = output_dir.join(format!("processed_{}", file_name));
                
                // Simple processing: read, transform, write
                let content = std::fs::read_to_string(&input_path)
                    .map_err(|e| PluginError::IoError(e.to_string()))?;
                
                let processed_content = self.process_content(&content);
                
                std::fs::write(&output_path, processed_content)
                    .map_err(|e| PluginError::IoError(e.to_string()))?;
                
                processed_files.push(output_path.to_string_lossy().to_string());
            }
        }
        
        Ok(PluginResult {
            success: true,
            message: format!("Processed {} files", processed_files.len()),
            data: Some(processed_files.into()),
        })
    }
    
    fn shutdown(&mut self) -> Result<(), PluginError> {
        // Cleanup plugin resources
        self.workspace = None;
        Ok(())
    }
}

impl DataProcessorPlugin {
    fn process_content(&self, content: &str) -> String {
        // Example processing: convert to uppercase and add timestamp
        format!("Processed at {}: {}", 
               chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC"),
               content.to_uppercase())
    }
}

// Usage example
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ws = workspace_tools::workspace()?;
    let mut plugin_manager = PluginManager::new(ws);
    
    // Load plugins from workspace
    let loaded_count = plugin_manager.load_plugins_from_directory("plugins")?;
    println!("Loaded {} plugins", loaded_count);
    
    // Execute a plugin
    let context = PluginContext::new();
    if let Ok(result) = plugin_manager.execute_plugin("data_processor", &context) {
        println!("Plugin result: {}", result.message);
    }
    
    // Cleanup
    plugin_manager.shutdown_all()?;
    
    Ok(())
}
```

**Plugin Configuration Example** (`plugins/data_processor.toml`):
```toml
name = "data_processor"
version = "1.0.0"
plugin_type = "data_processor"
description = "Processes data files in the workspace"

[settings]
batch_size = 100
timeout_seconds = 30

[permissions]
read_data = true
write_data = true
read_config = false
write_config = false
```

## Pattern 3: Multi-Workspace Monorepo

**Problem**: You have a large monorepo with multiple related projects that need to share resources and configuration while maintaining independence.

**Solution**: Create a workspace hierarchy with shared utilities:

```rust
use workspace_tools::Workspace;
use std::collections::HashMap;
use std::path::{Path, PathBuf};

pub struct MonorepoManager {
    root_workspace: Workspace,
    sub_workspaces: HashMap<String, Workspace>,
    shared_config: SharedConfig,
}

impl MonorepoManager {
    pub fn new() -> Result<Self, MonorepoError> {
        let root_workspace = workspace_tools::workspace()?;
        
        // Verify this is a monorepo structure
        if !Self::is_monorepo_root(&root_workspace) {
            return Err(MonorepoError::NotMonorepo);
        }
        
        let shared_config = SharedConfig::load(&root_workspace)?;
        
        Ok(Self {
            root_workspace,
            sub_workspaces: HashMap::new(),
            shared_config,
        })
    }
    
    fn is_monorepo_root(ws: &Workspace) -> bool {
        // Check for monorepo indicators
        ws.join("workspace.toml").exists() || 
        ws.join("monorepo.json").exists() ||
        ws.join("projects").is_dir()
    }
    
    pub fn discover_sub_workspaces(&mut self) -> Result<Vec<String>, MonorepoError> {
        let projects_dir = self.root_workspace.join("projects");
        let mut discovered = Vec::new();
        
        if projects_dir.exists() {
            for entry in std::fs::read_dir(&projects_dir)
                .map_err(|e| MonorepoError::IoError(e.to_string()))? {
                
                let entry = entry.map_err(|e| MonorepoError::IoError(e.to_string()))?;
                let project_path = entry.path();
                
                if project_path.is_dir() {
                    let project_name = project_path.file_name()
                        .unwrap()
                        .to_string_lossy()
                        .to_string();
                    
                    // Create workspace for this project
                    std::env::set_var("WORKSPACE_PATH", &project_path);
                    let sub_workspace = Workspace::resolve()
                        .map_err(|_| MonorepoError::InvalidSubWorkspace(project_name.clone()))?;
                    
                    self.sub_workspaces.insert(project_name.clone(), sub_workspace);
                    discovered.push(project_name);
                }
            }
        }
        
        // Restore original workspace path
        std::env::set_var("WORKSPACE_PATH", self.root_workspace.root());
        
        Ok(discovered)
    }
    
    pub fn get_sub_workspace(&self, name: &str) -> Option<&Workspace> {
        self.sub_workspaces.get(name)
    }
    
    pub fn execute_in_all_workspaces<F, R>(&self, mut operation: F) -> Vec<(String, Result<R, MonorepoError>)>
    where
        F: FnMut(&str, &Workspace) -> Result<R, MonorepoError>,
    {
        let mut results = Vec::new();
        
        // Execute in root workspace
        let root_result = operation("root", &self.root_workspace);
        results.push(("root".to_string(), root_result));
        
        // Execute in each sub-workspace
        for (name, workspace) in &self.sub_workspaces {
            let result = operation(name, workspace);
            results.push((name.clone(), result));
        }
        
        results
    }
    
    pub fn sync_shared_configuration(&self) -> Result<(), MonorepoError> {
        let shared_config_content = toml::to_string_pretty(&self.shared_config)
            .map_err(|e| MonorepoError::ConfigError(e.to_string()))?;
        
        // Write shared config to each sub-workspace
        for (name, workspace) in &self.sub_workspaces {
            let shared_config_path = workspace.config_dir().join("shared.toml");
            
            // Ensure config directory exists
            std::fs::create_dir_all(workspace.config_dir())
                .map_err(|e| MonorepoError::IoError(e.to_string()))?;
            
            std::fs::write(&shared_config_path, &shared_config_content)
                .map_err(|e| MonorepoError::IoError(e.to_string()))?;
            
            println!("Synced shared configuration to project: {}", name);
        }
        
        Ok(())
    }
    
    pub fn build_dependency_graph(&self) -> Result<DependencyGraph, MonorepoError> {
        let mut graph = DependencyGraph::new();
        
        // Add root workspace
        graph.add_node("root", &self.root_workspace);
        
        // Add sub-workspaces and their dependencies
        for (name, workspace) in &self.sub_workspaces {
            graph.add_node(name, workspace);
            
            // Parse Cargo.toml to find workspace dependencies
            let cargo_toml_path = workspace.join("Cargo.toml");
            if cargo_toml_path.exists() {
                let dependencies = self.parse_workspace_dependencies(&cargo_toml_path)?;
                for dep in dependencies {
                    if self.sub_workspaces.contains_key(&dep) {
                        graph.add_edge(name, &dep);
                    }
                }
            }
        }
        
        Ok(graph)
    }
    
    fn parse_workspace_dependencies(&self, cargo_toml_path: &Path) -> Result<Vec<String>, MonorepoError> {
        let content = std::fs::read_to_string(cargo_toml_path)
            .map_err(|e| MonorepoError::IoError(e.to_string()))?;
        
        let parsed: toml::Value = toml::from_str(&content)
            .map_err(|e| MonorepoError::ConfigError(e.to_string()))?;
        
        let mut workspace_deps = Vec::new();
        
        if let Some(dependencies) = parsed.get("dependencies").and_then(|d| d.as_table()) {
            for (dep_name, dep_config) in dependencies {
                if let Some(dep_table) = dep_config.as_table() {
                    if dep_table.get("path").is_some() {
                        // This is a local workspace dependency
                        workspace_deps.push(dep_name.clone());
                    }
                }
            }
        }
        
        Ok(workspace_deps)
    }
}

// Usage example for monorepo operations
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut monorepo = MonorepoManager::new()?;
    
    // Discover all sub-workspaces
    let projects = monorepo.discover_sub_workspaces()?;
    println!("Discovered projects: {:?}", projects);
    
    // Sync shared configuration
    monorepo.sync_shared_configuration()?;
    
    // Execute operation across all workspaces
    let results = monorepo.execute_in_all_workspaces(|name, workspace| {
        // Example: Check if tests directory exists
        let tests_exist = workspace.tests_dir().exists();
        Ok(format!("Tests directory exists: {}", tests_exist))
    });
    
    for (name, result) in results {
        match result {
            Ok(message) => println!("{}: {}", name, message),
            Err(e) => eprintln!("{}: Error - {}", name, e),
        }
    }
    
    // Build dependency graph
    let dep_graph = monorepo.build_dependency_graph()?;
    println!("Dependency graph: {:#?}", dep_graph);
    
    Ok(())
}
```

**Monorepo Structure**:
```
my-monorepo/
├── workspace.toml           # Monorepo configuration
├── config/                  # Shared configuration
│   ├── shared.toml
│   └── ci.yaml
├── scripts/                 # Shared build/deployment scripts
├── docs/                    # Monorepo-wide documentation
└── projects/                # Individual project workspaces
    ├── web-api/             # Project A
    │   ├── Cargo.toml
    │   ├── src/
    │   ├── config/
    │   └── tests/
    ├── mobile-client/       # Project B
    │   ├── Cargo.toml
    │   ├── src/
    │   ├── config/
    │   └── tests/
    └── shared-lib/          # Shared library
        ├── Cargo.toml
        ├── src/
        └── tests/
```

These patterns demonstrate how workspace_tools scales from simple applications to complex enterprise scenarios while maintaining clean, maintainable code organization.
```

### **Phase 3: Community Content Platform** (Weeks 5-6)

#### **Week 5: Interactive Documentation Platform**
```rust
// docs-platform/src/lib.rs - Interactive documentation platform

use axum::{
    extract::{Path, Query, State},
    http::StatusCode,
    response::{Html, Json},
    routing::get,
    Router,
};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;

#[derive(Debug, Serialize, Deserialize)]
pub struct DocumentationSite {
    pub title: String,
    pub description: String,
    pub sections: Vec<DocumentationSection>,
    pub examples: HashMap<String, InteractiveExample>,
    pub search_index: SearchIndex,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct DocumentationSection {
    pub id: String,
    pub title: String,
    pub content: String,
    pub subsections: Vec<DocumentationSection>,
    pub examples: Vec<String>, // Example IDs
    pub code_snippets: Vec<CodeSnippet>,
    pub metadata: SectionMetadata,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct CodeSnippet {
    pub language: String,
    pub code: String,
    pub executable: bool,
    pub description: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SectionMetadata {
    pub difficulty: DifficultyLevel,
    pub estimated_reading_time: u32, // minutes
    pub prerequisites: Vec<String>,
    pub related_sections: Vec<String>,
    pub last_updated: chrono::DateTime<chrono::Utc>,
}

#[derive(Debug, Serialize, Deserialize)]
pub enum DifficultyLevel {
    Beginner,
    Intermediate,
    Advanced,
    Expert,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct InteractiveExample {
    pub id: String,
    pub title: String,
    pub description: String,
    pub code: String,
    pub setup_files: Vec<(String, String)>,
    pub expected_output: Option<String>,
    pub explanation: String,
    pub difficulty: DifficultyLevel,
    pub tags: Vec<String>,
    pub run_count: u64,
    pub rating: f32,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SearchIndex {
    pub sections: HashMap<String, SearchableSection>,
    pub examples: HashMap<String, SearchableExample>,
    pub keywords: HashMap<String, Vec<String>>, // keyword -> [section_ids]
}

// Web application state
#[derive(Clone)]
pub struct AppState {
    pub docs: Arc<RwLock<DocumentationSite>>,
    pub workspace: Arc<workspace_tools::Workspace>,
    pub example_runner: Arc<ExampleRunner>,
}

pub struct ExampleRunner {
    temp_dir: tempfile::TempDir,
}

impl ExampleRunner {
    pub fn new() -> Result<Self, std::io::Error> {
        Ok(Self {
            temp_dir: tempfile::TempDir::new()?,
        })
    }
    
    pub async fn run_example(&self, example: &InteractiveExample) -> Result<ExampleResult, String> {
        let example_dir = self.temp_dir.path().join(&example.id);
        tokio::fs::create_dir_all(&example_dir).await
            .map_err(|e| e.to_string())?;
        
        // Set up Cargo.toml
        let cargo_toml = r#"[package]
name = "interactive-example"
version = "0.1.0"
edition = "2021"

[dependencies]
workspace_tools = { path = "../../../../" }
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.0", features = ["full"] }
"#;
        
        tokio::fs::write(example_dir.join("Cargo.toml"), cargo_toml).await
            .map_err(|e| e.to_string())?;
        
        // Create src directory and main.rs
        tokio::fs::create_dir_all(example_dir.join("src")).await
            .map_err(|e| e.to_string())?;
        tokio::fs::write(example_dir.join("src/main.rs"), &example.code).await
            .map_err(|e| e.to_string())?;
        
        // Create setup files
        for (file_path, content) in &example.setup_files {
            let full_path = example_dir.join(file_path);
            if let Some(parent) = full_path.parent() {
                tokio::fs::create_dir_all(parent).await
                    .map_err(|e| e.to_string())?;
            }
            tokio::fs::write(full_path, content).await
                .map_err(|e| e.to_string())?;
        }
        
        // Execute the example
        let output = tokio::process::Command::new("cargo")
            .args(&["run", "--quiet"])
            .current_dir(&example_dir)
            .output()
            .await
            .map_err(|e| e.to_string())?;
        
        Ok(ExampleResult {
            success: output.status.success(),
            stdout: String::from_utf8_lossy(&output.stdout).to_string(),
            stderr: String::from_utf8_lossy(&output.stderr).to_string(),
            execution_time: std::time::Duration::from_secs(1), // TODO: measure actual time
        })
    }
}

#[derive(Debug, Serialize)]
pub struct ExampleResult {
    pub success: bool,
    pub stdout: String,
    pub stderr: String,
    pub execution_time: std::time::Duration,
}

// API handlers
pub async fn serve_documentation(
    Path(section_id): Path<String>,
    State(state): State<AppState>,
) -> Result<Html<String>, StatusCode> {
    let docs = state.docs.read().await;
    
    if let Some(section) = find_section(&docs.sections, &section_id) {
        let html = render_section_html(section, &docs.examples);
        Ok(Html(html))
    } else {
        Err(StatusCode::NOT_FOUND)
    }
}

pub async fn run_interactive_example(
    Path(example_id): Path<String>,
    State(state): State<AppState>,
) -> Result<Json<ExampleResult>, StatusCode> {
    let docs = state.docs.read().await;
    
    if let Some(example) = docs.examples.get(&example_id) {
        match state.example_runner.run_example(example).await {
            Ok(result) => Ok(Json(result)),
            Err(error) => {
                let error_result = ExampleResult {
                    success: false,
                    stdout: String::new(),
                    stderr: error,
                    execution_time: std::time::Duration::from_secs(0),
                };
                Ok(Json(error_result))
            }
        }
    } else {
        Err(StatusCode::NOT_FOUND)
    }
}

#[derive(Deserialize)]
pub struct SearchQuery {
    q: String,
    filter: Option<String>,
    difficulty: Option<DifficultyLevel>,
}

pub async fn search_documentation(
    Query(query): Query<SearchQuery>,
    State(state): State<AppState>,
) -> Result<Json<SearchResults>, StatusCode> {
    let docs = state.docs.read().await;
    let results = search_content(&docs, &query.q, query.difficulty.as_ref());
    Ok(Json(results))
}

fn search_content(
    docs: &DocumentationSite,
    query: &str,
    difficulty_filter: Option<&DifficultyLevel>,
) -> SearchResults {
    let mut section_results = Vec::new();
    let mut example_results = Vec::new();
    
    let query_lower = query.to_lowercase();
    
    // Search sections
    search_sections_recursive(&docs.sections, &query_lower, &mut section_results);
    
    // Search examples
    for (id, example) in &docs.examples {
        if difficulty_filter.map_or(true, |filter| std::mem::discriminant(filter) == std::mem::discriminant(&example.difficulty)) {
            let relevance = calculate_example_relevance(example, &query_lower);
            if relevance > 0.0 {
                example_results.push(SearchResultItem {
                    id: id.clone(),
                    title: example.title.clone(),
                    excerpt: truncate_text(&example.description, 150),
                    relevance,
                    item_type: "example".to_string(),
                });
            }
        }
    }
    
    // Sort by relevance
    section_results.sort_by(|a, b| b.relevance.partial_cmp(&a.relevance).unwrap());
    example_results.sort_by(|a, b| b.relevance.partial_cmp(&a.relevance).unwrap());
    
    SearchResults {
        query: query.to_string(),
        total_results: section_results.len() + example_results.len(),
        sections: section_results,
        examples: example_results,
    }
}

#[derive(Debug, Serialize)]
pub struct SearchResults {
    pub query: String,
    pub total_results: usize,
    pub sections: Vec<SearchResultItem>,
    pub examples: Vec<SearchResultItem>,
}

#[derive(Debug, Serialize)]
pub struct SearchResultItem {
    pub id: String,
    pub title: String,
    pub excerpt: String,
    pub relevance: f32,
    pub item_type: String,
}

// HTML rendering functions
fn render_section_html(section: &DocumentationSection, examples: &HashMap<String, InteractiveExample>) -> String {
    format!(r#"<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{} - workspace_tools Documentation</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism.min.css" rel="stylesheet">
    <link href="/static/docs.css" rel="stylesheet">
</head>
<body>
    <nav class="sidebar">
        <div class="sidebar-header">
            <h2>workspace_tools</h2>
            <span class="version">v0.2.0</span>
        </div>
        <div class="search-box">
            <input type="text" id="search" placeholder="Search documentation...">
        </div>
        <!-- Navigation will be populated by JavaScript -->
    </nav>
    
    <main class="content">
        <article>
            <header>
                <h1>{}</h1>
                <div class="article-meta">
                    <span class="difficulty difficulty-{}">{:?}</span>
                    <span class="reading-time">{} min read</span>
                    <span class="last-updated">Updated {}</span>
                </div>
            </header>
            
            <div class="article-content">
                {}
            </div>
            
            {}
            
            {}
        </article>
    </main>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/components/prism-core.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/plugins/autoloader/prism-autoloader.min.js"></script>
    <script src="/static/docs.js"></script>
</body>
</html>"#,
        section.title,
        section.title,
        format!("{:?}", section.metadata.difficulty).to_lowercase(),
        section.metadata.difficulty,
        section.metadata.estimated_reading_time,
        section.metadata.last_updated.format("%B %d, %Y"),
        markdown_to_html(&section.content),
        render_code_snippets(&section.code_snippets),
        render_interactive_examples(&section.examples, examples)
    )
}

fn render_code_snippets(snippets: &[CodeSnippet]) -> String {
    if snippets.is_empty() {
        return String::new();
    }
    
    let mut html = String::from(r#"<section class="code-examples">
        <h2>Code Examples</h2>"#);
    
    for (i, snippet) in snippets.iter().enumerate() {
        html.push_str(&format!(r#"
        <div class="code-example" data-index="{}">
            {}
            <pre><code class="language-{}">{}</code></pre>
            {}
        </div>"#,
            i,
            snippet.description.as_ref().map_or(String::new(), |desc| format!(r#"<p class="code-description">{}</p>"#, desc)),
            snippet.language,
            html_escape(&snippet.code),
            if snippet.executable {
                r#"<button class="run-code-btn" onclick="runCodeSnippet(this)">Run Code</button>"#
            } else {
                ""
            }
        ));
    }
    
    html.push_str("</section>");
    html
}

fn render_interactive_examples(example_ids: &[String], examples: &HashMap<String, InteractiveExample>) -> String {
    if example_ids.is_empty() {
        return String::new();
    }
    
    let mut html = String::from(r#"<section class="interactive-examples">
        <h2>Interactive Examples</h2>
        <div class="examples-grid">"#);
    
    for example_id in example_ids {
        if let Some(example) = examples.get(example_id) {
            html.push_str(&format!(r#"
            <div class="example-card" data-example-id="{}">
                <h3>{}</h3>
                <p>{}</p>
                <div class="example-meta">
                    <span class="difficulty difficulty-{}">{:?}</span>
                    <span class="tags">{}</span>
                </div>
                <button class="run-example-btn" onclick="runInteractiveExample('{}')">
                    Try It Out
                </button>
                <div class="example-result" style="display: none;"></div>
            </div>"#,
                example.id,
                example.title,
                truncate_text(&example.description, 120),
                format!("{:?}", example.difficulty).to_lowercase(),
                example.difficulty,
                example.tags.join(", "),
                example.id
            ));
        }
    }
    
    html.push_str("</div></section>");
    html
}

// Utility functions
fn find_section(sections: &[DocumentationSection], id: &str) -> Option<&DocumentationSection> {
    for section in sections {
        if section.id == id {
            return Some(section);
        }
        if let Some(found) = find_section(&section.subsections, id) {
            return Some(found);
        }
    }
    None
}

fn search_sections_recursive(
    sections: &[DocumentationSection],
    query: &str,
    results: &mut Vec<SearchResultItem>,
) {
    for section in sections {
        let relevance = calculate_section_relevance(section, query);
        if relevance > 0.0 {
            results.push(SearchResultItem {
                id: section.id.clone(),
                title: section.title.clone(),
                excerpt: truncate_text(&section.content, 150),
                relevance,
                item_type: "section".to_string(),
            });
        }
        search_sections_recursive(&section.subsections, query, results);
    }
}

fn calculate_section_relevance(section: &DocumentationSection, query: &str) -> f32 {
    let title_matches = section.title.to_lowercase().matches(query).count() as f32 * 3.0;
    let content_matches = section.content.to_lowercase().matches(query).count() as f32;
    
    title_matches + content_matches
}

fn calculate_example_relevance(example: &InteractiveExample, query: &str) -> f32 {
    let title_matches = example.title.to_lowercase().matches(query).count() as f32 * 3.0;
    let description_matches = example.description.to_lowercase().matches(query).count() as f32 * 2.0;
    let code_matches = example.code.to_lowercase().matches(query).count() as f32;
    let tag_matches = example.tags.iter()
        .map(|tag| tag.to_lowercase().matches(query).count() as f32)
        .sum::<f32>() * 2.0;
    
    title_matches + description_matches + code_matches + tag_matches
}

fn truncate_text(text: &str, max_length: usize) -> String {
    if text.len() <= max_length {
        text.to_string()
    } else {
        format!("{}...", &text[..max_length.min(text.len())])
    }
}

fn markdown_to_html(markdown: &str) -> String {
    // TODO: Implement markdown to HTML conversion
    // For now, just return the markdown wrapped in <pre>
    format!("<pre>{}</pre>", html_escape(markdown))
}

fn html_escape(text: &str) -> String {
    text.replace('&', "&amp;")
        .replace('<', "&lt;")
        .replace('>', "&gt;")
        .replace('"', "&quot;")
        .replace('\'', "&#39;")
}

// Create the documentation router
pub fn create_docs_router(state: AppState) -> Router {
    Router::new()
        .route("/", get(|| async { Html(include_str!("../templates/index.html")) }))
        .route("/docs/:section_id", get(serve_documentation))
        .route("/api/examples/:example_id/run", get(run_interactive_example))
        .route("/api/search", get(search_documentation))
        .with_state(state)
}
```

#### **Week 6: Community Contribution System**
```rust
// community/src/lib.rs - Community contribution and feedback system

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use uuid::Uuid;

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CommunityContribution {
    pub id: Uuid,
    pub author: ContributionAuthor,
    pub contribution_type: ContributionType,
    pub title: String,
    pub description: String,
    pub content: ContributionContent,
    pub tags: Vec<String>,
    pub status: ContributionStatus,
    pub votes: VoteCount,
    pub reviews: Vec<CommunityReview>,
    pub created_at: chrono::DateTime<chrono::Utc>,
    pub updated_at: chrono::DateTime<chrono::Utc>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ContributionAuthor {
    pub username: String,
    pub display_name: String,
    pub email: Option<String>,
    pub github_handle: Option<String>,
    pub reputation: u32,
    pub contribution_count: u32,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum ContributionType {
    Documentation,
    Example,
    Tutorial,
    Pattern,
    Integration,
    BestPractice,
    Translation,
    BugReport,
    FeatureRequest,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum ContributionContent {
    Markdown { content: String },
    Code { language: String, code: String, description: String },
    Example { code: String, setup_files: Vec<(String, String)>, explanation: String },
    Integration { framework: String, guide: String, code_samples: Vec<CodeSample> },
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CodeSample {
    pub filename: String,
    pub language: String,
    pub code: String,
    pub description: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum ContributionStatus {
    Draft,
    Submitted,
    UnderReview,
    Approved,
    Published,
    NeedsRevision,
    Rejected,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct VoteCount {
    pub upvotes: u32,
    pub downvotes: u32,
}

impl VoteCount {
    pub fn score(&self) -> i32 {
        self.upvotes as i32 - self.downvotes as i32
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CommunityReview {
    pub id: Uuid,
    pub reviewer: String,
    pub rating: ReviewRating,
    pub feedback: String,
    pub suggestions: Vec<ReviewSuggestion>,
    pub created_at: chrono::DateTime<chrono::Utc>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum ReviewRating {
    Excellent,
    Good,
    NeedsImprovement,
    Poor,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ReviewSuggestion {
    pub suggestion_type: SuggestionType,
    pub description: String,
    pub code_change: Option<CodeChange>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum SuggestionType {
    CodeImprovement,
    ClarificationNeeded,
    AddExample,
    FixTypo,
    UpdateDocumentation,
    SecurityConcern,
    PerformanceIssue,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CodeChange {
    pub file_path: String,
    pub original: String,
    pub suggested: String,
    pub reason: String,
}

pub struct CommunityManager {
    contributions: HashMap<Uuid, CommunityContribution>,
    authors: HashMap<String, ContributionAuthor>,
    workspace: workspace_tools::Workspace,
}

impl CommunityManager {
    pub fn new(workspace: workspace_tools::Workspace) -> Self {
        Self {
            contributions: HashMap::new(),
            authors: HashMap::new(),
            workspace,
        }
    }
    
    pub fn load_from_workspace(&mut self) -> Result<(), CommunityError> {
        let community_dir = self.workspace.join("community");
        
        if !community_dir.exists() {
            std::fs::create_dir_all(&community_dir)
                .map_err(|e| CommunityError::IoError(e.to_string()))?;
            return Ok(());
        }
        
        // Load contributions
        let contributions_dir = community_dir.join("contributions");
        if contributions_dir.exists() {
            for entry in std::fs::read_dir(&contributions_dir)
                .map_err(|e| CommunityError::IoError(e.to_string()))? {
                
                let entry = entry.map_err(|e| CommunityError::IoError(e.to_string()))?;
                if entry.path().extension().map_or(false, |ext| ext == "json") {
                    let contribution = self.load_contribution(&entry.path())?;
                    self.contributions.insert(contribution.id, contribution);
                }
            }
        }
        
        // Load authors
        let authors_file = community_dir.join("authors.json");
        if authors_file.exists() {
            let content = std::fs::read_to_string(&authors_file)
                .map_err(|e| CommunityError::IoError(e.to_string()))?;
            self.authors = serde_json::from_str(&content)
                .map_err(|e| CommunityError::ParseError(e.to_string()))?;
        }
        
        Ok(())
    }
    
    pub fn submit_contribution(&mut self, mut contribution: CommunityContribution) -> Result<Uuid, CommunityError> {
        // Assign ID and set timestamps
        contribution.id = Uuid::new_v4();
        contribution.created_at = chrono::Utc::now();
        contribution.updated_at = contribution.created_at;
        contribution.status = ContributionStatus::Submitted;
        
        // Update author statistics
        if let Some(author) = self.authors.get_mut(&contribution.author.username) {
            author.contribution_count += 1;
        } else {
            self.authors.insert(contribution.author.username.clone(), contribution.author.clone());
        }
        
        // Save to workspace
        self.save_contribution(&contribution)?;
        
        let id = contribution.id;
        self.contributions.insert(id, contribution);
        
        Ok(id)
    }
    
    pub fn add_review(&mut self, contribution_id: Uuid, review: CommunityReview) -> Result<(), CommunityError> {
        let contribution = self.contributions.get_mut(&contribution_id)
            .ok_or(CommunityError::ContributionNotFound(contribution_id))?;
        
        contribution.reviews.push(review);
        contribution.updated_at = chrono::Utc::now();
        
        // Update status based on reviews
        self.update_contribution_status(contribution_id)?;
        
        // Save updated contribution
        self.save_contribution(contribution)?;
        
        Ok(())
    }
    
    pub fn vote_on_contribution(&mut self, contribution_id: Uuid, is_upvote: bool) -> Result<(), CommunityError> {
        let contribution = self.contributions.get_mut(&contribution_id)
            .ok_or(CommunityError::ContributionNotFound(contribution_id))?;
        
        if is_upvote {
            contribution.votes.upvotes += 1;
        } else {
            contribution.votes.downvotes += 1;
        }
        
        contribution.updated_at = chrono::Utc::now();
        
        // Update author reputation
        if let Some(author) = self.authors.get_mut(&contribution.author.username) {
            if is_upvote {
                author.reputation += 5;
            } else if author.reputation >= 2 {
                author.reputation -= 2;
            }
        }
        
        self.save_contribution(contribution)?;
        
        Ok(())
    }
    
    pub fn get_contributions_by_type(&self, contribution_type: &ContributionType) -> Vec<&CommunityContribution> {
        self.contributions.values()
            .filter(|c| std::mem::discriminant(&c.contribution_type) == std::mem::discriminant(contribution_type))
            .collect()
    }
    
    pub fn get_top_contributors(&self, limit: usize) -> Vec<&ContributionAuthor> {
        let mut authors: Vec<_> = self.authors.values().collect();
        authors.sort_by(|a, b| b.reputation.cmp(&a.reputation));
        authors.into_iter().take(limit).collect()
    }
    
    pub fn generate_community_report(&self) -> CommunityReport {
        let total_contributions = self.contributions.len();
        let total_authors = self.authors.len();
        
        let mut contributions_by_type = HashMap::new();
        let mut contributions_by_status = HashMap::new();
        
        for contribution in self.contributions.values() {
            let type_count = contributions_by_type.entry(contribution.contribution_type.clone()).or_insert(0);
            *type_count += 1;
            
            let status_count = contributions_by_status.entry(contribution.status.clone()).or_insert(0);
            *status_count += 1;
        }
        
        let top_contributors = self.get_top_contributors(10)
            .into_iter()
            .map(|author| TopContributor {
                username: author.username.clone(),
                display_name: author.display_name.clone(),
                reputation: author.reputation,
                contribution_count: author.contribution_count,
            })
            .collect();
        
        let recent_contributions = {
            let mut recent: Vec<_> = self.contributions.values()
                .filter(|c| matches!(c.status, ContributionStatus::Published))
                .collect();
            recent.sort_by(|a, b| b.created_at.cmp(&a.created_at));
            recent.into_iter()
                .take(20)
                .map(|c| RecentContribution {
                    id: c.id,
                    title: c.title.clone(),
                    author: c.author.display_name.clone(),
                    contribution_type: c.contribution_type.clone(),
                    created_at: c.created_at,
                    votes: c.votes.clone(),
                })
                .collect()
        };
        
        CommunityReport {
            total_contributions,
            total_authors,
            contributions_by_type,
            contributions_by_status,
            top_contributors,
            recent_contributions,
            generated_at: chrono::Utc::now(),
        }
    }
    
    fn load_contribution(&self, path: &std::path::Path) -> Result<CommunityContribution, CommunityError> {
        let content = std::fs::read_to_string(path)
            .map_err(|e| CommunityError::IoError(e.to_string()))?;
        
        serde_json::from_str(&content)
            .map_err(|e| CommunityError::ParseError(e.to_string()))
    }
    
    fn save_contribution(&self, contribution: &CommunityContribution) -> Result<(), CommunityError> {
        let contributions_dir = self.workspace.join("community/contributions");
        std::fs::create_dir_all(&contributions_dir)
            .map_err(|e| CommunityError::IoError(e.to_string()))?;
        
        let filename = format!("{}.json", contribution.id);
        let file_path = contributions_dir.join(filename);
        
        let content = serde_json::to_string_pretty(contribution)
            .map_err(|e| CommunityError::ParseError(e.to_string()))?;
        
        std::fs::write(&file_path, content)
            .map_err(|e| CommunityError::IoError(e.to_string()))?;
        
        Ok(())
    }
    
    fn update_contribution_status(&mut self, contribution_id: Uuid) -> Result<(), CommunityError> {
        let contribution = self.contributions.get_mut(&contribution_id)
            .ok_or(CommunityError::ContributionNotFound(contribution_id))?;
        
        if contribution.reviews.len() >= 3 {
            let excellent_count = contribution.reviews.iter()
                .filter(|r| matches!(r.rating, ReviewRating::Excellent))
                .count();
            let good_count = contribution.reviews.iter()
                .filter(|r| matches!(r.rating, ReviewRating::Good))
                .count();
            let poor_count = contribution.reviews.iter()
                .filter(|r| matches!(r.rating, ReviewRating::Poor))
                .count();
            
            contribution.status = if excellent_count >= 2 || (excellent_count + good_count) >= 3 {
                ContributionStatus::Approved
            } else if poor_count >= 2 {
                ContributionStatus::NeedsRevision
            } else {
                ContributionStatus::UnderReview
            };
        }
        
        Ok(())
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct CommunityReport {
    pub total_contributions: usize,
    pub total_authors: usize,
    pub contributions_by_type: HashMap<ContributionType, u32>,
    pub contributions_by_status: HashMap<ContributionStatus, u32>,
    pub top_contributors: Vec<TopContributor>,
    pub recent_contributions: Vec<RecentContribution>,
    pub generated_at: chrono::DateTime<chrono::Utc>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct TopContributor {
    pub username: String,
    pub display_name: String,
    pub reputation: u32,
    pub contribution_count: u32,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct RecentContribution {
    pub id: Uuid,
    pub title: String,
    pub author: String,
    pub contribution_type: ContributionType,
    pub created_at: chrono::DateTime<chrono::Utc>,
    pub votes: VoteCount,
}

#[derive(Debug)]
pub enum CommunityError {
    IoError(String),
    ParseError(String),
    ContributionNotFound(Uuid),
    InvalidContribution(String),
}

impl std::fmt::Display for CommunityError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            CommunityError::IoError(msg) => write!(f, "IO error: {}", msg),
            CommunityError::ParseError(msg) => write!(f, "Parse error: {}", msg),
            CommunityError::ContributionNotFound(id) => write!(f, "Contribution not found: {}", id),
            CommunityError::InvalidContribution(msg) => write!(f, "Invalid contribution: {}", msg),
        }
    }
}

impl std::error::Error for CommunityError {}
```

## **Success Criteria**
- [ ] Comprehensive documentation covering all features and use cases
- [ ] Interactive examples that run successfully in documentation
- [ ] Multi-language support for global adoption
- [ ] Community contribution system with review process
- [ ] Search functionality across all documentation
- [ ] Mobile-responsive documentation website
- [ ] Integration with popular learning platforms
- [ ] Video content and tutorials
- [ ] Documentation analytics showing user engagement
- [ ] Regular content updates and maintenance workflow

## **Metrics to Track**
- Documentation page views and time spent
- Interactive example execution count and success rate
- Community contribution submission and approval rates
- Search query analysis and content gaps
- User feedback and satisfaction scores
- Integration guide usage and framework adoption

## **Future Enhancements**
- AI-powered documentation assistance and Q&A
- Real-time collaborative editing for community contributions
- Automated documentation generation from code
- Interactive tutorials with guided exercises
- Integration with popular code editors for inline help
- Multilingual documentation with community translations

This comprehensive documentation ecosystem transforms workspace_tools from a technical library into an accessible, community-driven standard that educates and empowers the entire Rust ecosystem.

<function_calls>
<invoke name="TodoWrite">
<parameter name="todos">[{"id": "t1", "content": "Create task 011_ide_integration.md", "status": "completed"}, {"id": "t2", "content": "Create task 012_cargo_team_integration.md", "status": "completed"}, {"id": "t3", "content": "Create task 013_workspace_scaffolding.md (enhanced template system)", "status": "completed"}, {"id": "t4", "content": "Create task 014_performance_optimization.md", "status": "completed"}, {"id": "t5", "content": "Create task 015_documentation_ecosystem.md", "status": "completed"}, {"id": "t6", "content": "Create task 016_community_building.md", "status": "in_progress"}]