# skills/deploy-to-azure architecture

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

- Interactive diagram: https://gitdiagram.com/skills/deploy-to-azure
- Repository: https://github.com/skills/deploy-to-azure

## Overview

##### Project Type and Purpose
- This repository is neither a monolithic web app nor a microservice—it's a DevOps tutorial template that shows how to package a simple JavaScript “game” (static HTML/CSS/JS) into a Docker container and deploy it to Azure using GitHub Actions.
- The “app” itself lives under `src/`, `public/`, and is bundled via `webpack.config.js`. A simple test suite in `__test__` validates game logic.

##### Key Components (based on file tree and README)
a. Source Code
- Frontend assets: `index.html`, `public/index.css`
- Game logic / bundling: `src/index.js`, `src/game.js`, `webpack.config.js`
- Optional serverless handler: `handler.js` (could be demo for Azure Function)
- Tests: `__test__/game.test.js` + snapshots
b. CI/CD Pipelines
- Workflow definitions: `.github/workflows/0-welcome.yml` → `.github/workflows/6-destroy-azure-environment.yml`
- Step-by-step markdown guides in `.github/steps/`
c. Containerization
- `Dockerfile` builds the app into a container image
d. Deployment Targets
- Azure staging environment (Resource Group, Web App or Container Instance)
- Azure production environment
- Teardown job to destroy infra at the end

##### Relationships & Interactions
- Developer pushes code to GitHub → triggers GitHub Actions
- Actions runner executes jobs in sequence:
1. **Configure** jobs based on labels
2. **Setup** Azure credentials (via `azure/login` action)
3. **Build** with Node.js & Webpack → produce static bundle or Docker image
4. **Publish** Docker image to Azure Container Registry (if using container)
5. **Deploy** to staging Web App / Container Instance
6. On merge to `main`, **Deploy** to production
7. **Destroy** staging infra when finished
- Tests (`jest`) run before build to ensure code quality.

##### Architectural Patterns & Design Principles
- **Separation of Concerns**:
- Source code vs. CI/CD logic (code in `src/`, workflows in `.github/`)
- Staging vs. Production environments
- **Infrastructure as Code** via GitHub Actions & Azure CLI
- **Immutable Deployments**: Docker image built once and promoted from staging to prod

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actors
    Dev["Developer Push"]:::actor

    %% GitHub Repository Code Components
    subgraph "GitHub Repository"
        direction TB
        HTML["index.html"]:::code
        CSS["public/index.css"]:::code
        JSIndex["src/index.js"]:::code
        GameJS["src/game.js"]:::code
        Webpack["src/webpack.config.js"]:::code
        Handler["handler.js"]:::code
        Test["__test__/game.test.js"]:::code
        Snap["__test__/__snapshots__/game.test.js.snap"]:::code
        Dockerfile["Dockerfile"]:::code
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        direction TB
        Welcome["0-welcome.yml"]:::ci
        Config["1-configure-label-based-job.yml"]:::ci
        Setup["2-setup-azure-environment.yml"]:::ci
        Spinup["3-spinup-environment.yml"]:::ci
        TestStep["Run Jest Tests"]:::ci
        Build["Build with Node.js & Webpack"]:::ci
        PublishImage["Publish Docker Image to ACR"]:::ci
        DeployStg["4-deploy-to-staging-environment.yml"]:::ci
        DeployProd["5-deploy-to-prod-environment.yml"]:::ci
        Destroy["6-destroy-azure-environment.yml"]:::ci
        Guides["CI/CD Step Guides"]:::ci
    end

    %% Azure Staging
    subgraph "Azure Staging"
        direction TB
        ACR["Azure Container Registry"]:::azure
        StgRG["Staging Resource Group"]:::azure
        StgApp["Staging Web App"]:::azure
    end

    %% Azure Production
    subgraph "Azure Production"
        direction TB
        ProdRG["Production Resource Group"]:::azure
        ProdApp["Production Web App"]:::azure
    end

    %% Data Flows
    Dev -->|"1. Push to GitHub"| Welcome
    Welcome -->|"2. Configure Jobs"| Config
    Config -->|"3. Setup Azure Credentials"| Setup
    Setup -->|"4. Provision Environment"| Spinup
    Spinup -->|"5. Run Tests"| TestStep
    TestStep -->|"6. Bundle Code"| Build
    Build -->|"7. Publish Image"| PublishImage
    PublishImage -->|"to ACR"| ACR
    PublishImage --> DeployStg
    DeployStg --> ACR
    DeployStg -->|"Deploy to Staging"| StgApp
    DeployStg --> StgRG
    DeployProd -->|"Deploy to Production"| ProdApp
    DeployProd --> ProdRG
    Destroy -->|"Teardown Staging"| StgRG

    %% Merge to main triggers production
    DeployStg -->|"merge to main"| DeployProd

    %% Guides reference
    Welcome --> Guides
    Config --> Guides
    Setup --> Guides
    Spinup --> Guides
    DeployStg --> Guides
    DeployProd --> Guides
    Destroy --> Guides

    %% Click Events for Code Components
    click HTML "https://github.com/skills/deploy-to-azure/blob/main/index.html"
    click CSS "https://github.com/skills/deploy-to-azure/blob/main/public/index.css"
    click JSIndex "https://github.com/skills/deploy-to-azure/blob/main/src/index.js"
    click GameJS "https://github.com/skills/deploy-to-azure/blob/main/src/game.js"
    click Webpack "https://github.com/skills/deploy-to-azure/blob/main/src/webpack.config.js"
    click Handler "https://github.com/skills/deploy-to-azure/blob/main/handler.js"
    click Test "https://github.com/skills/deploy-to-azure/blob/main/__test__/game.test.js"
    click Snap "https://github.com/skills/deploy-to-azure/blob/main/__test__/__snapshots__/game.test.js.snap"
    click Dockerfile "https://github.com/skills/deploy-to-azure/tree/main/Dockerfile"

    %% Click Events for CI/CD Workflows
    click Welcome "https://github.com/skills/deploy-to-azure/blob/main/.github/workflows/0-welcome.yml"
    click Config "https://github.com/skills/deploy-to-azure/blob/main/.github/workflows/1-configure-label-based-job.yml"
    click Setup "https://github.com/skills/deploy-to-azure/blob/main/.github/workflows/2-setup-azure-environment.yml"
    click Spinup "https://github.com/skills/deploy-to-azure/blob/main/.github/workflows/3-spinup-environment.yml"
    click DeployStg "https://github.com/skills/deploy-to-azure/blob/main/.github/workflows/4-deploy-to-staging-environment.yml"
    click DeployProd "https://github.com/skills/deploy-to-azure/blob/main/.github/workflows/5-deploy-to-prod-environment.yml"
    click Destroy "https://github.com/skills/deploy-to-azure/blob/main/.github/workflows/6-destroy-azure-environment.yml"

    %% Click Event for Guides Directory
    click Guides "https://github.com/skills/deploy-to-azure/tree/main/.github/steps/"

    %% Styles
    classDef code fill:#ADD8E6,stroke:#000
    classDef ci fill:#90EE90,stroke:#000
    classDef azure fill:#FFA500,stroke:#000
    classDef actor fill:#D3D3D3,stroke:#000
```
