# pollenjp/cdk-ansible architecture

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

- Interactive diagram: https://gitdiagram.com/pollenjp/cdk-ansible
- Repository: https://github.com/pollenjp/cdk-ansible

## Overview

##### Project Type and Key Purposes
- This is a specialized toolkit (a “CDK”) for Ansible built in Rust.
- It provides libraries (core, macro, static), a command-line interface (CLI), and sample projects that implement a synthesizer for converting Rust code into JSON (and then YAML) files representing Ansible configurations.
- It also includes a module generation feature that creates new Rust packages for individual Ansible modules.

##### Analyzing the File Structure
- The top-level directories include .github (for CI/CD workflows), crates (for multiple Rust packages), examples (containing sample projects), and tools (for build, test, and publish scripts).
- Within the “crates” directory, you see several clearly separated packages:
– cdk-ansible-cli: The CLI tool to trigger module generation or synthesis.
– cdk-ansible-core: Contains core code and business logic (e.g., the synthesizer implementation).
– cdk-ansible-macro: Provides macros for easier user definitions and type-safety.
– cdk-ansible-static: Likely supplies static assets or helper logic needed during compile time or synthesis.
– cdk-ansible: May be the main library exposing functionality that both users and other crates leverage.
- The examples directory shows sample usage scenarios (for instance, the “simple-sample” project to demonstrate how a user defines an app by implementing Synthesizer and generating ansible files).
- Tools for building, testing, and publishing further round out the overall project lifecycle.

a. Main Components:
- User / Developer Interface: Illustrate the CLI (cdk-ansible-cli) as the primary entry point. Show that the CLI command (e.g., “cdk-ansible module” or “synth”) is what the developer uses to interact with the system.
- Static Resources: Represent the cdk-ansible-static crate used during synthesis.
- Generated Module Packages: Indicate that the CLI leverages these libraries to auto-generate new Rust packages for individual ansible modules.
- External Systems & Tools: Represent Ansible itself, which will ultimately use the playbook/inventory files; and additional tooling (like “uv” or conversion tools such as yq) that convert the JSON to YAML.

b. Relationships and Interactions:
- Demonstrate that the CLI communicates with core libraries (cdk-ansible-core) which may invoke macros (from cdk-ansible-macro) and static helpers (cdk-ansible-static).
- External conversion tools translating JSON files to YAML.
- Interactions with CI/CD where code changes trigger build and tests via GitHub workflows.

c. Architectural Patterns and Design Principles:
- The system is built using a modular, multi-crate structure; each crate has a well-defined responsibility.
- Separation of concerns is evident: the CLI is strictly for user interaction, core libraries handle business logic, and macros/ static assets support compile-time safety and resources.
- There is a clear layered approach: the developer writes Rust code (using provided macros), which then is synthesized into configuration artifacts.

d. Technologies, Frameworks, and Libraries:
- Rust is the core language providing type safety.
- Cargo (Rust’s build system) manages the dependency and multi-crate workspace.
- GitHub Actions (via .github/workflows) for CI/CD.
- External utilities like yq for post-processing the generated JSON files.

##### Summary
- It starts with user interaction via the CLI.
- It processes through a well-organized set of Rust crates, segregating responsibilities (CLI, core logic, macros, static resources).
- It ends with producing Ansible configuration files.
- It also highlights the external tooling (e.g., yq) used for file conversion and CI/CD systems ensuring code quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    U["User/Developer"]:::user

    %% CLI Layer
    CLI["cdk-ansible-cli"]:::cli

    %% Core Processing Layer
    CORE["cdk-ansible-core"]:::core
    MACRO["cdk-ansible-macro"]:::macro
    STATIC["cdk-ansible-static"]:::static
    LIB["cdk-ansible"]:::library

    %% Output Layer
    ARTIFACTS["Ansible Artifacts (JSON)"]:::output
    CONVERT["Conversion Tools (yq)"]:::external
    ANSIBLE["Ansible (External)"]:::external

    %% Additional Features
    MODULE["Module Generation (Rust Packages)"]:::module
    SAMPLE["Sample Projects"]:::sample
    CICD["CI/CD & Build Tools"]:::cicd

    %% Relationships
    U -->|"invokes"| CLI

    CLI -->|"triggers synthesis"| CORE
    CLI -->|"generates"| MODULE

    CORE -->|"uses"| MACRO
    CORE -->|"utilizes"| STATIC
    CORE -->|"integrates"| LIB

    CORE -->|"produces"| ARTIFACTS
    ARTIFACTS -->|"converted by"| CONVERT
    CONVERT -->|"feeds"| ANSIBLE

    CORE -->|"triggers"| CICD

    U -->|"references"| SAMPLE

    %% Click Events
    click CLI "https://github.com/pollenjp/cdk-ansible/tree/main/crates/cdk-ansible-cli"
    click CORE "https://github.com/pollenjp/cdk-ansible/tree/main/crates/cdk-ansible-core"
    click MACRO "https://github.com/pollenjp/cdk-ansible/tree/main/crates/cdk-ansible-macro"
    click STATIC "https://github.com/pollenjp/cdk-ansible/tree/main/crates/cdk-ansible-static"
    click LIB "https://github.com/pollenjp/cdk-ansible/tree/main/crates/cdk-ansible"
    click SAMPLE "https://github.com/pollenjp/cdk-ansible/tree/main/examples/simple-sample"
    click CICD "https://github.com/pollenjp/cdk-ansible/blob/main/.github"

    %% Styles
    classDef user fill:#ffadad,stroke:#e63946,stroke-width:2px;
    classDef cli fill:#f9c74f,stroke:#f08c00,stroke-width:2px;
    classDef core fill:#90be6d,stroke:#6a994e,stroke-width:2px;
    classDef macro fill:#f9844a,stroke:#f76d2b,stroke-width:2px;
    classDef static fill:#577590,stroke:#475d7b,stroke-width:2px;
    classDef library fill:#8ecae6,stroke:#219ebc,stroke-width:2px;
    classDef output fill:#277da1,stroke:#1b6ca8,stroke-width:2px;
    classDef external fill:#f94144,stroke:#d72638,stroke-width:2px;
    classDef cicd fill:#cdb4db,stroke:#9d4edd,stroke-width:2px;
    classDef sample fill:#ffba08,stroke:#f48c06,stroke-width:2px;
```
