# mrjoy/root_image_factory architecture

> Architecture diagram of the GitHub repository mrjoy/root_image_factory, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mrjoy/root_image_factory
- Repository: https://github.com/mrjoy/root_image_factory

## Overview

##### Main Components

a) Infrastructure Layer:
- AWS Multi-Account Setup
- Development Account
- Production Account
- CI/CD Account

b) Tool Chain Components:
- Terraform Management Layer
- Packer Build System
- Ansible Provisioning Layer

c) Output Artifacts:
- Debian 11 Root Images
- AWS AMIs

##### Infrastructure Organization
- IAM relationships between accounts

##### Automation Pipeline
- Terraform → Packer → Ansible sequence
- Configuration inputs:
- terraform/*.tf files
- packer/root_image.pkr.hcl
- packer/playbooks/*.yml

##### Output Management
- Resulting artifacts

##### Specific Elements

- File references from the project structure:
- terraform/
- main.tf
- variables.tf
- outputs.tf
- packer/
- root_image.pkr.hcl
- playbooks/
- cloud_images.yml
- vars_*.yml

##### Important Workflows to Highlight

a) Infrastructure Provisioning Flow:
- Terraform Workspace Selection → Account Configuration → Infrastructure Setup

b) Image Building Flow:
- Packer → Ansible Playbooks → Image Creation → Multi-format Output

##### Environment Separation
- Clear separation between development and production workflows
- Configuration differences using vars_*.yml files
- Workspace-specific behaviors

##### Key Relationships to Emphasize

- Terraform workspace to AWS account mapping
- Packer's interaction with provisioned infrastructure
- Ansible's role in image configuration
- Final image distribution paths

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph AWS["AWS Multi-Account Infrastructure"]
        Dev["Development Account"]:::aws
        Prod["Production Account"]:::aws
        CICD["CI/CD Account"]:::aws
        Dev --> Prod
        Dev --> CICD
    end

    subgraph Automation["Automation Pipeline"]
        direction TB
        TF["Terraform Management"]:::tool
        PK["Packer Build System"]:::tool
        AN["Ansible Provisioning"]:::tool
        
        TF --> PK
        PK --> AN
    end

    subgraph Config["Configuration Layer"]
        direction TB
        TFConfig["Terraform Configs"]:::config
        PKConfig["Packer Configs"]:::config
        ANConfig["Ansible Playbooks"]:::config
        
        subgraph EnvVars["Environment Variables"]
            ProdVars["Production Vars"]:::config
            StageVars["Staging Vars"]:::config
            DefVars["Default Vars"]:::config
        end
    end

    subgraph Output["Output Artifacts"]
        direction TB
        AMI["AWS AMIs"]:::output
        Vagrant["Vagrant Boxes"]:::output
    end

    subgraph Pipeline["CI/CD Pipeline"]
        CircleCI["CircleCI Config"]:::cicd
    end

    %% Connections
    TFConfig --> TF
    PKConfig --> PK
    ANConfig --> AN
    EnvVars --> AN
    AN --> AMI
    AN --> Vagrant
    CircleCI --> Automation

    %% Click Events
    click TF "https://github.com/MrJoy/root_image_factory/blob/develop/terraform/main.tf"
    click PKConfig "https://github.com/MrJoy/root_image_factory/blob/develop/packer/root_image.pkr.hcl"
    click ANConfig "https://github.com/MrJoy/root_image_factory/blob/develop/packer/playbooks/cloud_images.yml"
    click ProdVars "https://github.com/MrJoy/root_image_factory/blob/develop/packer/playbooks/vars_prod.yml"
    click StageVars "https://github.com/MrJoy/root_image_factory/blob/develop/packer/playbooks/vars_stage.yml"
    click DefVars "https://github.com/MrJoy/root_image_factory/blob/develop/packer/playbooks/vars_default.yml"
    click Vagrant "https://github.com/MrJoy/root_image_factory/blob/develop/packer/vm_configs/vagrant.vmx"
    click CircleCI "https://github.com/MrJoy/root_image_factory/blob/develop/.circleci/config.yml"

    %% Styles
    classDef aws fill:#2374b5,stroke:#fff,stroke-width:2px,color:#fff
    classDef tool fill:#78b356,stroke:#fff,stroke-width:2px,color:#fff
    classDef config fill:#f7a35c,stroke:#fff,stroke-width:2px,color:#fff
    classDef output fill:#8b46c7,stroke:#fff,stroke-width:2px,color:#fff
    classDef cicd fill:#e6425e,stroke:#fff,stroke-width:2px,color:#fff

    %% Legend
    subgraph Legend
        L1["AWS Infrastructure"]:::aws
        L2["Automation Tools"]:::tool
        L3["Configuration Files"]:::config
        L4["Output Artifacts"]:::output
        L5["CI/CD Components"]:::cicd
    end
```
