# traffic-tacos/traffic-tacos-infra-iac architecture

> Architecture diagram of the GitHub repository traffic-tacos/traffic-tacos-infra-iac, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/traffic-tacos/traffic-tacos-infra-iac
- Repository: https://github.com/traffic-tacos/traffic-tacos-infra-iac

## Overview

##### Project type and purpose
- This repository is an Infrastructure-as-Code (IaC) project written in Terraform. Its purpose is to provision and manage a AWS-based 3-tier, microservices-friendly environment for the “Traffic Tacos” system. It orchestrates network (VPC, subnets, IGW, NAT), compute (EKS, EC2), data (DynamoDB, ElastiCache, S3), messaging (SQS, EventBridge), observability (CloudWatch, Prometheus, Grafana), and edge services (Route53, ACM, CloudFront).

##### File structure
- Top-level Terraform entrypoints:
- `main.tf`, `providers.tf`, `backend.tf`, `var.tf`, `outputs.tf`
- A `modules/` directory containing one folder per AWS service (vpc, ec2, eks, dynamodb, eventbridge, sqs, s3-static, cloudfront, route53, acm, elasticache, awsprometheus, awsgrafana, ecr, plus a placeholder rds).
- CI/CD and tooling: `.github/workflows/terraform.yml`, `atlantis.yaml`.
- Documentation under `README.md` and `docs/`.

##### README for additional insights
- Confirms a 3-tier architecture: Public tier (ALB, bastion), Private App tier (EKS, EC2), Private DB tier (RDS planned, DynamoDB, ElastiCache).
- Two core microservices: Ticket Service and Reservation Service, each using DynamoDB + EventBridge + SQS patterns.
- EKS cluster with multiple node groups, Karpenter autoscaling, Helm support.
- Static website on S3 + CloudFront, custom domain via Route53 + ACM.

