pmat 2.93.1

PMAT - Zero-config AI context generation and code quality toolkit (CLI, MCP, HTTP)
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
//! Repository Showcase Gallery
//!
//! This module provides a curated collection of example repositories that demonstrate
//! the capabilities of PMAT across different languages, frameworks, and architectural patterns.
//! The showcase serves as both a demo and a reference for users exploring the tool.

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

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ShowcaseRepository {
    pub name: String,
    pub url: String,
    pub description: String,
    pub primary_language: String,
    pub languages: Vec<String>,
    pub frameworks: Vec<String>,
    pub category: RepositoryCategory,
    pub complexity_tier: ComplexityTier,
    pub estimated_analysis_time_seconds: u32,
    pub highlights: Vec<String>,
    pub analysis_preview: Option<AnalysisPreview>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum RepositoryCategory {
    WebFramework,
    SystemsProgramming,
    DataScience,
    CloudNative,
    DeveloperTools,
    GameDevelopment,
    MachineLearning,
    Blockchain,
    Mobile,
    Embedded,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Copy)]
pub enum ComplexityTier {
    Beginner,
    Intermediate,
    Advanced,
    Expert,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnalysisPreview {
    pub estimated_files: u32,
    pub estimated_functions: u32,
    pub estimated_complexity: f64,
    pub key_insights: Vec<String>,
    pub recommended_focus_areas: Vec<String>,
}

pub struct ShowcaseGallery {
    repositories: HashMap<String, ShowcaseRepository>,
    categories: HashMap<RepositoryCategory, Vec<String>>,
}

impl ShowcaseGallery {
    #[must_use] 
    pub fn new() -> Self {
        let mut gallery = Self {
            repositories: HashMap::new(),
            categories: HashMap::new(),
        };
        gallery.initialize_showcase_repositories();
        gallery
    }

