# ludicsa/terraform architecture

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

- Interactive diagram: https://gitdiagram.com/ludicsa/terraform
- Repository: https://github.com/ludicsa/terraform

## Overview

##### Project type and purpose
- This is not a typical front-end/back-end repo but an infrastructure-centric project that builds and deploys a standalone Java “registration application” (myapp.jar) to AWS.
- It uses Terraform for provisioning, Packer for AMI creation, and GitHub Actions for CI/CD.

##### File structure
- Top level:
- main.tf, variables.tf, .terraform.lock.hcl → Terraform IaC files
- packer/packer.json.pkr.hcl, packer/java.sh, packer/manifest.json → Packer template + provisioning script
- user-data.sh → EC2 user-data bootstrap script
- artifacts/myapp.jar → prebuilt Java application artifact
- .github/workflows/terraform.yml → GitHub Actions pipeline
- No application source code here: the JAR is consumed directly by Packer.

##### Extract README insights
- Confirms technologies: Terraform, Packer, AWS, GitHub Actions.
- Purpose: automate build (AMI) and delivery (infra provisioning) of a Java registration app.

##### Main components
a. CI/CD Pipeline (GitHub Actions)
b. Build phase: Packer
c. Artifact store (implicitly: Packer pulls myapp.jar from repo or artifact directory)
d. Infrastructure provisioning: Terraform
e. AWS environment: VPC → Subnets → Security Groups → EC2 instance (AMI built by Packer, bootstrapped by user-data.sh)
f. Java application runtime (the JAR running on EC2)
g. (Optionally) any external services or DB if defined in Terraform

##### Relationships and data flows
- Developer pushes code/JAR → GitHub repo
- GitHub Actions workflow:
1. Runs Packer:
- Uses packer.json.pkr.hcl + java.sh + manifest.json + artifacts/myapp.jar
- Produces a custom AMI in AWS
2. Runs Terraform:
- Uses main.tf + variables.tf + user-data.sh
- Reads AMI ID from Packer output
- Provisions VPC, networking, EC2 instance using that AMI
- EC2 boots, runs user-data.sh to start the Java registration app

##### Architectural patterns and principles
- Immutable infrastructure: AMI baking via Packer
- Infrastructure as Code: declarative Terraform modules
- GitOps/CI-driven deployment: GitHub Actions orchestrates build & deploy

##### Technologies/frameworks to annotate
- GitHub Actions
- Packer (HCL template, shell provisioner)
- Terraform (HCL modules)
- AWS (EC2, VPC, Security Groups, IAM roles if any)
- Java runtime (JRE/JDK inside AMI)

## Diagram (Mermaid)

```mermaid
graph TB
  subgraph "Client / Source Control"
    Dev["Developer / GitHub Repo"]:::external
  end
  Dev -->|"push code/JAR"| CI["GitHub Actions CI/CD"]:::pipeline
  click CI "https://github.com/ludicsa/terraform/blob/master/.github/workflows/terraform.yml"
  click Dev "https://github.com/ludicsa/terraform/blob/master/readme.md"

  subgraph "Build Phase"
    Template["packer.json.pkr.hcl"]:::iac
    Script["java.sh"]:::script
    Manifest["manifest.json"]:::iac
    Jar["myapp.jar"]:::artifact
    Template -->|"template"| Bake["AMI Bake"]:::build
    Script -->|"provision script"| Bake
    Manifest -->|"manifest"| Bake
    Jar -->|"artifact input"| Bake
    click Template "https://github.com/ludicsa/terraform/blob/master/packer/packer.json.pkr.hcl"
    click Script "https://github.com/ludicsa/terraform/blob/master/packer/java.sh"
    click Manifest "https://github.com/ludicsa/terraform/blob/master/packer/manifest.json"
    click Jar "https://github.com/ludicsa/terraform/blob/master/artifacts/myapp.jar"
  end
  CI -->|"runs Packer build"| Bake
  Bake -->|"produces AMI"| AMI["Custom AMI ID"]:::artifact

  subgraph "Terraform Config"
    TF["Terraform Provisioner"]:::iac
    TFVars["variables.tf"]:::iac
    Lock[".terraform.lock.hcl"]:::iac
    TFVars --> TF
    Lock --> TF
    click TF "https://github.com/ludicsa/terraform/blob/master/main.tf"
    click TFVars "https://github.com/ludicsa/terraform/blob/master/variables.tf"
    click Lock "https://github.com/ludicsa/terraform/blob/master/.terraform.lock.hcl"
  end
  CI -->|"runs Terraform"| TF
  AMI -->|"AMI input"| TF

  subgraph "AWS (Cloud)"
    subgraph "VPC"
      Subnets["Subnets"]:::aws
      SG["Security Groups"]:::aws
      Instance["EC2 Instance"]:::aws
    end
    TF -->|"provisions Subnets"| Subnets
    TF -->|"provisions SG"| SG
    TF -->|"launches EC2"| Instance
    Instance -->|"boots with user-data"| UD["user-data.sh"]:::script
    click UD "https://github.com/ludicsa/terraform/blob/master/user-data.sh"
    UD -->|"starts"| JavaApp["Java Registration App"]:::app
  end

  classDef pipeline fill:#D0E6FF,stroke:#0366d6;
  classDef build fill:#E0F8E0,stroke:#2C7;
  classDef iac fill:#E8FFE8,stroke:#4CAF50;
  classDef script fill:#FFF3CD,stroke:#FFEE7D;
  classDef artifact fill:#F0E0FF,stroke:#9C27B0;
  classDef external fill:#EEEEEE,stroke:#888888;
  classDef aws fill:#FFE0B2,stroke:#FB8C00;
  classDef app fill:#E1F5FE,stroke:#0288D1;
```
