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
//! Helper functions for display formatting

use crate::analyzer::display::BoxDrawer;
use crate::analyzer::{
    ArchitecturePattern, DetectedTechnology, DockerAnalysis, LibraryType, OrchestrationPattern,
    ProjectCategory, TechnologyCategory,
};
use colored::*;

/// Get emoji for project category
pub fn get_category_emoji(category: &ProjectCategory) -> &'static str {
    match category {
        ProjectCategory::Frontend => "🌐",
        ProjectCategory::Backend => "βš™οΈ",
        ProjectCategory::Api => "πŸ”Œ",
        ProjectCategory::Service => "πŸš€",
        ProjectCategory::Library => "πŸ“š",
        ProjectCategory::Tool => "πŸ”§",
        ProjectCategory::Documentation => "πŸ“–",
        ProjectCategory::Infrastructure => "πŸ—οΈ",
        ProjectCategory::Unknown => "❓",
    }
}

/// Format project category name
pub fn format_project_category(category: &ProjectCategory) -> &'static str {
    match category {
        ProjectCategory::Frontend => "Frontend",
        ProjectCategory::Backend => "Backend",
        ProjectCategory::Api => "API",
        ProjectCategory::Service => "Service",
        ProjectCategory::Library => "Library",
        ProjectCategory::Tool => "Tool",
        ProjectCategory::Documentation => "Documentation",
        ProjectCategory::Infrastructure => "Infrastructure",
        ProjectCategory::Unknown => "Unknown",
    }
}

/// Display architecture description
pub fn display_architecture_description(pattern: &ArchitecturePattern) {
    match pattern {
        ArchitecturePattern::Monolithic => {
            println!("   πŸ“¦ This is a single, self-contained application");
        }
        ArchitecturePattern::Fullstack => {
            println!("   🌐 This is a full-stack application with separate frontend and backend");
        }
        ArchitecturePattern::Microservices => {
            println!(
                "   πŸ”— This is a microservices architecture with multiple independent services"
            );
        }
        ArchitecturePattern::ApiFirst => {
            println!("   πŸ”Œ This is an API-first architecture focused on service interfaces");
        }
        ArchitecturePattern::EventDriven => {
            println!("   πŸ“‘ This is an event-driven architecture with decoupled components");
        }
        ArchitecturePattern::Mixed => {
            println!("   πŸ”€ This is a mixed architecture combining multiple patterns");
        }
    }
}

/// Helper function for displaying architecture description - returns string
pub fn display_architecture_description_to_string(pattern: &ArchitecturePattern) -> String {
    match pattern {
        ArchitecturePattern::Monolithic => {
            "   πŸ“¦ This is a single, self-contained application\n".to_string()
        }
        ArchitecturePattern::Fullstack => {
            "   🌐 This is a full-stack application with separate frontend and backend\n"
                .to_string()
        }
        ArchitecturePattern::Microservices => {
            "   πŸ”— This is a microservices architecture with multiple independent services\n"
                .to_string()
        }
        ArchitecturePattern::ApiFirst => {
            "   πŸ”Œ This is an API-first architecture focused on service interfaces\n".to_string()
        }
        ArchitecturePattern::EventDriven => {
            "   πŸ“‘ This is an event-driven architecture with decoupled components\n".to_string()
        }
        ArchitecturePattern::Mixed => {
            "   πŸ”€ This is a mixed architecture combining multiple patterns\n".to_string()
        }
    }
}

/// Get main technologies for display
pub fn get_main_technologies(technologies: &[DetectedTechnology]) -> String {
    let primary = technologies.iter().find(|t| t.is_primary);
    let frameworks: Vec<_> = technologies
        .iter()
        .filter(|t| {
            matches!(
                t.category,
                TechnologyCategory::FrontendFramework | TechnologyCategory::MetaFramework
            )
        })
        .take(2)
        .collect();

    let mut result = Vec::new();

    if let Some(p) = primary {
        result.push(p.name.clone());
    }

    for f in frameworks {
        if Some(&f.name) != primary.map(|p| &p.name) {
            result.push(f.name.clone());
        }
    }

    if result.is_empty() {
        "-".to_string()
    } else {
        result.join(", ")
    }
}

/// Add confidence score as a progress bar to the box drawer
pub fn add_confidence_bar_to_drawer(score: f32, box_drawer: &mut BoxDrawer) {
    let percentage = (score * 100.0) as u8;
    let bar_width = 20;
    let filled = ((score * bar_width as f32) as usize).min(bar_width);

    let bar = format!(
        "{}{}",
        "β–ˆ".repeat(filled).green(),
        "β–‘".repeat(bar_width - filled).dimmed()
    );

    let color = if percentage >= 80 {
        "green"
    } else if percentage >= 60 {
        "yellow"
    } else {
        "red"
    };

    let confidence_info = format!("{} {}", bar, format!("{:.0}%", percentage).color(color));
    box_drawer.add_line("Confidence:", &confidence_info, true);
}