    fn initialize_showcase_repositories(&mut self) {
        // Rust - Systems Programming
        self.add_repository(ShowcaseRepository {
            name: "Tokio".to_string(),
            url: "https://github.com/tokio-rs/tokio".to_string(),
            description: "A runtime for writing reliable asynchronous applications with Rust"
                .to_string(),
            primary_language: "rust".to_string(),
            languages: vec!["rust".to_string()],
            frameworks: vec!["Tokio".to_string()],
            category: RepositoryCategory::SystemsProgramming,
            complexity_tier: ComplexityTier::Advanced,
            estimated_analysis_time_seconds: 45,
            highlights: vec![
                "Complex async runtime implementation".to_string(),
                "Extensive use of unsafe Rust".to_string(),
                "High test coverage".to_string(),
                "Advanced concurrency patterns".to_string(),
            ],
            analysis_preview: Some(AnalysisPreview {
                estimated_files: 200,
                estimated_functions: 1500,
                estimated_complexity: 8.5,
                key_insights: vec![
                    "Complex state machines for async operations".to_string(),
                    "Sophisticated memory management".to_string(),
                    "Extensive macro usage for code generation".to_string(),
                ],
                recommended_focus_areas: vec![
                    "Async runtime components".to_string(),
                    "Thread pool implementation".to_string(),
                    "I/O driver abstractions".to_string(),
                ],
            }),
        });

        // Python - Web Framework
        self.add_repository(ShowcaseRepository {
            name: "Django".to_string(),
            url: "https://github.com/django/django".to_string(),
            description: "The Web framework for perfectionists with deadlines".to_string(),
            primary_language: "python".to_string(),
            languages: vec!["python".to_string(), "javascript".to_string()],
            frameworks: vec!["Django".to_string()],
            category: RepositoryCategory::WebFramework,
            complexity_tier: ComplexityTier::Advanced,
            estimated_analysis_time_seconds: 60,
            highlights: vec![
                "Comprehensive web framework".to_string(),
                "ORM with query optimization".to_string(),
                "Extensive middleware system".to_string(),
                "Admin interface auto-generation".to_string(),
            ],
            analysis_preview: Some(AnalysisPreview {
                estimated_files: 800,
                estimated_functions: 5000,
                estimated_complexity: 7.2,
                key_insights: vec![
                    "Layered architecture with clear separation".to_string(),
                    "Heavy use of metaclasses and descriptors".to_string(),
                    "Database abstraction layer complexity".to_string(),
                ],
                recommended_focus_areas: vec![
                    "ORM query generation".to_string(),
                    "Template engine implementation".to_string(),
                    "Middleware pipeline".to_string(),
                ],
            }),
        });

        // JavaScript - Frontend Framework
        self.add_repository(ShowcaseRepository {
            name: "React".to_string(),
            url: "https://github.com/facebook/react".to_string(),
            description: "The library for web and native user interfaces".to_string(),
            primary_language: "javascript".to_string(),
            languages: vec!["javascript".to_string(), "typescript".to_string()],
            frameworks: vec!["React".to_string()],
            category: RepositoryCategory::WebFramework,
            complexity_tier: ComplexityTier::Advanced,
            estimated_analysis_time_seconds: 40,
            highlights: vec![
                "Virtual DOM implementation".to_string(),
                "Fiber reconciliation algorithm".to_string(),
                "Hooks system".to_string(),
                "Concurrent rendering features".to_string(),
            ],
            analysis_preview: Some(AnalysisPreview {
                estimated_files: 300,
                estimated_functions: 2000,
                estimated_complexity: 7.8,
                key_insights: vec![
                    "Complex state reconciliation logic".to_string(),
                    "Sophisticated scheduling algorithms".to_string(),
                    "Memory optimization for component trees".to_string(),
                ],
                recommended_focus_areas: vec![
                    "Fiber reconciler core".to_string(),
                    "Hooks implementation".to_string(),
                    "Scheduling and priority systems".to_string(),
                ],
            }),
        });

        // Go - Cloud Native
        self.add_repository(ShowcaseRepository {
            name: "Kubernetes".to_string(),
            url: "https://github.com/kubernetes/kubernetes".to_string(),
            description: "Production-Grade Container Scheduling and Management".to_string(),
            primary_language: "go".to_string(),
            languages: vec!["go".to_string(), "yaml".to_string(), "shell".to_string()],
            frameworks: vec!["Kubernetes".to_string()],
            category: RepositoryCategory::CloudNative,
            complexity_tier: ComplexityTier::Expert,
            estimated_analysis_time_seconds: 120,
            highlights: vec![
                "Distributed systems architecture".to_string(),
                "Container orchestration".to_string(),
                "API server design".to_string(),
                "Extensive controller patterns".to_string(),
            ],
            analysis_preview: Some(AnalysisPreview {
                estimated_files: 2000,
                estimated_functions: 15000,
                estimated_complexity: 9.2,
                key_insights: vec![
                    "Complex state management across cluster".to_string(),
                    "Sophisticated API machinery".to_string(),
                    "Extensive use of Go interfaces and composition".to_string(),
                ],
                recommended_focus_areas: vec![
                    "API server and etcd integration".to_string(),
                    "Controller and operator patterns".to_string(),
                    "Scheduler implementation".to_string(),
                ],
            }),
        });

        // TypeScript - Developer Tools
        self.add_repository(ShowcaseRepository {
            name: "VS Code".to_string(),
            url: "https://github.com/microsoft/vscode".to_string(),
            description: "Visual Studio Code - Open Source IDE".to_string(),
            primary_language: "typescript".to_string(),
            languages: vec![
                "typescript".to_string(),
                "javascript".to_string(),
                "css".to_string(),
            ],
            frameworks: vec!["Electron".to_string(), "Monaco Editor".to_string()],
            category: RepositoryCategory::DeveloperTools,
            complexity_tier: ComplexityTier::Expert,
            estimated_analysis_time_seconds: 90,
            highlights: vec![
                "Advanced text editor implementation".to_string(),
                "Extension system architecture".to_string(),
                "Language server protocol".to_string(),
                "Cross-platform desktop application".to_string(),
            ],
            analysis_preview: Some(AnalysisPreview {
                estimated_files: 1500,
                estimated_functions: 10000,
                estimated_complexity: 8.9,
                key_insights: vec![
                    "Sophisticated extension host architecture".to_string(),
                    "Complex text buffer and editor implementations".to_string(),
                    "Extensive use of TypeScript advanced features".to_string(),
                ],
                recommended_focus_areas: vec![
                    "Extension host and API design".to_string(),
                    "Monaco editor core".to_string(),
                    "Language service integration".to_string(),
                ],
            }),
        });

        // Rust - Developer Tools (Simple)
        self.add_repository(ShowcaseRepository {
            name: "ripgrep".to_string(),
            url: "https://github.com/BurntSushi/ripgrep".to_string(),
            description: "A line-oriented search tool that recursively searches for patterns"
                .to_string(),
            primary_language: "rust".to_string(),
            languages: vec!["rust".to_string()],
            frameworks: vec!["clap".to_string(), "regex".to_string()],
            category: RepositoryCategory::DeveloperTools,
            complexity_tier: ComplexityTier::Intermediate,
            estimated_analysis_time_seconds: 15,
            highlights: vec![
                "High-performance search algorithms".to_string(),
                "Memory-efficient processing".to_string(),
                "Cross-platform compatibility".to_string(),
                "Rich CLI interface".to_string(),
            ],
            analysis_preview: Some(AnalysisPreview {
                estimated_files: 50,
                estimated_functions: 300,
                estimated_complexity: 5.5,
                key_insights: vec![
                    "Well-structured command-line tool".to_string(),
                    "Efficient file system traversal".to_string(),
                    "Optimized pattern matching algorithms".to_string(),
                ],
                recommended_focus_areas: vec![
                    "Search algorithm implementation".to_string(),
                    "File type detection logic".to_string(),
                    "Output formatting systems".to_string(),
                ],
            }),
        });

        // Python - Data Science
        self.add_repository(ShowcaseRepository {
            name: "pandas".to_string(),
            url: "https://github.com/pandas-dev/pandas".to_string(),
            description: "Flexible and powerful data analysis/manipulation library".to_string(),
            primary_language: "python".to_string(),
            languages: vec!["python".to_string(), "cython".to_string()],
            frameworks: vec!["NumPy".to_string(), "Cython".to_string()],
            category: RepositoryCategory::DataScience,
            complexity_tier: ComplexityTier::Advanced,
            estimated_analysis_time_seconds: 75,
            highlights: vec![
                "Complex data structures (DataFrame, Series)".to_string(),
                "High-performance computing with Cython".to_string(),
                "Extensive I/O capabilities".to_string(),
                "Statistical and analytical functions".to_string(),
            ],
            analysis_preview: Some(AnalysisPreview {
                estimated_files: 600,
                estimated_functions: 4000,
                estimated_complexity: 8.1,
                key_insights: vec![
                    "Complex data type system and indexing".to_string(),
                    "Extensive use of Cython for performance".to_string(),
                    "Sophisticated memory management".to_string(),
                ],
                recommended_focus_areas: vec![
                    "Core data structures implementation".to_string(),
                    "I/O and serialization systems".to_string(),
                    "Statistical computation engines".to_string(),
                ],
            }),
        });

        // JavaScript - Simple Web Tool
        self.add_repository(ShowcaseRepository {
            name: "Lodash".to_string(),
            url: "https://github.com/lodash/lodash".to_string(),
            description:
                "A modern JavaScript utility library delivering consistency and performance"
                    .to_string(),
            primary_language: "javascript".to_string(),
            languages: vec!["javascript".to_string()],
            frameworks: vec![],
            category: RepositoryCategory::DeveloperTools,
            complexity_tier: ComplexityTier::Beginner,
            estimated_analysis_time_seconds: 8,
            highlights: vec![
                "Comprehensive utility functions".to_string(),
                "Functional programming patterns".to_string(),
                "High test coverage".to_string(),
                "Consistent API design".to_string(),
            ],
            analysis_preview: Some(AnalysisPreview {
                estimated_files: 200,
                estimated_functions: 800,
                estimated_complexity: 3.2,
                key_insights: vec![
                    "Well-organized utility function library".to_string(),
                    "Consistent parameter handling patterns".to_string(),
                    "Extensive edge case handling".to_string(),
                ],
                recommended_focus_areas: vec![
                    "Array and object manipulation functions".to_string(),
                    "String processing utilities".to_string(),
                    "Type checking and validation systems".to_string(),
                ],
            }),
        });
    }