a. Main components (group into four logical layers):
1. Edge & DNS layer
- Route53 Hosted Zone
- ACM Certificate
- CloudFront CDN (fronting S3 static website)
2. Network & Security layer
- VPC with three tiers (Public, Private-App, Private-DB)
- Internet Gateway (Public tier)
- NAT Gateway (Private tiers)
- Security Groups & IAM roles
3. Compute & Microservices layer
- EKS Cluster (3 node-groups: ondemand, mix, monitoring)
- EC2 Bastion Host (in Public tier)
- ECR repositories for each microservice (gateway-api, reservation-api, inventory-api, payment-sim-api, reservation-worker)
- Microservices deployed via Kubernetes (ALB Ingress Controller)
4. Data & Messaging layer
- DynamoDB tables (6 tables for Ticket + Reservation)
- EventBridge buses & rules (Ticket + Reservation)
- SQS queues + DLQs (payment-webhooks, reservation-events)
- ElastiCache Redis cluster
5. Observability & Monitoring layer
- AWS Managed Prometheus workspace
- AWS Managed Grafana workspace
- CloudWatch metrics & alarms
b. Relationships and interactions:
- Users (web/mobile) → DNS → CloudFront → S3 static content or ALB → EKS services.
- EKS services ↔ DynamoDB for persistence.
- Services emit domain events to EventBridge → routed to SQS DLQs or downstream services.
- Reservation TTL logic via DynamoDB & EventBridge scheduler.
- Payment and reservation events flow through SQS for reliable processing.
- EKS Karpenter monitors SQS for spot interruption signals.
- Monitoring: EKS metrics → Prometheus → Grafana dashboards.
c. Architectural patterns/design principles:
- 3-Tier network segmentation for security/isolation.
- Microservices pattern with event-driven communication (EventBridge + SQS).
- Immutable infra via Terraform modules (one module per service).
- GitOps/CI integration via Atlantis/GitHub workflows.
d. Key technologies/frameworks:
- Terraform modules
- AWS core services (VPC, EC2, EKS, DynamoDB, SQS, EventBridge, ElastiCache, S3, CloudFront, ACM, Route53)
- Kubernetes (EKS), Helm (planned)
- Karpenter for auto-scaling
- AWS Managed Prometheus & Grafana

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Users
    Users["Users (Web/Mobile)"]

    %% Edge & DNS layer
    subgraph "Edge & DNS Layer"
        direction TB
        Route53["Route53 Hosted Zone"]:::edge
        ACM["ACM Certificate"]:::edge
        CloudFront["CloudFront CDN"]:::edge
        S3Static["S3 Static Website"]:::edge
    end

    %% Network & Security layer
    subgraph "Network & Security Layer"
        direction TB
        VPC["VPC (Public, Private-App, Private-DB)"]:::networking
        SG_Bastion["EC2 Security Groups (Bastion)"]:::networking
        SG_EKS["EKS Security Groups"]:::networking
    end

    %% Compute & Microservices layer
    subgraph "Compute & Microservices Layer"
        direction TB
        EKS["EKS Cluster\n(node groups, Karpenter)"]:::compute
        BastionHost["EC2 Bastion Host"]:::compute
        ECR["ECR Repositories"]:::compute
    end

    %% Data & Messaging layer
    subgraph "Data & Messaging Layer"
        direction TB
        DynamoDB["DynamoDB Tables"]:::data
        EventBridge["EventBridge Bus & Rules"]:::data
        SQS["SQS Queues & DLQs"]:::data
        ElastiCache["ElastiCache Redis Cluster"]:::data
    end

    %% Observability & Monitoring layer
    subgraph "Observability & Monitoring Layer"
        direction TB
        Prometheus["AWS Managed Prometheus"]:::obs
        Grafana["AWS Managed Grafana"]:::obs
        CloudWatch["CloudWatch Metrics & Alarms"]:::obs
    end

    %% CI/CD & Tooling
    subgraph "CI/CD & Tooling"
        direction TB
        GitHubActions["GitHub Actions Workflows"]:::cicd
        Atlantis["Atlantis Configuration"]:::cicd
    end

    %% Core Terraform Entry Points
    Core["Core Terraform Entry Points"]:::cicd

    %% Documentation
    Docs["README.md & docs/"]:::cicd

    %% Connections
    Users -->|"DNS lookup"| Route53
    Route53 --> CloudFront
    CloudFront --> S3Static
    CloudFront --> EKS
    VPC --> SG_Bastion
    VPC --> SG_EKS
    SG_EKS --> EKS
    SG_Bastion --> BastionHost
    VPC --> EKS
    VPC --> DynamoDB
    VPC --> ElastiCache
    VPC --> SQS
    VPC --> EventBridge

    EKS --> DynamoDB
    EKS --> EventBridge
    EKS --> SQS
    EKS --> ElastiCache

    EventBridge --> SQS

    EKS --> Prometheus
    Prometheus --> Grafana
    EKS --> CloudWatch
    DynamoDB --> CloudWatch
    SQS --> CloudWatch

    GitHubActions --> Core
    Atlantis --> Core
    Core --> Docs

    %% Click Events
    click Route53 "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/route53/main.tf"
    click ACM "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/acm/main.tf"
    click CloudFront "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/cloudfront/main.tf"
    click S3Static "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/s3-static/main.tf"
    click VPC "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/vpc/vpc.tf"
    click SG_Bastion "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/ec2/sg.tf"
    click SG_EKS "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/eks/sg.tf"
    click EKS "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/eks/eks.tf"
    click BastionHost "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/ec2/ec2.tf"
    click ECR "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/ecr/ecr.tf"
    click DynamoDB "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/dynamodb/dynamodb.tf"
    click EventBridge "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/eventbridge/eventbridge.tf"
    click SQS "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/sqs/main.tf"
    click ElastiCache "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/elasticache/main.tf"
    click Prometheus "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/awsprometheus/awspromethus.tf"
    click Grafana "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/modules/awsgrafana/awsgrafna.tf"
    click GitHubActions "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/.github/workflows/terraform.yml"
    click Atlantis "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/atlantis.yaml"
    click Core "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/main.tf"
    click Docs "https://github.com/traffic-tacos/traffic-tacos-infra-iac/blob/main/README.md"

    %% Styles
    classDef networking fill:#D0E8FF,stroke:#084B8A
    classDef compute fill:#D0FFD8,stroke:#336633
    classDef data fill:#FFE3B8,stroke:#CC6600
    classDef obs fill:#E8D0FF,stroke:#663399
    classDef edge fill:#D0FFFA,stroke:#006666
    classDef cicd fill:#F0F0F0,stroke:#666666
```
