# mulesoft-consulting/mulesoft_deploymentascode architecture

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

- Interactive diagram: https://gitdiagram.com/mulesoft-consulting/mulesoft_deploymentascode
- Repository: https://github.com/mulesoft-consulting/mulesoft_deploymentascode

## Overview

##### Project type and purpose
- This is a DevOps/Infrastructure-as-Code framework (called “Mule Deployments as Code”) written in Node.js.
- Its purpose is to manage and automate MuleSoft CloudHub deployments by declaring the desired target state in a YAML file, then using CI/CD to apply that state against Anypoint Platform.

##### File structure
- Top-level config and CI definitions:
- `.circleci/` (CircleCI pipeline config)
- `Jenkinsfile` (Jenkins pipeline)
- `.muleci/` (deployment scripts and shared logic)
- `_config.yml` (static site or documentation config)
- Source of truth for environment state:
- `deployment_descriptor.yml` (defines target state: apps, runtimes, workers)
- `app_properties/` (per-application property files keyed by branch/environment)
- Miscellaneous support files:
- `app_properties/*/*.properties`

##### README for additional insights
- Describes end-to-end flow: commit to Git → CI trigger → execute `.muleci/deployment.sh` → Anypoint-CLI calls → CloudHub.
- Explains state reconciliation: deploy if missing, update if changed (version, workers, region, properties).

##### Main components
a. Git repository (configuration repo)
– Contains `deployment_descriptor.yml`, `app_properties/`, CI scripts.
b. CI/CD Server(s)
– CircleCI or Jenkins
– Reads `.circleci/config.yml` or `Jenkinsfile`
– Runs shell script `.muleci/deployment.sh`
c. Deployment Framework (Node.js)
– `.muleci/mule_common.js`, `anypoint_deployment_*.js`
– Parses descriptor, loads property files, drives Anypoint-CLI
d. Artifact Repository
– Maven-style repo (Nexus, JFrog) where application zip packages are hosted
e. Anypoint-CLI
– Command-line tool interfacing with Anypoint Platform REST APIs
f. CloudHub / Anypoint Runtime Manager
– Target environment where Mule applications are deployed/updated
g. App Properties Store
– Files in `app_properties/[app]/[app]-[branch].properties`

##### Relationships and data flows
1. Developer pushes changes to Git (branches per environment).
2. CI/CD server checks out the config repo and runs the pipeline.
3. CI invokes `deployment.sh`, which in turn:
– Loads `deployment_descriptor.yml`
– Looks up matching property files under `app_properties/`
– Calls Node.js scripts in `.muleci/`
– Invokes Anypoint-CLI commands (login, get/deploy/update applications)
4. Anypoint-CLI communicates with CloudHub APIs to ensure target state.
5. If a new package version is needed, the framework pulls the ZIP from the artifact repository.

##### Architectural patterns & design principles
- Infrastructure-as-Code: config as the single source of truth, idempotent operations
- GitOps/Declarative approach: commit describes desired state
- Separation of concerns:
- CI pipeline config vs. deployment scripts vs. environment descriptor vs. app properties
- Extensibility: adding new deployment targets or properties by dropping in new JS modules or YAML entries

##### Diagramming recommendations
- Use clear labels: “Git Repo”, “CI Server”, “.muleci Scripts”, “Artifact Repo”, “Anypoint-CLI”, “CloudHub”
- Git → CI trigger
- CI → Deployment scripts
- Scripts → Anypoint-CLI → CloudHub API
- Scripts → Artifact Repo
- Blue: Source/configuration (Git, YAML, properties)
- Green: Execution/runtime (CI, Node.js)
- Orange: External services (Artifact repo, CloudHub)
- Rectangles for services/processes
- Clouds for external platforms

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layers
    subgraph "Developer/Maintainer Layer"
        direction TB
        GitRepo(("Git Repository")):::source
        Descriptor["deployment_descriptor.yml"]:::source
        AppProperties["app_properties/"]:::source
        ConfigSite["_config.yml"]:::source
        Images["images/"]:::source
    end

    subgraph "CI/CD Layer"
        direction TB
        CircleCIConfig[".circleci/config.yml"]:::runtime
        JenkinsConfig["Jenkinsfile"]:::runtime
        CIService(("CI Server")):::runtime
    end

    subgraph "Deployment Engine Layer"
        direction TB
        ShellScript[".muleci/deployment.sh"]:::runtime
        subgraph "Node.js Framework"
            direction TB
            MuleCommon["mule_common.js"]:::runtime
            CloudAPI["anypoint_deployment_cloud_api.js"]:::runtime
            ARMAPI["anypoint_deployment_arm_api.js"]:::runtime
        end
        AnypointCLI(("Anypoint-CLI")):::runtime
    end

    subgraph "External Systems"
        direction TB
        ArtifactRepo(("Artifact Repository")):::external
        CloudHub(("CloudHub / Runtime Manager")):::external
    end

    %% Relationships
    GitRepo -->|"contains config & scripts"| CIService
    CIService -->|uses| CircleCIConfig
    CIService -->|uses| JenkinsConfig
    CIService -->|triggers| ShellScript

    ShellScript -->|loads| Descriptor
    ShellScript -->|loads| AppProperties
    ShellScript -->|invokes| MuleCommon
    ShellScript -->|invokes| CloudAPI
    ShellScript -->|invokes| ARMAPI
    ShellScript -->|calls| AnypointCLI
    ShellScript -->|fetches packages from| ArtifactRepo

    AnypointCLI -->|deploys/updates apps via API| CloudHub
    CloudAPI -->|wraps| AnypointCLI
    ARMAPI -->|wraps| AnypointCLI

    %% Click Events
    click GitRepo "https://github.com/mulesoft-consulting/mulesoft_deploymentascode/tree/master//"
    click CircleCIConfig "https://github.com/mulesoft-consulting/mulesoft_deploymentascode/blob/master/.circleci/config.yml"
    click JenkinsConfig "https://github.com/mulesoft-consulting/mulesoft_deploymentascode/tree/master/Jenkinsfile"
    click ShellScript "https://github.com/mulesoft-consulting/mulesoft_deploymentascode/blob/master/.muleci/deployment.sh"
    click MuleCommon "https://github.com/mulesoft-consulting/mulesoft_deploymentascode/blob/master/.muleci/mule_common.js"
    click CloudAPI "https://github.com/mulesoft-consulting/mulesoft_deploymentascode/blob/master/.muleci/anypoint_deployment_cloud_api.js"
    click ARMAPI "https://github.com/mulesoft-consulting/mulesoft_deploymentascode/blob/master/.muleci/anypoint_deployment_arm_api.js"
    click Descriptor "https://github.com/mulesoft-consulting/mulesoft_deploymentascode/blob/master/deployment_descriptor.yml"
    click AppProperties "https://github.com/mulesoft-consulting/mulesoft_deploymentascode/tree/master/app_properties/"
    click ConfigSite "https://github.com/mulesoft-consulting/mulesoft_deploymentascode/blob/master/_config.yml"
    click Images "https://github.com/mulesoft-consulting/mulesoft_deploymentascode/tree/master/images/"

    %% Styles
    classDef source fill:#cce5ff,stroke:#3399ff,color:#000;
    classDef runtime fill:#d4edda,stroke:#28a745,color:#000;
    classDef external fill:#ffe5b4,stroke:#ff9900,color:#000;
```