/// Helper function for legacy detailed technology display
pub fn display_technologies_detailed_legacy(technologies: &[DetectedTechnology]) {
    // Group technologies by category
    let mut by_category: std::collections::HashMap<&TechnologyCategory, Vec<&DetectedTechnology>> =
        std::collections::HashMap::new();

    for tech in technologies {
        by_category.entry(&tech.category).or_default().push(tech);
    }

    // Find and display primary technology
    if let Some(primary) = technologies.iter().find(|t| t.is_primary) {
        println!("\nπŸ› οΈ  Technology Stack:");
        println!(
            "   🎯 PRIMARY: {} (confidence: {:.1}%)",
            primary.name,
            primary.confidence * 100.0
        );
        println!("      Architecture driver for this project");
    }

    // Display categories in order
    let categories = [
        (TechnologyCategory::MetaFramework, "πŸ—οΈ  Meta-Frameworks"),
        (
            TechnologyCategory::BackendFramework,
            "πŸ–₯️  Backend Frameworks",
        ),
        (
            TechnologyCategory::FrontendFramework,
            "🎨 Frontend Frameworks",
        ),
        (
            TechnologyCategory::Library(LibraryType::UI),
            "🎨 UI Libraries",
        ),
        (
            TechnologyCategory::Library(LibraryType::Utility),
            "πŸ“š Core Libraries",
        ),
        (TechnologyCategory::BuildTool, "πŸ”¨ Build Tools"),
        (TechnologyCategory::PackageManager, "πŸ“¦ Package Managers"),
        (TechnologyCategory::Database, "πŸ—ƒοΈ  Database & ORM"),
        (TechnologyCategory::Runtime, "⚑ Runtimes"),
        (TechnologyCategory::Testing, "πŸ§ͺ Testing"),
    ];

    for (category, label) in &categories {
        if let Some(techs) = by_category.get(category)
            && !techs.is_empty()
        {
            println!("\n   {}:", label);
            for tech in techs {
                println!(
                    "      β€’ {} (confidence: {:.1}%)",
                    tech.name,
                    tech.confidence * 100.0
                );
                if let Some(version) = &tech.version {
                    println!("        Version: {}", version);
                }
            }
        }
    }

    // Handle other Library types separately
    for (cat, techs) in &by_category {
        if let TechnologyCategory::Library(lib_type) = cat {
            let label = match lib_type {
                LibraryType::StateManagement => "πŸ”„ State Management",
                LibraryType::DataFetching => "πŸ”ƒ Data Fetching",
                LibraryType::Routing => "πŸ—ΊοΈ  Routing",
                LibraryType::Styling => "🎨 Styling",
                LibraryType::HttpClient => "🌐 HTTP Clients",
                LibraryType::Authentication => "πŸ” Authentication",
                LibraryType::Other(_) => "πŸ“¦ Other Libraries",
                _ => continue, // Skip already handled UI and Utility
            };

            // Only print if not already handled above
            if !matches!(lib_type, LibraryType::UI | LibraryType::Utility) && !techs.is_empty() {
                println!("\n   {}:", label);
                for tech in techs {
                    println!(
                        "      β€’ {} (confidence: {:.1}%)",
                        tech.name,
                        tech.confidence * 100.0
                    );
                    if let Some(version) = &tech.version {
                        println!("        Version: {}", version);
                    }
                }
            }
        }
    }
}

