# nicolgit/hub-and-spoke-playground architecture

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

- Interactive diagram: https://gitdiagram.com/nicolgit/hub-and-spoke-playground
- Repository: https://github.com/nicolgit/hub-and-spoke-playground

## Overview

##### Project Type and Purpose
- This is an **infrastructure-as-code** repository for deploying Azure hub-and-spoke network topologies and on-premise simulations. It uses ARM/Bicep templates to spin up VNets, subnets, firewalls, gateways, VMs, and optional services.
- The README describes multiple “playgrounds” (hub-01, hub-02, on-prem, on-prem-2, any-to-any routing, S2S VPN) plus dozens of step-by-step network scenarios.

##### High-Level File Structure & Architectural Patterns
- Top-level directories:
- **hub-01-bicep**, **hub-02-bicep**, **on-prem-bicep**, **on-prem-2-bicep**, **any-to-any-bicep**, **s2s-vpn-bicep** (each contains Bicep/JSON templates for a single network deployment).
- **scenarios** (Markdown docs with configuration steps for each network scenario).
- Architecture pattern: **Hub-and-Spoke** (central “hub” VNet hosting shared services & inspection, multiple “spoke” VNets, plus simulated on-prem VNets connected via VPN Gateway).
- Infrastructure defined declaratively (Bicep → ARM JSON), emphasizing repeatable, parameterized deployments.

##### Key Components
a. **Azure Virtual Networks**
- hub-lab-net / hub-lab-02-net (hub VNets, each with subnets: default, AzureFirewallSubnet, AzureBastionSubnet, GatewaySubnet)
- spoke-0x VNets (each with two subnets for VMs)
- on-prem-net / on-prem-2-net (simulated on-prem VNets, each with default, Bastion, Gateway subnets)
b. **Network Appliances & Services**
- **Azure Firewall Premium/Standard** in its subnet
- **Azure Bastion** in its subnet (secure SSH/RDP jumpbox)
- **Azure VPN Gateway** in GatewaySubnet (handles vNet-to-vNet or site-to-site IPSec connections)
- **Application Gateway**, **API Management**, **Azure OpenAI**, **Elastic SAN** (optional services deployed in specific scenarios)
c. **Compute**
- VMs in each spoke (Windows Server or Linux) and in on-prem nets (w10-onprem-vm, lin-onprem-vm)
d. **Routing & Policies**
- UDRs & route tables (e.g., any-to-any routing, forced-tunnel to Azure Firewall)
- Azure Firewall policies and IP Groups

##### Interactions & Data Flows
- **IPSec tunnels** or **vNet-to-vNet gateway connections** between on-prem VNets and hub VNet.
- **user/SSH/RDP** traffic flowing through Bastion into VMs.
- Outbound traffic from spokes routed to Azure Firewall, then to Internet or on-prem.

##### Architectural Patterns & Principles
- **Separation of Concerns**: isolate shared services (firewall, bastion, gateway) in hub; workloads in spokes.
- **Least Privilege**: route only required traffic through inspection points (Azure Firewall policies).
- **Scalability & Modularity**: parameterized Bicep modules for hub, spoke, on-prem, enabling reuse.
- **Idempotence & Repeatability**: declarative templates ensure consistent deployments across subscriptions/regions.

## Diagram (Mermaid)

