# microsoft/nubesgen architecture

> Architecture diagram of the GitHub repository microsoft/nubesgen, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoft/nubesgen
- Repository: https://github.com/microsoft/nubesgen

## Overview

##### Project Type and Purpose
- NubesGen is an open-source, full-stack “Infrastructure as Code” (IaC) generator. It provides:
- A Java-based CLI (under `cli/`) for local use.
- A Spring Boot REST server (under `rest-server/`) that exposes HTTP endpoints to generate and download IaC templates.
- A documentation site (under `docs/`) built with VuePress.
- A set of Terraform root modules (under `terraform/`) for provisioning NubesGen itself or sample infrastructure.

- End Users
- CLI Tool
- Web UI or HTTP Client
- Documentation Site
- REST Server
- Controllers (MVC layer)
- Service Layer (CodeGeneratorService, ConfigurationService, TelemetryService, TemplateListService)
- Template Engine & Resource Scanner (Mustache templates under `src/main/resources/nubesgen/…`)
- Compression Services (Zip, TarGz)
- Template Repository
- Bicep templates
- Terraform modules
- Pulumi templates
- CI/CD & Build Infrastructure
- GitHub Actions workflows
- Docker / Native images (GraalVM Dockerfile)
- Terraform Root Modules
- Container-apps, storage-blob modules for self-deployment

##### Relationships and Data Flows
- User (CLI or Web UI) → HTTP request → REST Controller
- Controller → delegates to Service Layer → picks configuration & templates
- Service Layer → Template Engine → generates raw files → Compression Service → returns archive
- REST Server → HTTP response with zip/tar artifact
- CLI Tool receives archive → unpacks to local project directory
- CI/CD pipelines → build and publish CLI JARs, REST Docker images, docs site

##### Architectural Patterns and Principles
- MVC pattern in REST server (Controllers → Services → Utils)
- Template-method pattern for language-specific scanners (JavaScanner, NodeJsScanner, etc.)
- Separation of concerns: CLI vs. server vs. docs vs. Terraform modules
- Mustache templates for code generation (decoupled from Java logic)
- Compression and packaging as pluggable services

##### Relevant Technologies
- Java 17, Maven, Spring Boot
- Mustache template engine
- GraalVM native build (Dockerfile.native)
- GitHub Actions for CI/CD
- VuePress for docs
- Terraform & Pulumi templates

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Swimlanes
    subgraph "Clients" 
        direction TB
        CLI["CLI Tool"]:::client
        WebUI["Web UI/HTTP Client"]:::client
    end

    subgraph "REST Server" 
        direction TB
        subgraph "Controllers" 
            direction TB
            MainCtrl["MainController"]:::server
            VersionCtrl["VersionController"]:::server
        end
        subgraph "Services" 
            direction TB
            CodeGenSvc["CodeGeneratorService"]:::server
            ConfigSvc["ConfigurationService"]:::server
            TelemetrySvc["TelemetryService"]:::server
            TemplateListSvc["TemplateListService"]:::server
        end
        subgraph "Template Engine & Scanner" 
            direction TB
            ResourceScanner["ResourceScannerUtils"]:::server
            MustacheTpl["Mustache Templates"]:::templates
        end
        subgraph "Compression Services" 
            direction TB
            ZipSvc["ZipService"]:::server
            TarGzSvc["TarGzService"]:::server
        end
        StaticUI["Embedded Web UI"]:::server
    end

    subgraph "Template Repository" 
        direction TB
        MustacheTpl
    end

    subgraph "CI/CD & Build" 
        direction TB
        GHWorkflows[".github/workflows"]:::cicd
        Artifacts["Publish Artifacts"]:::cicd
    end

    subgraph "Terraform Root Modules" 
        direction TB
        TerraformRoot["terraform/"]:::tf
        TerraformModules["terraform/modules/"]:::tf
    end

    %% Connections
    CLI -->|"HTTP POST /generate"| MainCtrl
    WebUI -->|"HTTP POST /generate"| MainCtrl
    MainCtrl -->|"calls"| CodeGenSvc
    MainCtrl -->|"calls"| VersionCtrl
    CodeGenSvc -->|"load config"| ConfigSvc
    CodeGenSvc -->|"list templates"| TemplateListSvc
    TemplateListSvc -->|"scan resources"| ResourceScanner
    ResourceScanner -->|"reads"| MustacheTpl
    CodeGenSvc -->|"generate files"| MustacheTpl
    CodeGenSvc -->|"compress"| ZipSvc
    CodeGenSvc -->|"compress"| TarGzSvc
    ZipSvc -->|"returns archive"| MainCtrl
    TarGzSvc -->|"returns archive"| MainCtrl
    MainCtrl -->|"HTTP Response (zip/tar)"| CLI
    MainCtrl -->|"HTTP Response (zip/tar)"| WebUI

    GHWorkflows -->|"build CLI JAR"| CLI
    GHWorkflows -->|"build REST Docker"| MainCtrl
    GHWorkflows -->|"build docs site"| DocsSite["docs/"]:::cicd
    GHWorkflows -->|"publish"| Artifacts

    Artifacts -->|"available to"| CLI
    Artifacts -->|"available to"| MainCtrl

    TerraformRoot --> TerraformModules

    %% Click Events
    click CLI "https://github.com/microsoft/nubesgen/tree/main/cli/"
    click MainCtrl "https://github.com/microsoft/nubesgen/blob/main/rest-server/src/main/java/io/github/nubesgen/web/MainController.java"
    click VersionCtrl "https://github.com/microsoft/nubesgen/blob/main/rest-server/src/main/java/io/github/nubesgen/web/VersionController.java"
    click CodeGenSvc "https://github.com/microsoft/nubesgen/blob/main/rest-server/src/main/java/io/github/nubesgen/service/CodeGeneratorService.java"
    click ConfigSvc "https://github.com/microsoft/nubesgen/blob/main/rest-server/src/main/java/io/github/nubesgen/service/ConfigurationService.java"
    click TelemetrySvc "https://github.com/microsoft/nubesgen/blob/main/rest-server/src/main/java/io/github/nubesgen/service/TelemetryService.java"
    click TemplateListSvc "https://github.com/microsoft/nubesgen/blob/main/rest-server/src/main/java/io/github/nubesgen/service/TemplateListService.java"
    click ResourceScanner "https://github.com/microsoft/nubesgen/blob/main/rest-server/src/main/java/io/github/nubesgen/utils/ResourceScannerUtils.java"
    click MustacheTpl "https://github.com/microsoft/nubesgen/tree/main/rest-server/src/main/resources/nubesgen/"
    click ZipSvc "https://github.com/microsoft/nubesgen/blob/main/rest-server/src/main/java/io/github/nubesgen/service/compression/ZipService.java"
    click TarGzSvc "https://github.com/microsoft/nubesgen/blob/main/rest-server/src/main/java/io/github/nubesgen/service/compression/TarGzService.java"
    click StaticUI "https://github.com/microsoft/nubesgen/tree/main/rest-server/src/main/resources/static/"
    click DocsSite "https://github.com/microsoft/nubesgen/tree/main/docs/"
    click TerraformRoot "https://github.com/microsoft/nubesgen/tree/main/terraform/"
    click TerraformModules "https://github.com/microsoft/nubesgen/tree/main/terraform/modules/"
    click GHWorkflows "https://github.com/microsoft/nubesgen/tree/main/.github/workflows/"

    %% Styles
    classDef client fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef server fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef templates fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef cicd fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef tf fill:#e0ffee,stroke:#333,stroke-width:1px
```
