ggen-core 26.6.25

Core graph-aware code generation engine
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
//! Production Readiness Tracking System (80/20 Rule Implementation)
//!
//! This module implements a comprehensive production readiness tracking system
//! that follows the 80/20 rule - focusing on the 20% of features that provide
//! 80% of production value.
//!
//! # Core Philosophy
//!
//! Production readiness is not about implementing 100% of features. It's about:
//! - **Security**: Core authentication, authorization, input validation
//! - **Reliability**: Error handling, logging, monitoring
//! - **Observability**: Metrics, tracing, health checks
//! - **Performance**: Basic optimization, resource management
//! - **Deployability**: Containerization, configuration management
//!
//! # 80/20 Rule Categories
//!
//! ## Critical (20% effort, 80% value)
//! - Authentication & authorization
//! - Error handling & logging
//! - Health checks & monitoring
//! - Basic security (input validation, CSRF)
//! - Database migrations & backups
//!
//! ## Important (30% effort, 15% value)
//! - API documentation
//! - Testing (unit, integration)
//! - Performance monitoring
//! - Configuration management
//! - Deployment automation
//!
//! ## Nice-to-have (50% effort, 5% value)
//! - Advanced caching
//! - Rate limiting
//! - Circuit breakers
//! - Advanced security features
//! - Complex monitoring dashboards

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::path::Path;
use thiserror::Error;

/// Production readiness status for a component
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ReadinessStatus {
    /// Component is complete and production-ready
    Complete,
    /// Component has placeholder implementation
    Placeholder,
    /// Component is missing entirely
    Missing,
    /// Component exists but needs review
    NeedsReview,
}

/// Production readiness category following 80/20 rule
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum ReadinessCategory {
    /// Critical features (20% effort, 80% value)
    Critical,
    /// Important features (30% effort, 15% value)
    Important,
    /// Nice-to-have features (50% effort, 5% value)
    NiceToHave,
}

impl std::fmt::Display for ReadinessCategory {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ReadinessCategory::Critical => write!(f, "Critical"),
            ReadinessCategory::Important => write!(f, "Important"),
            ReadinessCategory::NiceToHave => write!(f, "Nice-to-Have"),
        }
    }
}

/// Production readiness requirement
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReadinessRequirement {
    /// Unique identifier for this requirement
    pub id: String,
    /// Human-readable name
    pub name: String,
    /// Detailed description
    pub description: String,
    /// Category following 80/20 rule
    pub category: ReadinessCategory,
    /// Current implementation status
    pub status: ReadinessStatus,
    /// Files or components this requirement affects
    pub components: Vec<String>,
    /// Dependencies on other requirements
    pub dependencies: Vec<String>,
    /// Estimated effort in hours
    pub effort_hours: Option<u32>,
    /// Priority score (1-10, higher = more critical)
    pub priority: u8,
    /// Date when this requirement was last assessed
    pub last_assessed: DateTime<Utc>,
    /// Notes about implementation status
    pub notes: Option<String>,
}

/// Production readiness report for a project
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReadinessReport {
    /// Project name
    pub project_name: String,
    /// Generation timestamp
    pub generated_at: DateTime<Utc>,
    /// Overall readiness score (0-100)
    pub overall_score: f64,
    /// Requirements by category
    pub by_category: BTreeMap<ReadinessCategory, CategoryReport>,
    /// All requirements
    pub requirements: Vec<ReadinessRequirement>,
    /// Critical path requirements that block production
    pub blocking_requirements: Vec<String>,
    /// Next steps for production readiness
    pub next_steps: Vec<String>,
}

/// Report for a specific readiness category
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CategoryReport {
    /// Category type
    pub category: ReadinessCategory,
    /// Number of requirements in this category
    pub total_requirements: usize,
    /// Number of completed requirements
    pub completed: usize,
    /// Number with placeholder implementations
    pub placeholders: usize,
    /// Number missing entirely
    pub missing: usize,
    /// Category score (0-100)
    pub score: f64,
    /// Requirements in this category
    pub requirements: Vec<String>,
}

