syncable-cli 0.37.1

A Rust-based CLI that analyzes code repositories and generates Infrastructure as Code configurations
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
//! Matrix/dashboard view display functionality

use crate::analyzer::display::{
    BoxDrawer, format_list_smart, format_ports_smart, get_color_adapter, get_terminal_width,
    helpers::{add_confidence_bar_to_drawer, format_project_category},
    smart_truncate, visual_width,
};
use crate::analyzer::{ArchitecturePattern, MonorepoAnalysis};

/// Display analysis in a compact matrix/dashboard format
pub fn display_matrix_view(analysis: &MonorepoAnalysis) {
    // Header
    let colors = get_color_adapter();
    println!("\n{}", colors.border(&"".repeat(100)));
    println!("{}", colors.header_text("📊 PROJECT ANALYSIS DASHBOARD"));
    println!("{}", colors.border(&"".repeat(100)));

    // Architecture Overview Box
    display_architecture_box(analysis);

    // Technology Stack Box
    display_technology_stack_box(analysis);

    // Projects Matrix
    if analysis.projects.len() > 1 {
        display_projects_matrix(analysis);
    } else {
        display_single_project_matrix(analysis);
    }

    // Docker Infrastructure Overview
    if analysis
        .projects
        .iter()
        .any(|p| p.analysis.docker_analysis.is_some())
    {
        display_docker_overview_matrix(analysis);
    }

    // Analysis Metrics Box
    display_metrics_box(analysis);

    // Footer
    println!("\n{}", colors.border(&"".repeat(100)));
}

/// Display analysis in a compact matrix/dashboard format - returns string
pub fn display_matrix_view_to_string(analysis: &MonorepoAnalysis) -> String {
    let mut output = String::new();

    // Header
    let colors = get_color_adapter();
    output.push_str(&format!("\n{}\n", colors.border(&"".repeat(100))));
    output.push_str(&format!(
        "{}\n",
        colors.header_text("📊 PROJECT ANALYSIS DASHBOARD")
    ));
    output.push_str(&format!("{}\n", colors.border(&"".repeat(100))));

    // Architecture Overview Box
    output.push_str(&display_architecture_box_to_string(analysis));

    // Technology Stack Box
    output.push_str(&display_technology_stack_box_to_string(analysis));

    // Projects Matrix
    if analysis.projects.len() > 1 {
        output.push_str(&display_projects_matrix_to_string(analysis));
    } else {
        output.push_str(&display_single_project_matrix_to_string(analysis));
    }

    // Docker Infrastructure Overview
    if analysis
        .projects
        .iter()
        .any(|p| p.analysis.docker_analysis.is_some())
    {
        output.push_str(&display_docker_overview_matrix_to_string(analysis));
    }

    // Analysis Metrics Box
    output.push_str(&display_metrics_box_to_string(analysis));

    // Footer
    output.push_str(&format!("\n{}\n", colors.border(&"".repeat(100))));

    output
}

/// Display architecture overview in a box
fn display_architecture_box(analysis: &MonorepoAnalysis) {
    let colors = get_color_adapter();
    let mut box_drawer = BoxDrawer::new("Architecture Overview");

    let arch_type = if analysis.is_monorepo {
        format!("Monorepo ({} projects)", analysis.projects.len())
    } else {
        "Single Project".to_string()
    };

    box_drawer.add_line("Type:", &colors.project_type(&arch_type), true);
    box_drawer.add_line(
        "Pattern:",
        &colors.architecture_pattern(&format!(
            "{:?}",
            analysis.technology_summary.architecture_pattern
        )),
        true,
    );

    // Pattern description
    let pattern_desc = match &analysis.technology_summary.architecture_pattern {
        ArchitecturePattern::Monolithic => "Single, self-contained application",
        ArchitecturePattern::Fullstack => "Full-stack app with frontend/backend separation",
        ArchitecturePattern::Microservices => "Multiple independent microservices",
        ArchitecturePattern::ApiFirst => "API-first architecture with service interfaces",
        ArchitecturePattern::EventDriven => "Event-driven with decoupled components",
        ArchitecturePattern::Mixed => "Mixed architecture patterns",
    };
    box_drawer.add_value_only(&colors.dimmed(pattern_desc));

    println!("\n{}", box_drawer.draw());
}