    fn add_repository(&mut self, repo: ShowcaseRepository) {
        let category = repo.category.clone();
        let name = repo.name.clone();

        self.repositories.insert(name.clone(), repo);
        self.categories.entry(category).or_default().push(name);
    }

    #[must_use] 
    pub fn get_all_repositories(&self) -> Vec<&ShowcaseRepository> {
        self.repositories.values().collect()
    }

    #[must_use] 
    pub fn get_repositories_by_category(
        &self,
        category: &RepositoryCategory,
    ) -> Vec<&ShowcaseRepository> {
        if let Some(repo_names) = self.categories.get(category) {
            repo_names
                .iter()
                .filter_map(|name| self.repositories.get(name))
                .collect()
        } else {
            Vec::new()
        }
    }

    #[must_use] 
    pub fn get_repositories_by_complexity(
        &self,
        tier: &ComplexityTier,
    ) -> Vec<&ShowcaseRepository> {
        self.repositories
            .values()
            .filter(|repo| repo.complexity_tier == *tier)
            .collect()
    }

    #[must_use] 
    pub fn get_repositories_by_language(&self, language: &str) -> Vec<&ShowcaseRepository> {
        let lang_lower = language.to_lowercase();
        self.repositories
            .values()
            .filter(|repo| {
                repo.primary_language.to_lowercase() == lang_lower
                    || repo
                        .languages
                        .iter()
                        .any(|l| l.to_lowercase() == lang_lower)
            })
            .collect()
    }

