# bh10-d/ami-ubuntu-elk-packer architecture

> Architecture diagram of the GitHub repository bh10-d/ami-ubuntu-elk-packer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bh10-d/ami-ubuntu-elk-packer
- Repository: https://github.com/bh10-d/ami-ubuntu-elk-packer

## Overview

##### Project Type and Purpose
- Project Type: Infrastructure automation / DevOps script package.
- Purpose: To build and configure an AMI (using Packer) or to set up an ELK stack directly on a local Linux machine. It installs packages (openjdk, nginx, elasticsearch, kibana, logstash, filebeat) and configures a reverse proxy (NGINX) ensuring secured access to the Kibana dashboard.

##### File Structure
- Top-level Files:
- README.md – Provides instructions and details about the ELK deployment.
- template.json and vars.json – Indicate the Packer configuration for building an AMI.
- Directory "script":
- Contains several shell scripts (env.sh, local_machine.sh, filebeat.yml, remove.sh, script.sh) which handle varying tasks such as environment configuration, local deployment, service manipulation, and filebeat configuration.
- The presence of these components indicates that the system design involves:
- A Packer-driven image build process.
- Shell scripts to configure and manage the ELK stack on both cloud AMI instances and local machines.

##### README for Additional Insights
- The README outlines two deployment modes:
- AMI creation via Packer (using template.json and vars.json).
- Direct local deployment via local_machine.sh.
- It also details the installation of several packages and the use of Nginx as a reverse proxy (with provided credentials for accessing the Kibana dashboard).

a. Main Components:
- Packer Builder: Uses template.json and vars.json to produce an AMI.
- Initialization Scripts: Under the "script" directory, which include environment setup (env.sh), service control (script.sh, remove.sh), and local deployment (local_machine.sh).
- ELK Stack Components:
- Elasticsearch – Data storage and search engine.
- Logstash – Data processing pipeline.
- Kibana – Visualization and dashboarding tool.
- Filebeat – Lightweight shipper for forwarding logs.
- Nginx Reverse Proxy: Secures and routes access to Kibana.
- External Dependencies: OpenJDK (to support ELK applications).

b. Relationships and Interactions:
- The Packer Builder initiates the AMI build process; once the image is created, instance boot-up scripts ensure services (especially Elasticsearch) are started.
- For local deployments, the local_machine.sh script orchestrates installation and configuration of all components.
- Filebeat is configured (via filebeat.yml) to ship logs to Logstash/Elasticsearch.
- Nginx acts as the intermediary for accessing Kibana, providing authentication (username: kibanaadmin, password: kibanaadmin).

c. Architectural Patterns and Design Principles:
- Separation of concerns is visible in the split between image creation for cloud instances (using Packer) and local environment deployment.
- The design leverages composition: multiple scripts each handling specific deployment tasks.
- Clear layering exists with the infrastructure provisioning (AMI creation using Packer), application installation/configuration layer (ELK components and Nginx), and runtime operations (service management scripts).

d. Relevant Technologies:
- Packer for automating machine image builds.
- Shell scripting and configuration files to manage deployments.
- Nginx as a reverse proxy.
- ELK stack components (Elasticsearch, Logstash, Kibana, Filebeat).
- OpenJDK (required by the ELK stack).

##### Essential Elements
- Well-labeled components representing:
- Packer builder (with template.json and vars.json as configuration inputs)
- Shell script components (grouped under “Scripts”)
- Each element of the ELK stack (Elasticsearch, Logstash, Kibana, Filebeat)
- Nginx as the reverse proxy
- The flows for AMI creation versus local deployment.
- Data flow (e.g., logs moving from Filebeat to Logstash/Elasticsearch)
- Setup/initialization sequences (image creation leading to instance boot-up)
- Dependencies (e.g., services reliant on openjdk)
- Infrastructure provisioning (Packer)
- Deployment scripts/tools (shell scripts)
- Deployed services (ELK components and Nginx)
- External dependencies (such as OpenJDK)

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["README Documentation"]:::doc

    %% Cloud Deployment Branch
    subgraph "Cloud Deployment"
        T["Template Config"]:::infra
        V["Vars Config"]:::infra
        P["Packer Builder"]:::infra
        T -->|"uses"| P
        V -->|"uses"| P
        C["AMI Build Process"]:::infra
        I["Instance Boot-Up"]:::infra
        P -->|"builds"| C
        C -->|"triggers"| I
    end

    %% Local Deployment Branch
    subgraph "Local Deployment"
        L["Local Deployment Script"]:::scripts
    end

    %% Merge deployment branches into ELK Stack Deployment
    %% Both Instance Boot-Up and Local Deployment Script launch ELK components
    I -->|"deploys"| E["Elasticsearch"]:::elk
    L -->|"deploys"| E
       
    %% ELK Components flow
    E -->|"processes"| LS["Logstash"]:::elk
    LS -->|"visualizes"| K["Kibana"]:::elk
    Fb["Filebeat"]:::elk
    Fb -->|"forwards"| LS
    Fb -->|"forwards"| E
    N["Nginx Reverse Proxy"]:::proxy
    N -->|"routes"| K

    %% External Dependency
    G["OpenJDK"]:::external
    G ---|"supports"| E
    G ---|"supports"| LS
    G ---|"supports"| K

    %% Deployment Scripts Subgraph
    subgraph "Deployment Scripts"
        DS1["Environment Setup Script"]:::scripts
        DS2["Service Management Script"]:::scripts
        DS3["Service Removal Script"]:::scripts
        DS4["Filebeat Configuration"]:::scripts
    end
    %% Deployment Scripts feed into provisioning
    DS1 -->|"configures"| I
    DS1 -->|"configures"| L
    DS2 -->|"manages"| I
    DS3 -->|"controls"| I
    DS4 -->|"configures"| Fb

    %% Class Definitions for Colors
    classDef doc fill:#E3F2FD,stroke:#0D47A1,stroke-width:2px;
    classDef infra fill:#E8F5E9,stroke:#2E7D32,stroke-width:2px;
    classDef scripts fill:#FFF3E0,stroke:#EF6C00,stroke-width:2px;
    classDef elk fill:#E1F5FE,stroke:#0277BD,stroke-width:2px;
    classDef proxy fill:#F3E5F5,stroke:#8E24AA,stroke-width:2px;
    classDef external fill:#FFEBEE,stroke:#C62828,stroke-width:2px;

    %% Click Events
    click A "https://github.com/bh10-d/ami-ubuntu-elk-packer/blob/master/README.md"
    click T "https://github.com/bh10-d/ami-ubuntu-elk-packer/blob/master/template.json"
    click V "https://github.com/bh10-d/ami-ubuntu-elk-packer/blob/master/vars.json"
    click DS1 "https://github.com/bh10-d/ami-ubuntu-elk-packer/blob/master/script/env.sh"
    click L "https://github.com/bh10-d/ami-ubuntu-elk-packer/blob/master/script/local_machine.sh"
    click DS4 "https://github.com/bh10-d/ami-ubuntu-elk-packer/blob/master/script/filebeat.yml"
    click DS2 "https://github.com/bh10-d/ami-ubuntu-elk-packer/blob/master/script/script.sh"
    click DS3 "https://github.com/bh10-d/ami-ubuntu-elk-packer/blob/master/script/remove.sh"
```