/// Display architecture overview in a box - returns string
fn display_architecture_box_to_string(analysis: &MonorepoAnalysis) -> String {
    let colors = get_color_adapter();
    let mut box_drawer = BoxDrawer::new("Architecture Overview");

    let arch_type = if analysis.is_monorepo {
        format!("Monorepo ({} projects)", analysis.projects.len())
    } else {
        "Single Project".to_string()
    };

    box_drawer.add_line("Type:", &colors.project_type(&arch_type), true);
    box_drawer.add_line(
        "Pattern:",
        &colors.architecture_pattern(&format!(
            "{:?}",
            analysis.technology_summary.architecture_pattern
        )),
        true,
    );

    // Pattern description
    let pattern_desc = match &analysis.technology_summary.architecture_pattern {
        ArchitecturePattern::Monolithic => "Single, self-contained application",
        ArchitecturePattern::Fullstack => "Full-stack app with frontend/backend separation",
        ArchitecturePattern::Microservices => "Multiple independent microservices",
        ArchitecturePattern::ApiFirst => "API-first architecture with service interfaces",
        ArchitecturePattern::EventDriven => "Event-driven with decoupled components",
        ArchitecturePattern::Mixed => "Mixed architecture patterns",
    };
    box_drawer.add_value_only(&colors.dimmed(pattern_desc));

    format!("\n{}", box_drawer.draw())
}

/// Display technology stack overview
fn display_technology_stack_box(analysis: &MonorepoAnalysis) {
    let colors = get_color_adapter();
    let mut box_drawer = BoxDrawer::new("Technology Stack");
    let term_width = get_terminal_width();
    // Max value width for the Technology Stack box (leave room for label + borders)
    let max_value_width = term_width.saturating_sub(30).min(80);

    let mut has_content = false;

    // Languages - show up to 4 with truncation
    if !analysis.technology_summary.languages.is_empty() {
        let languages = format_list_smart(&analysis.technology_summary.languages, 4, 20);
        let languages = smart_truncate(&languages, max_value_width);
        box_drawer.add_line("Languages:", &colors.language(&languages), true);
        has_content = true;
    }

    // Frameworks - show up to 4 with truncation
    if !analysis.technology_summary.frameworks.is_empty() {
        let frameworks = format_list_smart(&analysis.technology_summary.frameworks, 4, 16);
        let frameworks = smart_truncate(&frameworks, max_value_width);
        box_drawer.add_line("Frameworks:", &colors.framework(&frameworks), true);
        has_content = true;
    }

    // Databases - show up to 3 with truncation
    if !analysis.technology_summary.databases.is_empty() {
        let databases = format_list_smart(&analysis.technology_summary.databases, 3, 15);
        let databases = smart_truncate(&databases, max_value_width);
        box_drawer.add_line("Databases:", &colors.database(&databases), true);
        has_content = true;
    }

    if !has_content {
        box_drawer.add_value_only("No technologies detected");
    }

    println!("\n{}", box_drawer.draw());
}

/// Display technology stack overview - returns string
fn display_technology_stack_box_to_string(analysis: &MonorepoAnalysis) -> String {
    let colors = get_color_adapter();
    let mut box_drawer = BoxDrawer::new("Technology Stack");
    let term_width = get_terminal_width();
    // Max value width for the Technology Stack box (leave room for label + borders)
    let max_value_width = term_width.saturating_sub(30).min(80);

    let mut has_content = false;

    // Languages - show up to 4 with truncation
    if !analysis.technology_summary.languages.is_empty() {
        let languages = format_list_smart(&analysis.technology_summary.languages, 4, 20);
        let languages = smart_truncate(&languages, max_value_width);
        box_drawer.add_line("Languages:", &colors.language(&languages), true);
        has_content = true;
    }

    // Frameworks - show up to 4 with truncation
    if !analysis.technology_summary.frameworks.is_empty() {
        let frameworks = format_list_smart(&analysis.technology_summary.frameworks, 4, 16);
        let frameworks = smart_truncate(&frameworks, max_value_width);
        box_drawer.add_line("Frameworks:", &colors.framework(&frameworks), true);
        has_content = true;
    }

    // Databases - show up to 3 with truncation
    if !analysis.technology_summary.databases.is_empty() {
        let databases = format_list_smart(&analysis.technology_summary.databases, 3, 15);
        let databases = smart_truncate(&databases, max_value_width);
        box_drawer.add_line("Databases:", &colors.database(&databases), true);
        has_content = true;
    }

    if !has_content {
        box_drawer.add_value_only("No technologies detected");
    }

    format!("\n{}", box_drawer.draw())
}

