# kea-chunsam/playus-terraform architecture

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

- Interactive diagram: https://gitdiagram.com/kea-chunsam/playus-terraform
- Repository: https://github.com/kea-chunsam/playus-terraform

## Overview

##### Project type and purpose
- This is an “Infrastructure-as-Code” Terraform repository.
- Its goal is to stand up a secure, multi-tier network on Kakao Cloud for the PlayUs application, hosting static React assets and a Spring API on Kubernetes behind an ALB.

##### File structure
- Top-level `.tf` files:
- network.tf defines the VPC, subnets (public vs. private)
- alb.tf defines the Application Load Balancer and its listeners/rules
- instance.tf and security.tf spin up bastion, NAT, web and K8s nodes plus security groups
- main.tf / data.tf / outputs.tf / variables.tf / require.tf glue modules together, import data sources, and export endpoints
- `templates/` houses the user-data scripts (`init-*.sh`) used to bootstrap each instance role (bastion, NAT, web, K8s master/worker).
- `terraform.tfvars.example` shows required variables (credentials, sizes, CIDRs).

##### README for architectural insights
- Public Subnet: Bastion (SSH & Nginx Proxy Manager), NAT instance, ALB
- Private Subnet: React Web Server, Kubernetes Cluster (1 master + 2 workers)
- ALB port 80 routes “/” → Web server; “/api/*” → Kong ingress on K8s
- Security groups lock each component to only necessary ports

## Diagram (Mermaid)

```mermaid
flowchart TD
    Internet["Internet (Users)"]:::external
    Internet -->|HTTP 80| ALB

    subgraph "PlayUs VPC" 
        direction TB
        subgraph "Public Subnet"
            direction TB
            ALB["ALB (alb.tf)"]:::alb
            Bastion["Bastion Host"]:::compute
            NAT["NAT Instance"]:::nat
        end

        subgraph "Private Subnet"
            direction TB
            React["React Web Servers"]:::compute
            subgraph "K8s Cluster"
                direction TB
                Kong["Kong Ingress"]:::compute
                KMaster["K8s Master Node"]:::compute
                KWorker1["K8s Worker Node 1"]:::compute
                KWorker2["K8s Worker Node 2"]:::compute
            end
        end
    end

    ALB -->|"/"| React
    ALB -->|"/api/*"| Kong
    Bastion -->|SSH 10000-10003| KMaster
    React -->|Outbound| NAT
    NAT -->|Internet| Internet

    subgraph "Terraform IaC"
        direction TB
        Main["main.tf"]:::tf
        Data["data.tf"]:::tf
        Vars["variables.tf"]:::tf
        Req["require.tf"]:::tf
        TFVars["terraform.tfvars.example"]:::tf
        Outputs["outputs.tf"]:::tf
    end

    Main --> Data
    Main --> Vars
    Main --> Req
    Main --> TFVars
    Main --> Outputs

    click ALB "https://github.com/kea-chunsam/playus-terraform/blob/main/alb.tf"
    click Bastion "https://github.com/kea-chunsam/playus-terraform/blob/main/templates/init-bastion.sh"
    click NAT "https://github.com/kea-chunsam/playus-terraform/blob/main/templates/init-nat.sh"
    click React "https://github.com/kea-chunsam/playus-terraform/blob/main/templates/init-web.sh"
    click KMaster "https://github.com/kea-chunsam/playus-terraform/blob/main/templates/init-k8s-master.sh"
    click KWorker1 "https://github.com/kea-chunsam/playus-terraform/blob/main/templates/init-k8s-slave.sh"
    click KWorker2 "https://github.com/kea-chunsam/playus-terraform/blob/main/templates/init-k8s-slave.sh"
    click Main "https://github.com/kea-chunsam/playus-terraform/blob/main/main.tf"
    click Data "https://github.com/kea-chunsam/playus-terraform/blob/main/data.tf"
    click Vars "https://github.com/kea-chunsam/playus-terraform/blob/main/variables.tf"
    click Req "https://github.com/kea-chunsam/playus-terraform/blob/main/require.tf"
    click TFVars "https://github.com/kea-chunsam/playus-terraform/blob/main/terraform.tfvars.example"
    click Outputs "https://github.com/kea-chunsam/playus-terraform/blob/main/outputs.tf"

    classDef external fill:#ffffff,stroke:#000000
    classDef alb fill:#ffcc80,stroke:#ff9900
    classDef compute fill:#cce5ff,stroke:#3399ff
    classDef nat fill:#e0e0e0,stroke:#888888
    classDef tf fill:#f2f2f2,stroke:#666666
```
