# sohailsajid79/azure-tetris-deployment architecture

> Architecture diagram of the GitHub repository sohailsajid79/azure-tetris-deployment, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sohailsajid79/azure-tetris-deployment
- Repository: https://github.com/sohailsajid79/azure-tetris-deployment

## Overview

##### Main Components
- Infrastructure as Code (Terraform): Components include the Azure Resource Group, VNet, Subnet, Network Interface, Network Security Group (NSG), Public IP, and the Linux Virtual Machine.
- Virtual Machine: Hosts the Dockerized Tetris web application. The VM setup (and provisioning) is orchestrated by Terraform.
- Docker Container: Runs the Tetris application. The Docker image is pulled from Docker Hub (sajid79/tetris-js-app:amd64) and hosted on port 8080.
- NGINX Reverse Proxy: Installed on the VM to manage HTTP/HTTPS traffic and forward requests to the Docker container. It handles SSL redirection (from HTTP port 80 to HTTPS port 443), and proxies traffic internally to the Tetris application.
- SSL/TLS Security: Managed with Certbot and Let’s Encrypt, which provides the necessary certificates for securing communication.
- GitHub Actions Pipeline: Automates the deployment process by validating the deployment environment, scanning for vulnerabilities, pulling the Docker image, and updating the deployment through CI/CD.
- DNS and Cloudflare: Integrates with Cloudflare DNS to map the subdomain (tetris.sohailsajid.dev) to the VM’s public IP for public accessibility.

##### Relationships and Data/Control Flows
- Terraform initiates and orchestrates the provisioning of all Azure infrastructure components.
- After the VM is provisioned, a Docker container (running the Tetris app) is started on the VM.
- NGINX running on the VM receives incoming traffic on ports 80/443. HTTP traffic is automatically redirected to HTTPS.
- Requests reaching NGINX are proxied to the Docker container on port 8080.
- SSL/TLS certificates are automatically managed by Certbot, ensuring that communication is secure.
- GitHub Actions coordinate the deployment process (triggered by pushes) to ensure that updates are automatically rolled out and verified.
- Cloudflare DNS ensures that requests to tetris.sohailsajid.dev resolve to the correct VM public IP.

##### Architectural Patterns and Design Principles
- Infrastructure as Code (IaC): Using Terraform to set up repeatable and scalable cloud resources.
- Containerization: Docker ensures consistent application packaging and deployment.
- Reverse Proxy Pattern: NGINX serves static content, manages HTTPS redirection, and routes traffic to the application container.
- CI/CD Pipeline: GitHub Actions automates testing, deployment, and environmental consistency.
- Security Best Practices: The use of SSL/TLS certificates managed by Certbot for secure communication and an NSG to restrict access to only necessary ports.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Azure Infrastructure (Terraform)"
        TF["Terraform IaC"]:::infra
        RG["Resource Group"]:::infra
        VNET["VNet"]:::infra
        SUBNET["Subnet"]:::infra
        NSG["NSG"]:::infra
        PUBIP["Public IP"]:::infra
        VM["Linux VM"]:::infra
    end

    TF --> RG
    RG --> VNET
    VNET --> SUBNET
    SUBNET --> NSG
    NSG --> PUBIP
    PUBIP --> VM

    subgraph "Application Runtime (VM)"
        NGINX["NGINX Reverse Proxy (ports 80/443)"]:::net
        SSL["SSL (Let’s Encrypt/Certbot)"]:::net
        DOCKER["Tetris App Container\n(sajid79/tetris-js-app:amd64, port 8080)"]:::app
        FRONTEND["Frontend Assets\n(dist/ & src/)"]:::app
    end

    VM --> NGINX
    NGINX --> DOCKER
    DOCKER --> FRONTEND
    NGINX --> SSL

    subgraph "CI/CD Pipeline"
        GHA["GitHub Actions"]:::automation
    end

    GHA -->|"deploys_updates"| VM

    subgraph "External Services"
        CF["Cloudflare DNS"]:::net
        CLIENT["Client Browser"]:::external
    end

    CLIENT -->|"DNS_lookup"| CF
    CF -->|"resolves_to"| PUBIP

    %% Click Events
    click TF "https://github.com/sohailsajid79/azure-tetris-deployment/blob/main/terraform/main.tf"
    click VM "https://github.com/sohailsajid79/azure-tetris-deployment/blob/main/terraform/vm.tf"
    click DOCKER "https://github.com/sohailsajid79/azure-tetris-deployment/tree/main/Dockerfile"
    click NGINX "https://github.com/sohailsajid79/azure-tetris-deployment/blob/main/default.conf"
    click GHA "https://github.com/sohailsajid79/azure-tetris-deployment/blob/main/.github/workflows/deploy-application.yaml"
    click FRONTEND "https://github.com/sohailsajid79/azure-tetris-deployment/tree/main/dist/"
    click FRONTEND "https://github.com/sohailsajid79/azure-tetris-deployment/tree/main/src/"

    %% Styles
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef app fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef net fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef automation fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef external fill:#E6E6FA,stroke:#333,stroke-width:2px;
```