/// Column width constraints for responsive display
struct ColumnConfig {
    max_width: usize,
    min_width: usize,
}

/// Display projects in a matrix table format with smart truncation
fn display_projects_matrix(analysis: &MonorepoAnalysis) {
    let term_width = get_terminal_width();
    let mut box_drawer = BoxDrawer::new("Projects Matrix");

    // Column configuration: max widths to prevent explosion
    // Adjusted based on terminal width
    let is_wide = term_width >= 120;
    let col_configs = [
        ColumnConfig {
            max_width: if is_wide { 24 } else { 18 },
            min_width: 7,
        }, // Project
        ColumnConfig {
            max_width: 10,
            min_width: 4,
        }, // Type
        ColumnConfig {
            max_width: if is_wide { 20 } else { 16 },
            min_width: 9,
        }, // Languages (wider for 2-3 items)
        ColumnConfig {
            max_width: if is_wide { 22 } else { 18 },
            min_width: 9,
        }, // Main Tech (wider for 2 items)
        ColumnConfig {
            max_width: if is_wide { 16 } else { 12 },
            min_width: 5,
        }, // Ports
        ColumnConfig {
            max_width: 6,
            min_width: 6,
        }, // Docker
        ColumnConfig {
            max_width: 4,
            min_width: 4,
        }, // Deps
    ];

    // Collect all data first, applying smart formatting
    let mut project_data = Vec::new();
    for project in &analysis.projects {
        let name = smart_truncate(&project.name, col_configs[0].max_width);
        let proj_type = smart_truncate(
            format_project_category(&project.project_category),
            col_configs[1].max_width,
        );

        // Languages: show 2-3 with "+N" for extras (wider terminals get 3)
        let lang_names: Vec<String> = project
            .analysis
            .languages
            .iter()
            .map(|l| l.name.clone())
            .collect();
        let max_langs = if is_wide { 3 } else { 2 };
        let languages = format_list_smart(&lang_names, max_langs, 12);

        // Main tech: show 2 with "+N" for extras
        let tech_names: Vec<String> = project
            .analysis
            .technologies
            .iter()
            .map(|t| t.name.clone())
            .collect();
        let main_tech = format_list_smart(&tech_names, 2, 14);

        // Smart ports: deduplicate and limit to 3
        let port_numbers: Vec<u16> = project.analysis.ports.iter().map(|p| p.number).collect();
        let ports = format_ports_smart(&port_numbers, 3);

        let docker = if project.analysis.docker_analysis.is_some() {
            "Yes"
        } else {
            "No"
        };
        let deps_count = project.analysis.dependencies.len().to_string();

        project_data.push((
            name,
            proj_type,
            languages,
            main_tech,
            ports,
            docker.to_string(),
            deps_count,
        ));
    }

    // Calculate column widths based on content (capped by max_width)
    let headers = [
        "Project",
        "Type",
        "Languages",
        "Main Tech",
        "Ports",
        "Docker",
        "Deps",
    ];
    let mut col_widths: Vec<usize> = headers
        .iter()
        .zip(&col_configs)
        .map(|(h, cfg)| visual_width(h).clamp(cfg.min_width, cfg.max_width))
        .collect();

    for (name, proj_type, languages, main_tech, ports, docker, deps_count) in &project_data {
        col_widths[0] = col_widths[0]
            .max(visual_width(name))
            .min(col_configs[0].max_width);
        col_widths[1] = col_widths[1]
            .max(visual_width(proj_type))
            .min(col_configs[1].max_width);
        col_widths[2] = col_widths[2]
            .max(visual_width(languages))
            .min(col_configs[2].max_width);
        col_widths[3] = col_widths[3]
            .max(visual_width(main_tech))
            .min(col_configs[3].max_width);
        col_widths[4] = col_widths[4]
            .max(visual_width(ports))
            .min(col_configs[4].max_width);
        col_widths[5] = col_widths[5]
            .max(visual_width(docker))
            .min(col_configs[5].max_width);
        col_widths[6] = col_widths[6]
            .max(visual_width(deps_count))
            .min(col_configs[6].max_width);
    }

    // Create header row
    let header_parts: Vec<String> = headers
        .iter()
        .zip(&col_widths)
        .map(|(h, &w)| format!("{:<width$}", h, width = w))
        .collect();
    let header_line = header_parts.join("");
    box_drawer.add_value_only(&header_line);

    // Add separator
    let separator_parts: Vec<String> = col_widths.iter().map(|&w| "".repeat(w)).collect();
    let separator_line = separator_parts.join("─┼─");
    box_drawer.add_value_only(&separator_line);

    // Add data rows
    for (name, proj_type, languages, main_tech, ports, docker, deps_count) in project_data {
        let row_parts = [
            format!("{:<width$}", name, width = col_widths[0]),
            format!("{:<width$}", proj_type, width = col_widths[1]),
            format!("{:<width$}", languages, width = col_widths[2]),
            format!("{:<width$}", main_tech, width = col_widths[3]),
            format!("{:<width$}", ports, width = col_widths[4]),
            format!("{:<width$}", docker, width = col_widths[5]),
            format!("{:<width$}", deps_count, width = col_widths[6]),
        ];
        let row_line = row_parts.join("");
        box_drawer.add_value_only(&row_line);
    }

    println!("\n{}", box_drawer.draw());
}