/// Helper function for legacy detailed technology display - returns string
pub fn display_technologies_detailed_legacy_to_string(
    technologies: &[DetectedTechnology],
) -> String {
    let mut output = String::new();

    // Group technologies by category
    let mut by_category: std::collections::HashMap<&TechnologyCategory, Vec<&DetectedTechnology>> =
        std::collections::HashMap::new();

    for tech in technologies {
        by_category.entry(&tech.category).or_default().push(tech);
    }

    // Find and display primary technology
    if let Some(primary) = technologies.iter().find(|t| t.is_primary) {
        output.push_str("\nπŸ› οΈ  Technology Stack:\n");
        output.push_str(&format!(
            "   🎯 PRIMARY: {} (confidence: {:.1}%)\n",
            primary.name,
            primary.confidence * 100.0
        ));
        output.push_str("      Architecture driver for this project\n");
    }

    // Display categories in order
    let categories = [
        (TechnologyCategory::MetaFramework, "πŸ—οΈ  Meta-Frameworks"),
        (
            TechnologyCategory::BackendFramework,
            "πŸ–₯️  Backend Frameworks",
        ),
        (
            TechnologyCategory::FrontendFramework,
            "🎨 Frontend Frameworks",
        ),
        (
            TechnologyCategory::Library(LibraryType::UI),
            "🎨 UI Libraries",
        ),
        (
            TechnologyCategory::Library(LibraryType::Utility),
            "πŸ“š Core Libraries",
        ),
        (TechnologyCategory::BuildTool, "πŸ”¨ Build Tools"),
        (TechnologyCategory::PackageManager, "πŸ“¦ Package Managers"),
        (TechnologyCategory::Database, "πŸ—ƒοΈ  Database & ORM"),
        (TechnologyCategory::Runtime, "⚑ Runtimes"),
        (TechnologyCategory::Testing, "πŸ§ͺ Testing"),
    ];

    for (category, label) in &categories {
        if let Some(techs) = by_category.get(category)
            && !techs.is_empty()
        {
            output.push_str(&format!("\n   {}:\n", label));
            for tech in techs {
                output.push_str(&format!(
                    "      β€’ {} (confidence: {:.1}%)\n",
                    tech.name,
                    tech.confidence * 100.0
                ));
                if let Some(version) = &tech.version {
                    output.push_str(&format!("        Version: {}\n", version));
                }
            }
        }
    }

    // Handle other Library types separately
    for (cat, techs) in &by_category {
        if let TechnologyCategory::Library(lib_type) = cat {
            let label = match lib_type {
                LibraryType::StateManagement => "πŸ”„ State Management",
                LibraryType::DataFetching => "πŸ”ƒ Data Fetching",
                LibraryType::Routing => "πŸ—ΊοΈ  Routing",
                LibraryType::Styling => "🎨 Styling",
                LibraryType::HttpClient => "🌐 HTTP Clients",
                LibraryType::Authentication => "πŸ” Authentication",
                LibraryType::Other(_) => "πŸ“¦ Other Libraries",
                _ => continue, // Skip already handled UI and Utility
            };

            // Only print if not already handled above
            if !matches!(lib_type, LibraryType::UI | LibraryType::Utility) && !techs.is_empty() {
                output.push_str(&format!("\n   {}:\n", label));
                for tech in techs {
                    output.push_str(&format!(
                        "      β€’ {} (confidence: {:.1}%)\n",
                        tech.name,
                        tech.confidence * 100.0
                    ));
                    if let Some(version) = &tech.version {
                        output.push_str(&format!("        Version: {}\n", version));
                    }
                }
            }
        }
    }

    output
}

/// Helper function for legacy Docker analysis display
pub fn display_docker_analysis_detailed_legacy(docker_analysis: &DockerAnalysis) {
    println!("\n   🐳 Docker Infrastructure Analysis:");

    // Dockerfiles
    if !docker_analysis.dockerfiles.is_empty() {
        println!(
            "      πŸ“„ Dockerfiles ({}):",
            docker_analysis.dockerfiles.len()
        );
        for dockerfile in &docker_analysis.dockerfiles {
            println!("         β€’ {}", dockerfile.path.display());
            if let Some(env) = &dockerfile.environment {
                println!("           Environment: {}", env);
            }
            if let Some(base_image) = &dockerfile.base_image {
                println!("           Base image: {}", base_image);
            }
            if !dockerfile.exposed_ports.is_empty() {
                println!(
                    "           Exposed ports: {}",
                    dockerfile
                        .exposed_ports
                        .iter()
                        .map(|p| p.to_string())
                        .collect::<Vec<_>>()
                        .join(", ")
                );
            }
            if dockerfile.is_multistage {
                println!(
                    "           Multi-stage build: {} stages",
                    dockerfile.build_stages.len()
                );
            }
            println!("           Instructions: {}", dockerfile.instruction_count);
        }
    }

    // Compose files
    if !docker_analysis.compose_files.is_empty() {
        println!(
            "      πŸ“‹ Compose Files ({}):",
            docker_analysis.compose_files.len()
        );
        for compose_file in &docker_analysis.compose_files {
            println!("         β€’ {}", compose_file.path.display());
            if let Some(env) = &compose_file.environment {
                println!("           Environment: {}", env);
            }
            if let Some(version) = &compose_file.version {
                println!("           Version: {}", version);
            }
            if !compose_file.service_names.is_empty() {
                println!(
                    "           Services: {}",
                    compose_file.service_names.join(", ")
                );
            }
            if !compose_file.networks.is_empty() {
                println!("           Networks: {}", compose_file.networks.join(", "));
            }
            if !compose_file.volumes.is_empty() {
                println!("           Volumes: {}", compose_file.volumes.join(", "));
            }
        }
    }

    // Rest of the detailed Docker display...
    println!(
        "      πŸ—οΈ  Orchestration Pattern: {:?}",
        docker_analysis.orchestration_pattern
    );
    match docker_analysis.orchestration_pattern {
        OrchestrationPattern::SingleContainer => {
            println!("         Simple containerized application");
        }
        OrchestrationPattern::DockerCompose => {
            println!("         Multi-service Docker Compose setup");
        }
        OrchestrationPattern::Microservices => {
            println!("         Microservices architecture with service discovery");
        }
        OrchestrationPattern::EventDriven => {
            println!("         Event-driven architecture with message queues");
        }
        OrchestrationPattern::ServiceMesh => {
            println!("         Service mesh for advanced service communication");
        }
        OrchestrationPattern::Mixed => {
            println!("         Mixed/complex orchestration pattern");
        }
    }
}

