# csye-6225-spring-2025/tf-aws-infra architecture

> Architecture diagram of the GitHub repository csye-6225-spring-2025/tf-aws-infra, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/csye-6225-spring-2025/tf-aws-infra
- Repository: https://github.com/csye-6225-spring-2025/tf-aws-infra

## Overview

##### Project Type and Purpose
- This is an “Infrastructure as Code” (IaC) repository using Terraform to provision a full AWS environment for the Health Tracker web application.
- It’s focused on creating a scalable, secure, multi-tier cloud architecture with CI/CD integration via GitHub Actions.

##### File Structure
- Root Terraform files (main.tf, variables.tf, outputs.tf, versions.tf) define resources, variables, and outputs.
- GitHub Actions workflow (terraform.yml) under .github/workflows orchestrates CI/CD.
- No application code—this repo’s sole purpose is AWS infra provisioning.

##### README Insights
- The README outlines key AWS components: VPC (public/private subnets), NAT gateways, ALB, ASGs, RDS, S3 (remote state), CloudWatch, IAM roles, security groups, NACLs.
- Emphasizes modular Terraform design, remote state management, and Checkov security scans.

a. Networking Layer
- VPC spanning three Availability Zones
- Public Subnets (with Internet Gateway)
- Private Subnets (with NAT Gateways)
- Route Tables, NACLs
b. Compute & Load Balancing
- Application Load Balancer (HTTPS listener, path‐based routing) in public subnets
- Auto Scaling Groups of EC2 instances in private subnets
c. Security & IAM
- Security Groups for ALB and EC2 instances
- IAM Roles and Policies for EC2, Lambda, and CI/CD processes
- KMS-managed keys for EBS encryption
d. Storage & Databases
- RDS MySQL cluster (multi-AZ) in isolated subnets
- S3 bucket for Terraform remote state and application assets
e. Observability & Logging
- CloudWatch Logs and Metrics
- VPC Flow Logs
f. CI/CD Integration
- GitHub Actions runner (external service) invoking terraform plan/apply
- S3/DynamoDB backend for state locking
- Checkov security scan step

##### Relationships and Data Flows
- Internet → ALB → EC2 ASG → RDS
- EC2 ASG retrieves assets from S3 and emits logs to CloudWatch
- GitHub Actions pushes state to S3 and locks in DynamoDB
- NAT Gateways enable outbound internet from private subnet (for package updates)
- IAM policies enforce least-privilege access between components

##### Architectural Patterns & Design Principles
- Multi-tier (Web tier, App tier, Data tier)
- High availability across 3 AZs
- Immutable infrastructure (AMI-based EC2 launches)

##### Technologies & Frameworks
- Terraform v1.5+ (IaC orchestration)
- AWS Cloud services (VPC, EC2, ALB, RDS, S3, CloudWatch, IAM, KMS)
- GitHub Actions (CI/CD workflow)
- Checkov (IaC compliance scanner)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Entities
    Internet["Internet"]:::external
    GitHubActions["GitHub Actions Runner"]:::ci

    %% Repository Structure
    subgraph "IaC Repository"
        direction TB
        subgraph "Terraform Configuration"
            direction TB
            MainTF["main.tf"]:::config
            VariablesTF["variables.tf"]:::config
            OutputsTF["outputs.tf"]:::config
            VersionsTF["versions.tf"]:::config
        end
        Docs["README.md"]:::doc
        Gitignore[".gitignore"]:::doc
    end

    %% AWS Cloud Architecture
    subgraph "AWS Cloud (Region)" 
        direction TB
        subgraph "Networking Layer" 
            direction TB
            VPC["VPC (3 AZs)"]:::network
            IGW["Internet Gateway"]:::network
            PublicSub["Public Subnets"]:::network
            PrivateSub["Private Subnets"]:::network
            NATGW["NAT Gateway"]:::network
            RT["Route Tables & NACLs"]:::network
        end
        subgraph "Compute & Load Balancing"
            direction TB
            ALB["ALB (HTTPS)"]:::compute
            ASG["EC2 Auto Scaling Group"]:::compute
        end
        subgraph "Storage & Database"
            direction TB
            S3State["S3 Remote State"]:::storage
            DynamoDB["DynamoDB Lock Table"]:::storage
            RDS["RDS MySQL (Multi-AZ)"]:::storage
        end
        subgraph "Security & IAM"
            direction TB
            SG["Security Groups"]:::security
            IAMRoles["IAM Roles & Policies"]:::security
            KMS["KMS Key"]:::security
        end
        subgraph "Observability & Logging"
            direction TB
            CWLogs["CloudWatch Logs & Metrics"]:::obs
            VPCLogs["VPC Flow Logs"]:::obs
        end
    end

    %% Connections
    Internet -->|"HTTPS request"| ALB
    ALB -->|"Route to ASG"| ASG
    ASG -->|"DB read/write"| RDS
    ASG -->|"Pulls assets"| S3State
    ASG -->|"Sends logs"| CWLogs
    PrivateSub -->|"Outbound via"| NATGW

    GitHubActions -->|"terraform plan/apply"| MainTF
    GitHubActions -->|"push state"| S3State
    GitHubActions -->|"lock state"| DynamoDB
    GitHubActions -->|"Checkov scan"| MainTF

    %% Infrastructure as Code Links
    MainTF --> VPC
    MainTF --> ALB
    MainTF --> ASG
    VariablesTF --> VPC

    %% Click Events
    click MainTF "https://github.com/csye-6225-spring-2025/tf-aws-infra/blob/main/main.tf"
    click VariablesTF "https://github.com/csye-6225-spring-2025/tf-aws-infra/blob/main/variables.tf"
    click OutputsTF "https://github.com/csye-6225-spring-2025/tf-aws-infra/blob/main/outputs.tf"
    click VersionsTF "https://github.com/csye-6225-spring-2025/tf-aws-infra/blob/main/versions.tf"
    click Docs "https://github.com/csye-6225-spring-2025/tf-aws-infra/blob/main/README.md"
    click Gitignore "https://github.com/csye-6225-spring-2025/tf-aws-infra/blob/main/.gitignore"
    click GitHubActions "https://github.com/csye-6225-spring-2025/tf-aws-infra/blob/main/.github/workflows/terraform.yml"

    %% Styles
    classDef external fill:#dddddd,stroke:#333,stroke-width:1px;
    classDef ci fill:#DDA0DD,stroke:#333,stroke-width:1px;
    classDef config fill:#F0F8FF,stroke:#333,stroke-width:1px;
    classDef doc fill:#FFEFD5,stroke:#333,stroke-width:1px;
    classDef network fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef compute fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef storage fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef security fill:#FFC0CB,stroke:#333,stroke-width:1px;
    classDef obs fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