/// Display projects in a matrix table format - returns string (with smart truncation)
fn display_projects_matrix_to_string(analysis: &MonorepoAnalysis) -> String {
    let term_width = get_terminal_width();
    let mut box_drawer = BoxDrawer::new("Projects Matrix");

    // Column configuration: max widths to prevent explosion
    let is_wide = term_width >= 120;
    let col_configs = [
        ColumnConfig {
            max_width: if is_wide { 24 } else { 18 },
            min_width: 7,
        }, // Project
        ColumnConfig {
            max_width: 10,
            min_width: 4,
        }, // Type
        ColumnConfig {
            max_width: if is_wide { 20 } else { 16 },
            min_width: 9,
        }, // Languages (wider for 2-3 items)
        ColumnConfig {
            max_width: if is_wide { 22 } else { 18 },
            min_width: 9,
        }, // Main Tech (wider for 2 items)
        ColumnConfig {
            max_width: if is_wide { 16 } else { 12 },
            min_width: 5,
        }, // Ports
        ColumnConfig {
            max_width: 6,
            min_width: 6,
        }, // Docker
        ColumnConfig {
            max_width: 4,
            min_width: 4,
        }, // Deps
    ];

    // Collect all data first, applying smart formatting
    let mut project_data = Vec::new();
    for project in &analysis.projects {
        let name = smart_truncate(&project.name, col_configs[0].max_width);
        let proj_type = smart_truncate(
            format_project_category(&project.project_category),
            col_configs[1].max_width,
        );

        // Languages: show 2-3 with "+N" for extras (wider terminals get 3)
        let lang_names: Vec<String> = project
            .analysis
            .languages
            .iter()
            .map(|l| l.name.clone())
            .collect();
        let max_langs = if is_wide { 3 } else { 2 };
        let languages = format_list_smart(&lang_names, max_langs, 12);

        // Main tech: show 2 with "+N" for extras
        let tech_names: Vec<String> = project
            .analysis
            .technologies
            .iter()
            .map(|t| t.name.clone())
            .collect();
        let main_tech = format_list_smart(&tech_names, 2, 14);

        // Smart ports: deduplicate and limit to 3
        let port_numbers: Vec<u16> = project.analysis.ports.iter().map(|p| p.number).collect();
        let ports = format_ports_smart(&port_numbers, 3);

        let docker = if project.analysis.docker_analysis.is_some() {
            "Yes"
        } else {
            "No"
        };
        let deps_count = project.analysis.dependencies.len().to_string();

        project_data.push((
            name,
            proj_type,
            languages,
            main_tech,
            ports,
            docker.to_string(),
            deps_count,
        ));
    }

    // Calculate column widths based on content (capped by max_width)
    let headers = [
        "Project",
        "Type",
        "Languages",
        "Main Tech",
        "Ports",
        "Docker",
        "Deps",
    ];
    let mut col_widths: Vec<usize> = headers
        .iter()
        .zip(&col_configs)
        .map(|(h, cfg)| visual_width(h).clamp(cfg.min_width, cfg.max_width))
        .collect();

    for (name, proj_type, languages, main_tech, ports, docker, deps_count) in &project_data {
        col_widths[0] = col_widths[0]
            .max(visual_width(name))
            .min(col_configs[0].max_width);
        col_widths[1] = col_widths[1]
            .max(visual_width(proj_type))
            .min(col_configs[1].max_width);
        col_widths[2] = col_widths[2]
            .max(visual_width(languages))
            .min(col_configs[2].max_width);
        col_widths[3] = col_widths[3]
            .max(visual_width(main_tech))
            .min(col_configs[3].max_width);
        col_widths[4] = col_widths[4]
            .max(visual_width(ports))
            .min(col_configs[4].max_width);
        col_widths[5] = col_widths[5]
            .max(visual_width(docker))
            .min(col_configs[5].max_width);
        col_widths[6] = col_widths[6]
            .max(visual_width(deps_count))
            .min(col_configs[6].max_width);
    }

    // Create header row
    let header_parts: Vec<String> = headers
        .iter()
        .zip(&col_widths)
        .map(|(h, &w)| format!("{:<width$}", h, width = w))
        .collect();
    let header_line = header_parts.join("");
    box_drawer.add_value_only(&header_line);

    // Add separator
    let separator_parts: Vec<String> = col_widths.iter().map(|&w| "".repeat(w)).collect();
    let separator_line = separator_parts.join("─┼─");
    box_drawer.add_value_only(&separator_line);

    // Add data rows
    for (name, proj_type, languages, main_tech, ports, docker, deps_count) in project_data {
        let row_parts = [
            format!("{:<width$}", name, width = col_widths[0]),
            format!("{:<width$}", proj_type, width = col_widths[1]),
            format!("{:<width$}", languages, width = col_widths[2]),
            format!("{:<width$}", main_tech, width = col_widths[3]),
            format!("{:<width$}", ports, width = col_widths[4]),
            format!("{:<width$}", docker, width = col_widths[5]),
            format!("{:<width$}", deps_count, width = col_widths[6]),
        ];
        let row_line = row_parts.join("");
        box_drawer.add_value_only(&row_line);
    }

    format!("\n{}", box_drawer.draw())
}