    #[must_use] 
    pub fn get_repository_by_name(&self, name: &str) -> Option<&ShowcaseRepository> {
        self.repositories.get(name)
    }

    #[must_use] 
    pub fn get_categories(&self) -> Vec<&RepositoryCategory> {
        self.categories.keys().collect()
    }

    #[must_use] 
    pub fn get_quick_start_recommendations(&self) -> Vec<&ShowcaseRepository> {
        // Return beginner and intermediate repositories for quick starts
        self.repositories
            .values()
            .filter(|repo| {
                matches!(
                    repo.complexity_tier,
                    ComplexityTier::Beginner | ComplexityTier::Intermediate
                )
            })
            .take(4)
            .collect()
    }

    #[must_use] 
    pub fn get_featured_repositories(&self) -> Vec<&ShowcaseRepository> {
        // Return a curated selection of featured repositories
        let featured_names = vec!["Tokio", "Django", "React", "VS Code"];
        featured_names
            .into_iter()
            .filter_map(|name| self.repositories.get(name))
            .collect()
    }

    #[must_use] 
    pub fn generate_showcase_summary(&self) -> ShowcaseSummary {
        let total_repositories = self.repositories.len();
        let languages: std::collections::HashSet<String> = self
            .repositories
            .values()
            .flat_map(|repo| repo.languages.iter().cloned())
            .collect();

        let categories_count = self.categories.len();

        let complexity_distribution = {
            let mut distribution = HashMap::new();
            for repo in self.repositories.values() {
                *distribution.entry(repo.complexity_tier).or_insert(0) += 1;
            }
            distribution
        };

        ShowcaseSummary {
            total_repositories,
            total_languages: languages.len(),
            total_categories: categories_count,
            complexity_distribution,
            featured_count: 4,
            quick_start_count: self.get_quick_start_recommendations().len(),
        }
    }
}

#[derive(Debug, Serialize)]
pub struct ShowcaseSummary {
    pub total_repositories: usize,
    pub total_languages: usize,
    pub total_categories: usize,
    pub complexity_distribution: HashMap<ComplexityTier, usize>,
    pub featured_count: usize,
    pub quick_start_count: usize,
}

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

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

    #[test]
    fn test_showcase_gallery_initialization() {
        let gallery = ShowcaseGallery::new();

        assert!(!gallery.repositories.is_empty());
        assert!(!gallery.categories.is_empty());

        // Should have repositories in different categories
        assert!(gallery.categories.len() >= 4);
    }

    #[test]
    fn test_repository_filtering() {
        let gallery = ShowcaseGallery::new();

        // Test filtering by language
        let rust_repos = gallery.get_repositories_by_language("rust");
        assert!(!rust_repos.is_empty());

        // Test filtering by complexity
        let beginner_repos = gallery.get_repositories_by_complexity(&ComplexityTier::Beginner);
        assert!(!beginner_repos.is_empty());

        // Test filtering by category
        let web_repos = gallery.get_repositories_by_category(&RepositoryCategory::WebFramework);
        assert!(!web_repos.is_empty());
    }

    #[test]
    fn test_showcase_recommendations() {
        let gallery = ShowcaseGallery::new();

        let quick_start = gallery.get_quick_start_recommendations();
        assert!(!quick_start.is_empty());
        assert!(quick_start.len() <= 4);

        let featured = gallery.get_featured_repositories();
        assert!(!featured.is_empty());
        assert_eq!(featured.len(), 4);
    }

    #[test]
    fn test_showcase_summary() {
        let gallery = ShowcaseGallery::new();
        let summary = gallery.generate_showcase_summary();

        assert!(summary.total_repositories > 0);
        assert!(summary.total_languages > 0);
        assert!(summary.total_categories > 0);
        assert!(!summary.complexity_distribution.is_empty());
    }

    #[test]
    fn test_repository_structure() {
        let gallery = ShowcaseGallery::new();

        if let Some(repo) = gallery.get_repository_by_name("Tokio") {
            assert_eq!(repo.name, "Tokio");
            assert_eq!(repo.primary_language, "rust");
            assert!(matches!(repo.complexity_tier, ComplexityTier::Advanced));
            assert!(repo.analysis_preview.is_some());
        } else {
            panic!("Tokio repository should be present in showcase");
        }
    }
}

#[cfg(test)]
mod property_tests {
    use proptest::prelude::*;

    proptest! {
        #[test]
        fn basic_property_stability(_input in ".*") {
            // Basic property test for coverage
            prop_assert!(true);
        }

        #[test]
        fn module_consistency_check(_x in 0u32..1000) {
            // Module consistency verification
            prop_assert!(_x < 1001);
        }
    }
}