/// Helper function for legacy Docker analysis display - returns string
pub fn display_docker_analysis_detailed_legacy_to_string(
    docker_analysis: &DockerAnalysis,
) -> String {
    let mut output = String::new();

    output.push_str("\n   🐳 Docker Infrastructure Analysis:\n");

    // Dockerfiles
    if !docker_analysis.dockerfiles.is_empty() {
        output.push_str(&format!(
            "      πŸ“„ Dockerfiles ({}):\n",
            docker_analysis.dockerfiles.len()
        ));
        for dockerfile in &docker_analysis.dockerfiles {
            output.push_str(&format!("         β€’ {}\n", dockerfile.path.display()));
            if let Some(env) = &dockerfile.environment {
                output.push_str(&format!("           Environment: {}\n", env));
            }
            if let Some(base_image) = &dockerfile.base_image {
                output.push_str(&format!("           Base image: {}\n", base_image));
            }
            if !dockerfile.exposed_ports.is_empty() {
                output.push_str(&format!(
                    "           Exposed ports: {}\n",
                    dockerfile
                        .exposed_ports
                        .iter()
                        .map(|p| p.to_string())
                        .collect::<Vec<_>>()
                        .join(", ")
                ));
            }
            if dockerfile.is_multistage {
                output.push_str(&format!(
                    "           Multi-stage build: {} stages\n",
                    dockerfile.build_stages.len()
                ));
            }
            output.push_str(&format!(
                "           Instructions: {}\n",
                dockerfile.instruction_count
            ));
        }
    }

    // Compose files
    if !docker_analysis.compose_files.is_empty() {
        output.push_str(&format!(
            "      πŸ“‹ Compose Files ({}):\n",
            docker_analysis.compose_files.len()
        ));
        for compose_file in &docker_analysis.compose_files {
            output.push_str(&format!("         β€’ {}\n", compose_file.path.display()));
            if let Some(env) = &compose_file.environment {
                output.push_str(&format!("           Environment: {}\n", env));
            }
            if let Some(version) = &compose_file.version {
                output.push_str(&format!("           Version: {}\n", version));
            }
            if !compose_file.service_names.is_empty() {
                output.push_str(&format!(
                    "           Services: {}\n",
                    compose_file.service_names.join(", ")
                ));
            }
            if !compose_file.networks.is_empty() {
                output.push_str(&format!(
                    "           Networks: {}\n",
                    compose_file.networks.join(", ")
                ));
            }
            if !compose_file.volumes.is_empty() {
                output.push_str(&format!(
                    "           Volumes: {}\n",
                    compose_file.volumes.join(", ")
                ));
            }
        }
    }

    // Rest of the detailed Docker display...
    output.push_str(&format!(
        "      πŸ—οΈ  Orchestration Pattern: {:?}\n",
        docker_analysis.orchestration_pattern
    ));
    match docker_analysis.orchestration_pattern {
        OrchestrationPattern::SingleContainer => {
            output.push_str("         Simple containerized application\n");
        }
        OrchestrationPattern::DockerCompose => {
            output.push_str("         Multi-service Docker Compose setup\n");
        }
        OrchestrationPattern::Microservices => {
            output.push_str("         Microservices architecture with service discovery\n");
        }
        OrchestrationPattern::EventDriven => {
            output.push_str("         Event-driven architecture with message queues\n");
        }
        OrchestrationPattern::ServiceMesh => {
            output.push_str("         Service mesh for advanced service communication\n");
        }
        OrchestrationPattern::Mixed => {
            output.push_str("         Mixed/complex orchestration pattern\n");
        }
    }

    output
}