/// Display single project in matrix format
fn display_single_project_matrix(analysis: &MonorepoAnalysis) {
    if let Some(project) = analysis.projects.first() {
        let colors = get_color_adapter();
        let mut box_drawer = BoxDrawer::new("Project Overview");

        // Basic info
        box_drawer.add_line("Name:", &colors.primary(&project.name), true);
        box_drawer.add_line(
            "Type:",
            &colors.secondary(format_project_category(&project.project_category)),
            true,
        );

        // Languages
        if !project.analysis.languages.is_empty() {
            let lang_info = project
                .analysis
                .languages
                .iter()
                .map(|l| l.name.clone())
                .collect::<Vec<_>>()
                .join(", ");
            box_drawer.add_line("Languages:", &colors.language(&lang_info), true);
        }

        // Technologies by category (simplified for string version)
        if !project.analysis.technologies.is_empty() {
            let tech_names = project
                .analysis
                .technologies
                .iter()
                .take(3)
                .map(|t| t.name.clone())
                .collect::<Vec<_>>()
                .join(", ");
            box_drawer.add_line("Technologies:", &colors.technology(&tech_names), true);
        }

        // Key metrics
        box_drawer.add_separator();
        box_drawer.add_line("Key Metrics:", "", true);

        // Display metrics on two lines to fit properly
        box_drawer.add_value_only(&colors.info(&format!(
            "Entry Points: {} │ Exposed Ports: {} │ Env Variables: {}",
            project.analysis.entry_points.len(),
            project.analysis.ports.len(),
            project.analysis.environment_variables.len()
        )));

        box_drawer.add_value_only(&colors.info(&format!(
            "Build Scripts: {} │ Dependencies: {}",
            project.analysis.build_scripts.len(),
            project.analysis.dependencies.len()
        )));

        // Confidence score with progress bar
        add_confidence_bar_to_drawer(
            project.analysis.analysis_metadata.confidence_score,
            &mut box_drawer,
        );

        println!("\n{}", box_drawer.draw());
    }
}