```mermaid
flowchart LR
    subgraph "On-Premise" 
        direction TB
        OnpremNet["on-prem-net (VNet)"]:::onprem
        OnPrem_Default["default subnet"]:::onprem
        OnPrem_BastionSubnet["AzureBastionSubnet"]:::shared
        OnPrem_GatewaySubnet["GatewaySubnet"]:::shared
        w10_onprem_vm["w10-onprem-vm"]:::onprem
        lin_onprem_vm["lin-onprem-vm"]:::onprem
        OnpremNet --> OnPrem_Default
        OnpremNet --> OnPrem_BastionSubnet
        OnpremNet --> OnPrem_GatewaySubnet
        OnPrem_Default --> w10_onprem_vm
        OnPrem_Default --> lin_onprem_vm
        OnPrem_BastionSubnet -->|"SSH/RDP"| w10_onprem_vm
        OnPrem_GatewaySubnet -->|IPSec Tunnel| Hub_GatewaySubnet
    end

    subgraph "Hub" 
        direction TB
        HubNet["hub-lab-net (VNet)"]:::hub
        Hub_Default["default subnet"]:::hub
        Hub_FirewallSubnet["AzureFirewallSubnet"]:::shared
        Hub_BastionSubnet["AzureBastionSubnet"]:::shared
        Hub_GatewaySubnet["GatewaySubnet"]:::shared
        HubNet --> Hub_Default
        HubNet --> Hub_FirewallSubnet
        HubNet --> Hub_BastionSubnet
        HubNet --> Hub_GatewaySubnet
        Hub_FirewallSubnet --> AzureFirewall["Azure Firewall"]:::shared
        Hub_BastionSubnet --> AzureBastion["Azure Bastion"]:::shared
        Hub_GatewaySubnet --> VPN_Gateway["Azure VPN Gateway"]:::shared
    end

    subgraph "Spokes" 
        direction TB
        SpokeNet1["spoke-01-net (VNet)"]:::spoke
        Spoke_Default1["default subnet"]:::spoke
        spoke01_vm["spoke-01-vm"]:::spoke
        SpokeNet1 --> Spoke_Default1
        Spoke_Default1 --> spoke01_vm

        SpokeNet2["spoke-02-net (VNet)"]:::spoke
        Spoke_Default2["default subnet"]:::spoke
        spoke02_vm["spoke-02-vm"]:::spoke
        SpokeNet2 --> Spoke_Default2
        Spoke_Default2 --> spoke02_vm
    end

    %% Peering and Tunnels
    HubNet -.->|VNet Peering| SpokeNet1
    HubNet -.->|VNet Peering| SpokeNet2

    %% Any-to-Any Routing & Firewall Policy
    AnyToAny["any-to-any routing"]:::policy
    Hub_Default -->|UDR| AnyToAny -->|route to| Hub_FirewallSubnet

    %% S2S VPN Connectivity
    connectOnPremTunnel["S2S VPN (Hub↔On-Prem)"]:::shared
    OnPrem_GatewaySubnet -.-> connectOnPremTunnel
    connectOnPremTunnel -.-> Hub_GatewaySubnet

    %% Click Events
    click HubNet "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/hub-01-bicep/hub-01.bicep"
    click HubNet "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/hub-01-bicep/hub-01.json"
    click SpokeNet1 "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/hub-02-bicep/hub-02.bicep"
    click SpokeNet1 "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/hub-02-bicep/hub-02.json"
    click OnpremNet "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/on-prem-bicep/on-prem.bicep"
    click OnpremNet "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/on-prem-bicep/on-prem.json"
    click OnpremNet "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/on-prem-2-bicep/on-prem-2.bicep"
    click OnpremNet "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/on-prem-2-bicep/on-prem-2.json"
    click AnyToAny "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/any-to-any-bicep/any-to-any.bicep"
    click AnyToAny "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/any-to-any-bicep/any-to-any.json"
    click AnyToAny "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/any-to-any-bicep/fw-policy.bicep"
    click connectOnPremTunnel "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/s2s-vpn-bicep/connect-on-prem.bicep"
    click connectOnPremTunnel "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/s2s-vpn-bicep/connect-on-prem.json"
    click connectOnPremTunnel "https://github.com/nicolgit/hub-and-spoke-playground/blob/main/s2s-vpn-bicep/connect-gateways-bgp-to-be-verified.bicep"

    classDef hub fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef spoke fill:#98FB98,stroke:#000,stroke-width:1px
    classDef onprem fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef shared fill:#FFA500,stroke:#000,stroke-width:1px
    classDef policy fill:#FF6347,stroke:#000,stroke-width:1px
```
