# mrjoy/base_image_factory architecture

> Architecture diagram of the GitHub repository mrjoy/base_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/base_image_factory
- Repository: https://github.com/mrjoy/base_image_factory

## Overview

##### Main Components

a) Image Building Pipeline:
- Root Image (starting point)
- Base Image Layer
- Language-specific Image Layer
- Final AMI Output

b) Core Services:
- Fluentd (teak-log-collector)
- Config-O-Mat (teak-configurator)
- Systemd Services
- CloudWatch Integration

**Top Level (Infrastructure):**
- AWS Environment
- Security Groups
- CloudWatch Logs
- AMI Storage

**Middle Level (Build Process):**
- Packer Build Pipeline
- Root Image Input
- Base Image Provisioning
- Language-specific Provisioning

**Bottom Level (Service Layer):**
- System Services
- teak-log-collector (Fluentd)
- teak-configurator (Config-O-Mat)
- teak-init.target

##### Key Relationships

a) Build Flow:
- Packer/Ansible provisioning steps between each stage

b) Service Dependencies:
- How teak-init.target depends on core services
- Log flow from services → Fluentd → CloudWatch

##### Important Details

a) Configuration Sources:
- Playbooks directory structure
- Variable files for different environments (development, stage, prod)
- System configuration files in /etc

b) Language Support:
- Parallel language-specific image creation paths (Ruby 3.1.4, 3.2.2)
- Provisioning playbooks specific to each language

##### Specific Implementation Notes

- Annotations for important configuration points (e.g., TEAK_SERVICE environment variable)
- CloudWatch Logs structure for different log types

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph AWS["AWS Environment"]
        direction TB
        CW[CloudWatch Logs]:::aws
        AMIStore[AMI Storage]:::aws
        SG[Security Groups]:::aws
    end

    subgraph BuildPipeline["Image Building Pipeline"]
        direction TB
        Root[Root Image]:::image
        Base[Base Image]:::image
        Lang1[Ruby 3.1.4 Image]:::image
        Lang2[Ruby 3.2.2 Image]:::image
        FinalAMI1[Final AMI Ruby 3.1.4]:::output
        FinalAMI2[Final AMI Ruby 3.2.2]:::output
        
        Root --> |Packer Build| Base
        Base --> |Language Provisioning| Lang1
        Base --> |Language Provisioning| Lang2
        Lang1 --> |System Finalization| FinalAMI1
        Lang2 --> |System Finalization| FinalAMI2
    end

    subgraph Services["Core Services Layer"]
        direction TB
        Fluentd[teak-log-collector]:::service
        ConfigOMat[teak-configurator]:::service
        TeakInit[teak-init.target]:::service
        TeakSlice[teak-services.slice]:::service
    end

    subgraph Config["Configuration Layer"]
        direction TB
        DevConfig[Development Vars]:::config
        ProdConfig[Production Vars]:::config
        StageConfig[Stage Vars]:::config
        TF[Terraform Config]:::infra
    end

    TeakInit --> TeakSlice
    TeakSlice --> Fluentd
    TeakSlice --> ConfigOMat
    Fluentd --> CW
    FinalAMI1 --> AMIStore
    FinalAMI2 --> AMIStore
    TF --> SG

    classDef aws fill:#2196F3,stroke:#1565C0,color:white
    classDef image fill:#FF9800,stroke:#F57C00,color:white
    classDef service fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef config fill:#757575,stroke:#616161,color:white
    classDef output fill:#4CAF50,stroke:#388E3C,color:white
    classDef infra fill:#607D8B,stroke:#455A64,color:white

    click Base "https://github.com/MrJoy/base_image_factory/blob/main/base_image.pkr.hcl"
    click Lang1 "https://github.com/MrJoy/base_image_factory/tree/main/language_images/ruby314"
    click Lang2 "https://github.com/MrJoy/base_image_factory/tree/main/language_images/ruby322"
    click Fluentd "https://github.com/MrJoy/base_image_factory/blob/main/playbooks/root/etc/systemd/system/teak-log-collector.service"
    click ConfigOMat "https://github.com/MrJoy/base_image_factory/blob/main/playbooks/root/etc/systemd/system/teak-configurator.service"
    click TeakInit "https://github.com/MrJoy/base_image_factory/blob/main/playbooks/root/etc/systemd/system/teak-init.target"
    click TeakSlice "https://github.com/MrJoy/base_image_factory/blob/main/playbooks/root/etc/systemd/system/teak-services.slice"
    click DevConfig "https://github.com/MrJoy/base_image_factory/blob/main/playbooks/vars_development.yml"
    click ProdConfig "https://github.com/MrJoy/base_image_factory/blob/main/playbooks/vars_prod.yml"
    click StageConfig "https://github.com/MrJoy/base_image_factory/blob/main/playbooks/vars_stage.yml"
    click TF "https://github.com/MrJoy/base_image_factory/blob/main/terraform/main.tf"
```