/// Display single project in matrix format - returns string
fn display_single_project_matrix_to_string(analysis: &MonorepoAnalysis) -> String {
    if let Some(project) = analysis.projects.first() {
        let colors = get_color_adapter();
        let mut box_drawer = BoxDrawer::new("Project Overview");

        // Basic info
        box_drawer.add_line("Name:", &colors.primary(&project.name), true);
        box_drawer.add_line(
            "Type:",
            &colors.secondary(format_project_category(&project.project_category)),
            true,
        );

        // Languages
        if !project.analysis.languages.is_empty() {
            let lang_info = project
                .analysis
                .languages
                .iter()
                .map(|l| l.name.clone())
                .collect::<Vec<_>>()
                .join(", ");
            box_drawer.add_line("Languages:", &colors.language(&lang_info), true);
        }

        // Technologies by category (simplified for string version)
        if !project.analysis.technologies.is_empty() {
            let tech_names = project
                .analysis
                .technologies
                .iter()
                .take(3)
                .map(|t| t.name.clone())
                .collect::<Vec<_>>()
                .join(", ");
            box_drawer.add_line("Technologies:", &colors.technology(&tech_names), true);
        }

        // Key metrics
        box_drawer.add_separator();
        box_drawer.add_line("Key Metrics:", "", true);

        // Display metrics on two lines to fit properly
        box_drawer.add_value_only(&colors.info(&format!(
            "Entry Points: {} │ Exposed Ports: {} │ Env Variables: {}",
            project.analysis.entry_points.len(),
            project.analysis.ports.len(),
            project.analysis.environment_variables.len()
        )));

        box_drawer.add_value_only(&colors.info(&format!(
            "Build Scripts: {} │ Dependencies: {}",
            project.analysis.build_scripts.len(),
            project.analysis.dependencies.len()
        )));

        // Confidence score with progress bar
        add_confidence_bar_to_drawer(
            project.analysis.analysis_metadata.confidence_score,
            &mut box_drawer,
        );

        format!("\n{}", box_drawer.draw())
    } else {
        String::new()
    }
}

/// Display Docker infrastructure overview in matrix format
fn display_docker_overview_matrix(analysis: &MonorepoAnalysis) {
    let colors = get_color_adapter();
    let mut box_drawer = BoxDrawer::new("Docker Infrastructure");

    let mut total_dockerfiles = 0;
    let mut total_compose_files = 0;
    let mut total_services = 0;
    let mut orchestration_patterns = std::collections::HashSet::new();

    for project in &analysis.projects {
        if let Some(docker) = &project.analysis.docker_analysis {
            total_dockerfiles += docker.dockerfiles.len();
            total_compose_files += docker.compose_files.len();
            total_services += docker.services.len();
            orchestration_patterns.insert(&docker.orchestration_pattern);
        }
    }

    box_drawer.add_line(
        "Dockerfiles:",
        &colors.metric(&total_dockerfiles.to_string()),
        true,
    );
    box_drawer.add_line(
        "Compose Files:",
        &colors.metric(&total_compose_files.to_string()),
        true,
    );
    box_drawer.add_line(
        "Total Services:",
        &colors.metric(&total_services.to_string()),
        true,
    );

    let patterns = orchestration_patterns
        .iter()
        .map(|p| format!("{:?}", p))
        .collect::<Vec<_>>()
        .join(", ");
    box_drawer.add_line(
        "Orchestration Patterns:",
        &colors.secondary(&patterns),
        true,
    );

    // Service connectivity summary
    let mut has_services = false;
    for project in &analysis.projects {
        if let Some(docker) = &project.analysis.docker_analysis {
            for service in &docker.services {
                if !service.ports.is_empty() || !service.depends_on.is_empty() {
                    has_services = true;
                    break;
                }
            }
        }
    }

    if has_services {
        box_drawer.add_separator();
        box_drawer.add_line("Service Connectivity:", "", true);

        for project in &analysis.projects {
            if let Some(docker) = &project.analysis.docker_analysis {
                for service in &docker.services {
                    if !service.ports.is_empty() || !service.depends_on.is_empty() {
                        let port_info = service
                            .ports
                            .iter()
                            .filter_map(|p| {
                                p.host_port.map(|hp| format!("{}:{}", hp, p.container_port))
                            })
                            .collect::<Vec<_>>()
                            .join(", ");

                        let deps_info = if service.depends_on.is_empty() {
                            String::new()
                        } else {
                            format!("{}", service.depends_on.join(", "))
                        };

                        let info = format!("  {}: {}{}", service.name, port_info, deps_info);
                        box_drawer.add_value_only(&colors.info(&info));
                    }
                }
            }
        }
    }

    println!("\n{}", box_drawer.draw());
}