/// Error types for production readiness operations
#[derive(Error, Debug)]
pub enum ProductionError {
    #[error("Failed to load readiness configuration: {0}")]
    ConfigLoad(#[from] std::io::Error),

    #[error("Failed to parse readiness configuration: {0}")]
    ConfigParse(#[from] toml::de::Error),

    #[error("Failed to serialize readiness configuration: {0}")]
    ConfigSerialize(#[from] toml::ser::Error),

    #[error("Requirement not found: {0}")]
    RequirementNotFound(String),

    #[error("Circular dependency detected in requirements")]
    CircularDependency,

    #[error("Invalid requirement status transition")]
    InvalidTransition,

    #[error("Project analysis failed: {0}")]
    AnalysisFailed(String),
}

/// Result type for production readiness operations
pub type Result<T> = std::result::Result<T, ProductionError>;

/// Production readiness tracker
pub struct ReadinessTracker {
    /// Project root directory
    project_root: std::path::PathBuf,
    /// Current requirements
    requirements: Vec<ReadinessRequirement>,
    /// Configuration file path
    config_path: std::path::PathBuf,
}

impl ReadinessTracker {
    /// Create a new readiness tracker for a project
    pub fn new<P: AsRef<Path>>(project_root: P) -> Self {
        let project_root = project_root.as_ref().to_path_buf();
        let config_path = project_root.join(".ggen").join("production.toml");

        Self {
            project_root,
            requirements: Vec::new(),
            config_path,
        }
    }

    /// Load production readiness configuration
    pub fn load(&mut self) -> Result<()> {
        if self.config_path.exists() {
            let content = std::fs::read_to_string(&self.config_path)?;
            let config: ProductionConfig = toml::from_str(&content)?;
            self.requirements = config.requirements;
        } else {
            // Initialize with default requirements
            self.requirements = Self::default_requirements();
        }
        Ok(())
    }

    /// Save current requirements to configuration
    pub fn save(&self) -> Result<()> {
        let config = ProductionConfig {
            requirements: self.requirements.clone(),
        };

        // Ensure .ggen directory exists
        let parent_dir = self.config_path.parent().ok_or_else(|| {
            ProductionError::ConfigLoad(std::io::Error::new(
                std::io::ErrorKind::InvalidInput,
                format!(
                    "Config path has no parent directory: {}",
                    self.config_path.display()
                ),
            ))
        })?;
        std::fs::create_dir_all(parent_dir)?;

        let content = toml::to_string_pretty(&config)?;
        std::fs::write(&self.config_path, content)?;
        Ok(())
    }

    /// Generate a comprehensive readiness report
    pub fn generate_report(&self) -> ReadinessReport {
        let mut by_category = BTreeMap::new();
        let mut blocking_requirements = Vec::new();
        let mut next_steps = Vec::new();

        // Group requirements by category
        for req in &self.requirements {
            let category = req.category.clone();
            let entry = by_category
                .entry(category)
                .or_insert_with(|| CategoryReport {
                    category: req.category.clone(),
                    total_requirements: 0,
                    completed: 0,
                    placeholders: 0,
                    missing: 0,
                    score: 0.0,
                    requirements: Vec::new(),
                });

            entry.total_requirements += 1;
            entry.requirements.push(req.id.clone());

            match req.status {
                ReadinessStatus::Complete => entry.completed += 1,
                ReadinessStatus::Placeholder => entry.placeholders += 1,
                ReadinessStatus::Missing => entry.missing += 1,
                ReadinessStatus::NeedsReview => {
                    // Treat as incomplete for scoring
                    if req.category == ReadinessCategory::Critical {
                        blocking_requirements.push(req.id.clone());
                    }
                }
            }
        }

        // Calculate scores for each category
        for report in by_category.values_mut() {
            let total = report.total_requirements as f64;
            if total > 0.0 {
                let completed_ratio = report.completed as f64 / total;
                let placeholder_ratio = report.placeholders as f64 / total;

                // Weight: Complete = 1.0, Placeholder = 0.5, Missing/Review = 0.0
                report.score = placeholder_ratio.mul_add(0.5, completed_ratio) * 100.0;
            }
        }

        // Calculate overall score (weighted by category importance)
        let critical_score = by_category
            .get(&ReadinessCategory::Critical)
            .map(|r| r.score)
            .unwrap_or(0.0)
            * 0.8; // 80% weight
        let important_score = by_category
            .get(&ReadinessCategory::Important)
            .map(|r| r.score)
            .unwrap_or(0.0)
            * 0.15; // 15% weight
        let nice_score = by_category
            .get(&ReadinessCategory::NiceToHave)
            .map(|r| r.score)
            .unwrap_or(0.0)
            * 0.05; // 5% weight

        let overall_score = critical_score + important_score + nice_score;

        // Generate next steps based on critical missing items
        for req in &self.requirements {
            if req.category == ReadinessCategory::Critical
                && (req.status == ReadinessStatus::Missing
                    || req.status == ReadinessStatus::NeedsReview)
            {
                next_steps.push(format!("Implement {}: {}", req.name, req.description));
            }
        }

        ReadinessReport {
            project_name: crate::lifecycle::model::defaults::DEFAULT_READINESS_PROJECT_NAME
                .to_string(),
            generated_at: Utc::now(),
            overall_score,
            by_category,
            requirements: self.requirements.clone(),
            blocking_requirements,
            next_steps,
        }
    }

    /// Update the status of a requirement
    pub fn update_requirement(
        &mut self, requirement_id: &str, status: ReadinessStatus,
    ) -> Result<()> {
        // Find the requirement first
        let req_index = self
            .requirements
            .iter()
            .position(|r| r.id == requirement_id)
            .ok_or_else(|| ProductionError::RequirementNotFound(requirement_id.to_string()))?;

        // Validate status transition before updating
        let current_status = self.requirements[req_index].status.clone();
        Self::validate_transition_static(&current_status, &status)?;

        // Update the requirement
        self.requirements[req_index].status = status;
        self.requirements[req_index].last_assessed = Utc::now();
        Ok(())
    }

    /// Add a new requirement
    pub fn add_requirement(&mut self, requirement: ReadinessRequirement) -> Result<()> {
        // Check for circular dependencies
        self.validate_dependencies(&requirement)?;

        self.requirements.push(requirement);
        Ok(())
    }

    /// Get requirements by status
    pub fn get_by_status(&self, status: &ReadinessStatus) -> Vec<&ReadinessRequirement> {
        self.requirements
            .iter()
            .filter(|r| &r.status == status)
            .collect()
    }

    /// Get requirements by category
    pub fn get_by_category(&self, category: &ReadinessCategory) -> Vec<&ReadinessRequirement> {
        self.requirements
            .iter()
            .filter(|r| r.category == *category)
            .collect()
    }

    /// Validate status transition
    fn validate_transition_static(from: &ReadinessStatus, to: &ReadinessStatus) -> Result<()> {
        match (from, to) {
            (ReadinessStatus::Missing, ReadinessStatus::Placeholder) => Ok(()),
            (ReadinessStatus::Missing, ReadinessStatus::Complete) => Ok(()),
            (ReadinessStatus::Placeholder, ReadinessStatus::Complete) => Ok(()),
            (ReadinessStatus::Placeholder, ReadinessStatus::NeedsReview) => Ok(()),
            (ReadinessStatus::Complete, ReadinessStatus::NeedsReview) => Ok(()),
            _ => Err(ProductionError::InvalidTransition),
        }
    }

    /// Validate dependency graph for cycles
    fn validate_dependencies(&self, requirement: &ReadinessRequirement) -> Result<()> {
        let mut visited = std::collections::HashSet::new();
        let mut path = Vec::new();

        for dep_id in &requirement.dependencies {
            if self.has_cycle(dep_id, &mut visited, &mut path) {
                return Err(ProductionError::CircularDependency);
            }
        }
        Ok(())
    }

    /// Check for cycles in dependency graph
    fn has_cycle(
        &self, req_id: &str, visited: &mut std::collections::HashSet<String>,
        path: &mut Vec<String>,
    ) -> bool {
        if path.contains(&req_id.to_string()) {
            return true; // Cycle detected
        }

        if visited.contains(req_id) {
            return false; // Already processed
        }

        let req = match self.requirements.iter().find(|r| r.id == req_id) {
            Some(r) => r,
            None => return false,
        };

        visited.insert(req_id.to_string());
        path.push(req_id.to_string());

        for dep_id in &req.dependencies {
            if self.has_cycle(dep_id, visited, path) {
                return true;
            }
        }

        path.pop();
        false
    }

    /// Get default production requirements following 80/20 rule
    fn default_requirements() -> Vec<ReadinessRequirement> {
        vec![
            // Critical (20% effort, 80% value)
            ReadinessRequirement {
                id: "auth-basic".to_string(),
                name: "Basic Authentication".to_string(),
                description: "User authentication system with login/logout".to_string(),
                category: ReadinessCategory::Critical,
                status: ReadinessStatus::Missing,
                components: vec!["src/auth.rs".to_string(), "templates/auth.tmpl".to_string()],
                dependencies: vec![],
                effort_hours: Some(8),
                priority: 10,
                last_assessed: Utc::now(),
                notes: Some("Core authentication is essential for production".to_string()),
            },
            ReadinessRequirement {
                id: "error-handling".to_string(),
                name: "Comprehensive Error Handling".to_string(),
                description:
                    "Proper error handling with thiserror, no unwrap/expect in production code"
                        .to_string(),
                category: ReadinessCategory::Critical,
                status: ReadinessStatus::Missing,
                components: vec![
                    "src/error.rs".to_string(),
                    "templates/error-handling.tmpl".to_string(),
                ],
                dependencies: vec![],
                effort_hours: Some(12),
                priority: 10,
                last_assessed: Utc::now(),
                notes: Some("Production code must handle errors gracefully".to_string()),
            },
            ReadinessRequirement {
                id: "logging-tracing".to_string(),
                name: "Structured Logging & Tracing".to_string(),
                description: "Comprehensive logging with tracing crate and structured output"
                    .to_string(),
                category: ReadinessCategory::Critical,
                status: ReadinessStatus::Missing,
                components: vec![
                    "src/logging.rs".to_string(),
                    "config/tracing.toml".to_string(),
                ],
                dependencies: vec![],
                effort_hours: Some(6),
                priority: 9,
                last_assessed: Utc::now(),
                notes: Some("Essential for debugging and monitoring in production".to_string()),
            },
            ReadinessRequirement {
                id: "health-checks".to_string(),
                name: "Health Check Endpoints".to_string(),
                description: "HTTP health check endpoints for load balancer and monitoring"
                    .to_string(),
                category: ReadinessCategory::Critical,
                status: ReadinessStatus::Missing,
                components: vec![
                    "src/health.rs".to_string(),
                    "templates/health.tmpl".to_string(),
                ],
                dependencies: vec![],
                effort_hours: Some(4),
                priority: 8,
                last_assessed: Utc::now(),
                notes: Some("Required for container orchestration and monitoring".to_string()),
            },
            ReadinessRequirement {
                id: "input-validation".to_string(),
                name: "Input Validation & Sanitization".to_string(),
                description:
                    "Comprehensive input validation and sanitization to prevent injection attacks"
                        .to_string(),
                category: ReadinessCategory::Critical,
                status: ReadinessStatus::Missing,
                components: vec![
                    "src/validation.rs".to_string(),
                    "templates/validation.tmpl".to_string(),
                ],
                dependencies: vec!["auth-basic".to_string()],
                effort_hours: Some(10),
                priority: 9,
                last_assessed: Utc::now(),
                notes: Some("Critical for security and data integrity".to_string()),
            },
            ReadinessRequirement {
                id: "database-migrations".to_string(),
                name: "Database Schema Migrations".to_string(),
                description: "Automated database schema migrations with rollback capability"
                    .to_string(),
                category: ReadinessCategory::Critical,
                status: ReadinessStatus::Missing,
                components: vec!["migrations/".to_string(), "src/database.rs".to_string()],
                dependencies: vec![],
                effort_hours: Some(8),
                priority: 8,
                last_assessed: Utc::now(),
                notes: Some("Essential for zero-downtime deployments".to_string()),
            },
            // Important (30% effort, 15% value)
            ReadinessRequirement {
                id: "api-documentation".to_string(),
                name: "OpenAPI Documentation".to_string(),
                description: "Complete OpenAPI/Swagger documentation for all endpoints".to_string(),
                category: ReadinessCategory::Important,
                status: ReadinessStatus::Missing,
                components: vec!["docs/api.md".to_string(), "openapi.yaml".to_string()],
                dependencies: vec![],
                effort_hours: Some(12),
                priority: 7,
                last_assessed: Utc::now(),
                notes: Some("Important for API consumers and automated testing".to_string()),
            },
            ReadinessRequirement {
                id: "unit-tests".to_string(),
                name: "Comprehensive Unit Tests".to_string(),
                description: "Unit tests for all public functions with >80% coverage".to_string(),
                category: ReadinessCategory::Important,
                status: ReadinessStatus::Missing,
                components: vec!["tests/unit/".to_string()],
                dependencies: vec![],
                effort_hours: Some(20),
                priority: 7,
                last_assessed: Utc::now(),
                notes: Some("Essential for code quality and refactoring confidence".to_string()),
            },
            ReadinessRequirement {
                id: "integration-tests".to_string(),
                name: "Integration Tests".to_string(),
                description: "Integration tests for component interactions".to_string(),
                category: ReadinessCategory::Important,
                status: ReadinessStatus::Missing,
                components: vec!["tests/integration/".to_string()],
                dependencies: vec!["unit-tests".to_string()],
                effort_hours: Some(16),
                priority: 6,
                last_assessed: Utc::now(),
                notes: Some("Validates component interactions work correctly".to_string()),
            },
            ReadinessRequirement {
                id: "performance-monitoring".to_string(),
                name: "Performance Monitoring".to_string(),
                description: "Basic performance metrics collection and alerting".to_string(),
                category: ReadinessCategory::Important,
                status: ReadinessStatus::Missing,
                components: vec![
                    "src/metrics.rs".to_string(),
                    "config/metrics.toml".to_string(),
                ],
                dependencies: vec!["logging-tracing".to_string()],
                effort_hours: Some(8),
                priority: 6,
                last_assessed: Utc::now(),
                notes: Some("Essential for production performance management".to_string()),
            },
            ReadinessRequirement {
                id: "docker-containerization".to_string(),
                name: "Docker Containerization".to_string(),
                description: "Production-ready Docker containers with multi-stage builds"
                    .to_string(),
                category: ReadinessCategory::Important,
                status: ReadinessStatus::Missing,
                components: vec!["Dockerfile".to_string(), "docker-compose.yml".to_string()],
                dependencies: vec!["health-checks".to_string()],
                effort_hours: Some(6),
                priority: 7,
                last_assessed: Utc::now(),
                notes: Some("Required for consistent deployment across environments".to_string()),
            },
            ReadinessRequirement {
                id: "configuration-management".to_string(),
                name: "Configuration Management".to_string(),
                description: "Environment-based configuration with validation".to_string(),
                category: ReadinessCategory::Important,
                status: ReadinessStatus::Missing,
                components: vec!["config/".to_string(), "src/config.rs".to_string()],
                dependencies: vec![],
                effort_hours: Some(8),
                priority: 7,
                last_assessed: Utc::now(),
                notes: Some("Essential for multi-environment deployments".to_string()),
            },
            // Nice-to-have (50% effort, 5% value)
            ReadinessRequirement {
                id: "rate-limiting".to_string(),
                name: "Rate Limiting".to_string(),
                description: "API rate limiting to prevent abuse".to_string(),
                category: ReadinessCategory::NiceToHave,
                status: ReadinessStatus::Missing,
                components: vec!["src/rate_limit.rs".to_string()],
                dependencies: vec!["auth-basic".to_string()],
                effort_hours: Some(12),
                priority: 4,
                last_assessed: Utc::now(),
                notes: Some("Nice to have for high-traffic applications".to_string()),
            },
            ReadinessRequirement {
                id: "caching-layer".to_string(),
                name: "Advanced Caching".to_string(),
                description: "Redis-based caching with cache invalidation strategies".to_string(),
                category: ReadinessCategory::NiceToHave,
                status: ReadinessStatus::Missing,
                components: vec!["src/cache.rs".to_string(), "config/redis.toml".to_string()],
                dependencies: vec!["performance-monitoring".to_string()],
                effort_hours: Some(16),
                priority: 3,
                last_assessed: Utc::now(),
                notes: Some("Improves performance but adds complexity".to_string()),
            },
            ReadinessRequirement {
                id: "circuit-breaker".to_string(),
                name: "Circuit Breaker Pattern".to_string(),
                description: "Circuit breaker for external service calls".to_string(),
                category: ReadinessCategory::NiceToHave,
                status: ReadinessStatus::Missing,
                components: vec!["src/circuit_breaker.rs".to_string()],
                dependencies: vec!["error-handling".to_string()],
                effort_hours: Some(10),
                priority: 3,
                last_assessed: Utc::now(),
                notes: Some("Improves resilience but adds complexity".to_string()),
            },
            ReadinessRequirement {
                id: "advanced-security".to_string(),
                name: "Advanced Security Features".to_string(),
                description:
                    "Advanced security features like CSRF protection, CORS, security headers"
                        .to_string(),
                category: ReadinessCategory::NiceToHave,
                status: ReadinessStatus::Missing,
                components: vec![
                    "src/security.rs".to_string(),
                    "config/security.toml".to_string(),
                ],
                dependencies: vec!["input-validation".to_string()],
                effort_hours: Some(14),
                priority: 4,
                last_assessed: Utc::now(),
                notes: Some("Additional security hardening for sensitive applications".to_string()),
            },
            ReadinessRequirement {
                id: "monitoring-dashboard".to_string(),
                name: "Monitoring Dashboard".to_string(),
                description: "Grafana/Kibana dashboard for comprehensive monitoring".to_string(),
                category: ReadinessCategory::NiceToHave,
                status: ReadinessStatus::Missing,
                components: vec!["docker/grafana/".to_string(), "docker/kibana/".to_string()],
                dependencies: vec!["performance-monitoring".to_string()],
                effort_hours: Some(20),
                priority: 2,
                last_assessed: Utc::now(),
                notes: Some("Nice for observability but not essential for MVP".to_string()),
            },
        ]
    }
}

/// Production readiness configuration file format
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProductionConfig {
    /// List of all production requirements
    pub requirements: Vec<ReadinessRequirement>,
}

/// Placeholder marker for incomplete implementations
#[derive(Debug, Clone)]
pub struct Placeholder {
    /// Unique identifier for this placeholder
    pub id: String,
    /// What this placeholder represents
    pub description: String,
    /// Category of placeholder
    pub category: ReadinessCategory,
    /// Files/components this affects
    pub affects: Vec<String>,
    /// Implementation guidance
    pub guidance: String,
    /// Priority for implementation
    pub priority: u8,
}

impl Placeholder {
    /// Create a new placeholder marker
    pub fn new(
        id: String, description: String, category: ReadinessCategory, affects: Vec<String>,
        guidance: String, priority: u8,
    ) -> Self {
        Self {
            id,
            description,
            category,
            affects,
            guidance,
            priority,
        }
    }

    /// Generate a placeholder comment for code
    pub fn to_comment(&self) -> String {
        format!(
            r"// 🚧 PLACEHOLDER: {description}
// Category: {category:?}
// Priority: {priority}
// Guidance: {guidance}
// FUTURE: Implement this placeholder for production readiness",
            description = self.description,
            category = self.category,
            priority = self.priority,
            guidance = self.guidance
        )
    }

    /// Generate a placeholder template section
    pub fn to_template_section(&self) -> String {
        format!(
            r"{{{{!-- 🚧 PLACEHOLDER: {description} --}}
{{{{!-- Category: {category:?} --}}
{{{{!-- Priority: {priority} --}}
{{{{!-- Guidance: {guidance} --}}
{{{{!-- FUTURE: Implement this placeholder for production readiness --}}}}",
            description = self.description,
            category = self.category,
            priority = self.priority,
            guidance = self.guidance
        )
    }
}

impl ReadinessTracker {
    /// Analyze project for existing production features
    pub fn analyze_project(&mut self) -> Result<()> {
        // Scan for existing implementations
        self.scan_for_authentication()?;
        self.scan_for_error_handling()?;
        self.scan_for_logging()?;
        self.scan_for_health_checks()?;
        self.scan_for_input_validation()?;
        self.scan_for_database_setup()?;
        self.scan_for_tests()?;
        self.scan_for_documentation()?;
        self.scan_for_docker_setup()?;
        self.scan_for_configuration()?;

        Ok(())
    }

    /// Scan for authentication implementation
    fn scan_for_authentication(&mut self) -> Result<()> {
        let auth_patterns = ["auth", "login", "authentication", "jwt", "session"];
        let has_auth = self.scan_for_patterns(&auth_patterns);

        if has_auth {
            self.update_requirement("auth-basic", ReadinessStatus::Complete)?;
        }
        Ok(())
    }

    /// Scan for error handling implementation
    fn scan_for_error_handling(&mut self) -> Result<()> {
        let error_patterns = ["thiserror", "Result<", "map_err", "anyhow"];
        let has_error_handling = self.scan_for_patterns(&error_patterns);

        if has_error_handling {
            self.update_requirement("error-handling", ReadinessStatus::Complete)?;
        }
        Ok(())
    }

    /// Scan for logging implementation
    fn scan_for_logging(&mut self) -> Result<()> {
        let logging_patterns = ["tracing", "log::", "slog", "println!"];
        let has_logging = self.scan_for_patterns(&logging_patterns);

        if has_logging {
            self.update_requirement("logging-tracing", ReadinessStatus::Complete)?;
        }
        Ok(())
    }

    /// Scan for health check implementation
    fn scan_for_health_checks(&mut self) -> Result<()> {
        let health_patterns = ["health", "/health", "health_check"];
        let has_health = self.scan_for_patterns(&health_patterns);

        if has_health {
            self.update_requirement("health-checks", ReadinessStatus::Complete)?;
        }
        Ok(())
    }

    /// Scan for input validation
    fn scan_for_input_validation(&mut self) -> Result<()> {
        let validation_patterns = ["validate", "validator", "serde", "Deserialize"];
        let has_validation = self.scan_for_patterns(&validation_patterns);

        if has_validation {
            self.update_requirement("input-validation", ReadinessStatus::Complete)?;
        }
        Ok(())
    }

    /// Scan for database setup
    fn scan_for_database_setup(&mut self) -> Result<()> {
        let db_patterns = ["sqlx", "diesel", "sea-orm", "migration", "schema"];
        let has_db = self.scan_for_patterns(&db_patterns);

        if has_db {
            self.update_requirement("database-migrations", ReadinessStatus::Complete)?;
        }
        Ok(())
    }

    /// Scan for test implementation
    fn scan_for_tests(&mut self) -> Result<()> {
        let test_patterns = ["#[test]", "#[cfg(test)]", "tests/"];
        let has_tests = self.scan_for_patterns(&test_patterns);

        if has_tests {
            self.update_requirement("unit-tests", ReadinessStatus::Complete)?;
            self.update_requirement("integration-tests", ReadinessStatus::Complete)?;
        }
        Ok(())
    }

    /// Scan for documentation
    fn scan_for_documentation(&mut self) -> Result<()> {
        let doc_patterns = ["README.md", "docs/", "openapi", "swagger"];
        let has_docs = self.scan_for_patterns(&doc_patterns);

        if has_docs {
            self.update_requirement("api-documentation", ReadinessStatus::Complete)?;
        }
        Ok(())
    }

    /// Scan for Docker setup
    fn scan_for_docker_setup(&mut self) -> Result<()> {
        let docker_patterns = ["Dockerfile", "docker-compose", ".dockerignore"];
        let has_docker = self.scan_for_patterns(&docker_patterns);

        if has_docker {
            self.update_requirement("docker-containerization", ReadinessStatus::Complete)?;
        }
        Ok(())
    }

    /// Scan for configuration management
    fn scan_for_configuration(&mut self) -> Result<()> {
        let config_patterns = ["config.toml", "settings.toml", "app.toml"];
        let has_config = self.scan_for_patterns(&config_patterns);

        if has_config {
            self.update_requirement("configuration-management", ReadinessStatus::Complete)?;
        }
        Ok(())
    }

    /// Scan source files for pattern matches
    fn scan_for_patterns(&self, patterns: &[&str]) -> bool {
        let src_dir = self.project_root.join("src");
        let templates_dir = self.project_root.join("templates");
        let config_dir = self.project_root.join("config");

        let search_dirs = [src_dir, templates_dir, config_dir];

        for dir in &search_dirs {
            if !dir.exists() {
                continue;
            }

            for pattern in patterns {
                if Self::directory_contains_pattern(dir, pattern) {
                    return true;
                }
            }
        }

        false
    }

    /// Check if directory contains files matching pattern
    fn directory_contains_pattern(dir: &std::path::Path, pattern: &str) -> bool {
        if let Ok(entries) = std::fs::read_dir(dir) {
            for entry in entries.flatten() {
                let path = entry.path();
                if path.is_file() {
                    if let Ok(content) = std::fs::read_to_string(&path) {
                        if content.contains(pattern) {
                            return true;
                        }
                    }
                } else if path.is_dir() {
                    // Recursively check subdirectories
                    if Self::directory_contains_pattern(&path, pattern) {
                        return true;
                    }
                }
            }
        }
        false
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_default_requirements() {
        let requirements = ReadinessTracker::default_requirements();

        // Should have requirements in all categories
        let critical = requirements
            .iter()
            .filter(|r| r.category == ReadinessCategory::Critical)
            .count();
        let important = requirements
            .iter()
            .filter(|r| r.category == ReadinessCategory::Important)
            .count();
        let nice = requirements
            .iter()
            .filter(|r| r.category == ReadinessCategory::NiceToHave)
            .count();

        assert!(critical > 0, "Should have critical requirements");
        assert!(important > 0, "Should have important requirements");
        assert!(nice > 0, "Should have nice-to-have requirements");

        // Critical should be highest priority
        for req in &requirements {
            if req.category == ReadinessCategory::Critical {
                assert!(
                    req.priority >= 8,
                    "Critical requirements should have high priority"
                );
            }
        }
    }

    #[test]
    fn test_readiness_report_generation() {
        let mut tracker = ReadinessTracker::new("/tmp/test");
        tracker.load().unwrap(); // Load default requirements
        let report = tracker.generate_report();

        assert_eq!(
            report.project_name,
            crate::lifecycle::model::defaults::DEFAULT_READINESS_PROJECT_NAME
        );
        assert!(report.overall_score >= 0.0 && report.overall_score <= 100.0);
        assert!(
            !report.by_category.is_empty(),
            "by_category should not be empty after loading defaults"
        );
        assert!(
            !report.requirements.is_empty(),
            "requirements should not be empty after loading defaults"
        );
    }

    #[test]
    fn test_status_transitions() {
        let mut tracker = ReadinessTracker::new("/tmp/test");
        tracker.load().unwrap();

        // Valid transitions
        assert!(tracker
            .update_requirement("auth-basic", ReadinessStatus::Placeholder)
            .is_ok());
        assert!(tracker
            .update_requirement("auth-basic", ReadinessStatus::Complete)
            .is_ok());

        // Invalid transition (Complete -> Missing not allowed)
        assert!(tracker
            .update_requirement("auth-basic", ReadinessStatus::Missing)
            .is_err());
    }

    // === CRITICAL 80/20 TESTS: Production Readiness ===

    #[test]
    fn test_readiness_category_ordering() {
        assert!(ReadinessCategory::Critical < ReadinessCategory::Important);
        assert!(ReadinessCategory::Important < ReadinessCategory::NiceToHave);
    }

    #[test]
    fn test_readiness_status_valid_transitions() {
        // Missing -> Placeholder
        assert!(ReadinessTracker::validate_transition_static(
            &ReadinessStatus::Missing,
            &ReadinessStatus::Placeholder
        )
        .is_ok());

        // Missing -> Complete
        assert!(ReadinessTracker::validate_transition_static(
            &ReadinessStatus::Missing,
            &ReadinessStatus::Complete
        )
        .is_ok());

        // Placeholder -> Complete
        assert!(ReadinessTracker::validate_transition_static(
            &ReadinessStatus::Placeholder,
            &ReadinessStatus::Complete
        )
        .is_ok());

        // Placeholder -> NeedsReview
        assert!(ReadinessTracker::validate_transition_static(
            &ReadinessStatus::Placeholder,
            &ReadinessStatus::NeedsReview
        )
        .is_ok());

        // Complete -> NeedsReview
        assert!(ReadinessTracker::validate_transition_static(
            &ReadinessStatus::Complete,
            &ReadinessStatus::NeedsReview
        )
        .is_ok());
    }

    #[test]
    fn test_readiness_status_invalid_transitions() {
        // Complete -> Missing (invalid)
        assert!(ReadinessTracker::validate_transition_static(
            &ReadinessStatus::Complete,
            &ReadinessStatus::Missing
        )
        .is_err());

        // Complete -> Placeholder (invalid)
        assert!(ReadinessTracker::validate_transition_static(
            &ReadinessStatus::Complete,
            &ReadinessStatus::Placeholder
        )
        .is_err());
    }

    #[test]
    fn test_readiness_report_scoring() {
        let mut tracker = ReadinessTracker::new("/tmp/test");
        tracker.load().unwrap();

        let report = tracker.generate_report();

        // Score should be between 0-100
        assert!(report.overall_score >= 0.0 && report.overall_score <= 100.0);

        // Should have all three categories
        assert!(report
            .by_category
            .contains_key(&ReadinessCategory::Critical));
        assert!(report
            .by_category
            .contains_key(&ReadinessCategory::Important));
        assert!(report
            .by_category
            .contains_key(&ReadinessCategory::NiceToHave));
    }

    #[test]
    fn test_category_report_calculation() {
        let mut tracker = ReadinessTracker::new("/tmp/test");
        tracker.load().unwrap();

        // Mark some as complete
        tracker
            .update_requirement("auth-basic", ReadinessStatus::Complete)
            .ok();
        tracker
            .update_requirement("error-handling", ReadinessStatus::Complete)
            .ok();

        let report = tracker.generate_report();
        let critical_report = report
            .by_category
            .get(&ReadinessCategory::Critical)
            .unwrap();

        assert!(critical_report.completed > 0);
        assert!(critical_report.score > 0.0);
    }

    #[test]
    fn test_get_by_status() {
        let mut tracker = ReadinessTracker::new("/tmp/test");
        tracker.load().unwrap();

        let missing = tracker.get_by_status(&ReadinessStatus::Missing);
        assert!(!missing.is_empty());

        tracker
            .update_requirement("auth-basic", ReadinessStatus::Complete)
            .ok();
        let complete = tracker.get_by_status(&ReadinessStatus::Complete);
        assert!(!complete.is_empty());
    }

    #[test]
    fn test_get_by_category() {
        let mut tracker = ReadinessTracker::new("/tmp/test");
        tracker.load().unwrap();

        let critical = tracker.get_by_category(&ReadinessCategory::Critical);
        let important = tracker.get_by_category(&ReadinessCategory::Important);
        let nice = tracker.get_by_category(&ReadinessCategory::NiceToHave);

        assert!(!critical.is_empty());
        assert!(!important.is_empty());
        assert!(!nice.is_empty());
    }

    #[test]
    fn test_requirement_not_found() {
        let mut tracker = ReadinessTracker::new("/tmp/test");
        tracker.load().unwrap();

        let result = tracker.update_requirement("nonexistent", ReadinessStatus::Complete);
        assert!(result.is_err());
    }

    #[test]
    fn test_add_requirement_success() {
        let mut tracker = ReadinessTracker::new("/tmp/test");
        tracker.load().unwrap();

        let req = ReadinessRequirement {
            id: "custom-req".to_string(),
            name: "Custom Requirement".to_string(),
            description: "Test requirement".to_string(),
            category: ReadinessCategory::Critical,
            status: ReadinessStatus::Missing,
            components: vec![],
            dependencies: vec![],
            effort_hours: Some(4),
            priority: 8,
            last_assessed: Utc::now(),
            notes: None,
        };

        assert!(tracker.add_requirement(req).is_ok());
    }

    #[test]
    fn test_dependency_validation() {
        let mut tracker = ReadinessTracker::new("/tmp/test");
        tracker.load().unwrap();

        // Add requirement with non-circular dependency (auth-basic already exists)
        let req = ReadinessRequirement {
            id: "req1".to_string(),
            name: "Req 1".to_string(),
            description: "Test".to_string(),
            category: ReadinessCategory::Critical,
            status: ReadinessStatus::Missing,
            components: vec![],
            dependencies: vec!["auth-basic".to_string()],
            effort_hours: Some(4),
            priority: 8,
            last_assessed: Utc::now(),
            notes: None,
        };

        // Should succeed - no circular dependency
        assert!(tracker.add_requirement(req).is_ok());
    }

    #[test]
    fn test_placeholder_creation() {
        let placeholder = Placeholder::new(
            "test-placeholder".to_string(),
            "Test description".to_string(),
            ReadinessCategory::Critical,
            vec!["file.rs".to_string()],
            "Implement this feature".to_string(),
            9,
        );

        assert_eq!(placeholder.id, "test-placeholder");
        assert_eq!(placeholder.priority, 9);
    }

    #[test]
    fn test_placeholder_to_comment() {
        let placeholder = Placeholder::new(
            "test".to_string(),
            "Test placeholder".to_string(),
            ReadinessCategory::Critical,
            vec![],
            "Implement this".to_string(),
            8,
        );

        let comment = placeholder.to_comment();
        assert!(comment.contains("PLACEHOLDER"));
        assert!(comment.contains("Test placeholder"));
        assert!(comment.contains("Priority: 8"));
    }

    #[test]
    fn test_placeholder_registry() {
        let mut registry = PlaceholderRegistry::new();

        let placeholder = Placeholder::new(
            "test".to_string(),
            "Test".to_string(),
            ReadinessCategory::Critical,
            vec![],
            "Implement".to_string(),
            8,
        );

        registry.register("test".to_string(), placeholder);

        assert!(registry.get("test").is_some());
        assert_eq!(registry.list().len(), 1);
    }

    #[test]
    fn test_placeholder_registry_by_category() {
        let mut registry = PlaceholderRegistry::new();

        let p1 = Placeholder::new(
            "critical".to_string(),
            "Critical".to_string(),
            ReadinessCategory::Critical,
            vec![],
            "Impl".to_string(),
            9,
        );

        let p2 = Placeholder::new(
            "important".to_string(),
            "Important".to_string(),
            ReadinessCategory::Important,
            vec![],
            "Impl".to_string(),
            7,
        );

        registry.register("critical".to_string(), p1);
        registry.register("important".to_string(), p2);

        let critical = registry.get_by_category(&ReadinessCategory::Critical);
        assert_eq!(critical.len(), 1);

        let important = registry.get_by_category(&ReadinessCategory::Important);
        assert_eq!(important.len(), 1);
    }

    #[test]
    fn test_placeholder_processor() {
        let mut processor = PlaceholderProcessor::new();

        let placeholder = Placeholder::new(
            "test".to_string(),
            "Test".to_string(),
            ReadinessCategory::Critical,
            vec![],
            "Impl".to_string(),
            8,
        );

        processor
            .registry_mut()
            .register("test".to_string(), placeholder);

        assert!(processor.process("test").is_ok());
        assert!(processor.process("nonexistent").is_err());
    }
}

/// Placeholder registry for managing placeholder implementations
#[derive(Debug, Clone, Default)]
pub struct PlaceholderRegistry {
    placeholders: std::collections::HashMap<String, Placeholder>,
}

impl PlaceholderRegistry {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn register(&mut self, id: String, placeholder: Placeholder) {
        self.placeholders.insert(id, placeholder);
    }

    pub fn get(&self, id: &str) -> Option<&Placeholder> {
        self.placeholders.get(id)
    }

    pub fn list(&self) -> Vec<&Placeholder> {
        self.placeholders.values().collect()
    }

    pub fn get_by_category(&self, category: &ReadinessCategory) -> Vec<&Placeholder> {
        self.placeholders
            .values()
            .filter(|p| &p.category == category)
            .collect()
    }

    pub fn generate_summary(&self) -> String {
        let mut summary = String::new();
        summary.push_str("Placeholder Summary:\n");

        for (id, placeholder) in &self.placeholders {
            summary.push_str(&format!(
                "  {}: {} ({:?})\n",
                id, placeholder.description, placeholder.category
            ));
        }

        summary
    }
}

/// Placeholder processor for handling placeholder operations
#[derive(Debug, Clone)]
pub struct PlaceholderProcessor {
    registry: PlaceholderRegistry,
}

impl Default for PlaceholderProcessor {
    fn default() -> Self {
        Self::new()
    }
}

impl PlaceholderProcessor {
    pub fn new() -> Self {
        Self {
            registry: PlaceholderRegistry::new(),
        }
    }

    pub fn process(&self, placeholder_id: &str) -> Result<()> {
        if let Some(_placeholder) = self.registry.get(placeholder_id) {
            tracing::info!("Processing placeholder: {}", placeholder_id);
            Ok(())
        } else {
            Err(ProductionError::RequirementNotFound(
                placeholder_id.to_string(),
            ))
        }
    }

    pub fn registry(&self) -> &PlaceholderRegistry {
        &self.registry
    }

    pub fn registry_mut(&mut self) -> &mut PlaceholderRegistry {
        &mut self.registry
    }
}