/// Display docker overview matrix - returns string
fn display_docker_overview_matrix_to_string(analysis: &MonorepoAnalysis) -> String {
    let colors = get_color_adapter();
    let mut box_drawer = BoxDrawer::new("Docker Infrastructure");

    let mut total_dockerfiles = 0;
    let mut total_compose_files = 0;
    let mut total_services = 0;

    for project in &analysis.projects {
        if let Some(docker) = &project.analysis.docker_analysis {
            total_dockerfiles += docker.dockerfiles.len();
            total_compose_files += docker.compose_files.len();
            total_services += docker.services.len();
        }
    }

    box_drawer.add_line(
        "Dockerfiles:",
        &colors.metric(&total_dockerfiles.to_string()),
        true,
    );
    box_drawer.add_line(
        "Compose Files:",
        &colors.metric(&total_compose_files.to_string()),
        true,
    );
    box_drawer.add_line(
        "Total Services:",
        &colors.metric(&total_services.to_string()),
        true,
    );

    format!("\n{}", box_drawer.draw())
}

/// Display analysis metrics
fn display_metrics_box(analysis: &MonorepoAnalysis) {
    let colors = get_color_adapter();
    let mut box_drawer = BoxDrawer::new("Analysis Metrics");

    // Performance metrics
    let duration_ms = analysis.metadata.analysis_duration_ms;
    let duration_str = if duration_ms < 1000 {
        format!("{}ms", duration_ms)
    } else {
        format!("{:.1}s", duration_ms as f64 / 1000.0)
    };

    // Create metrics line without emojis first to avoid width calculation issues
    let metrics_line = format!(
        "Duration: {} | Files: {} | Score: {:.0}% | Version: {}",
        duration_str,
        analysis.metadata.files_analyzed,
        analysis.metadata.confidence_score * 100.0,
        analysis.metadata.analyzer_version
    );

    // Apply single color to the entire line for consistency
    let colored_metrics = colors.info(&metrics_line);
    box_drawer.add_value_only(&colored_metrics.to_string());

    println!("\n{}", box_drawer.draw());
}

/// Display analysis metrics - returns string
fn display_metrics_box_to_string(analysis: &MonorepoAnalysis) -> String {
    let colors = get_color_adapter();
    let mut box_drawer = BoxDrawer::new("Analysis Metrics");

    // Performance metrics
    let duration_ms = analysis.metadata.analysis_duration_ms;
    let duration_str = if duration_ms < 1000 {
        format!("{}ms", duration_ms)
    } else {
        format!("{:.1}s", duration_ms as f64 / 1000.0)
    };

    // Create metrics line
    let metrics_line = format!(
        "Duration: {} | Files: {} | Score: {:.0}% | Version: {}",
        duration_str,
        analysis.metadata.files_analyzed,
        analysis.metadata.confidence_score * 100.0,
        analysis.metadata.analyzer_version
    );

    box_drawer.add_value_only(&colors.info(&metrics_line));

    format!("\n{}", box_drawer.draw())
}