# tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall architecture

> Architecture diagram of the GitHub repository tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall
- Repository: https://github.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall

## Overview

##### Project type and purpose
- This is an AWS-focused Terraform project for deploying a centralized network inspection solution using AWS Network Firewall.
- It builds multiple VPCs (VPC-A, VPC-B, Security-VPC), EC2 instances, Transit Gateway attachments, NAT gateways, IGW, and Network Firewall resources to force both north-south and east-west traffic through inspection.

##### File structure
- Top-level Terraform files:
- vpc-a.tf, vpc-b.tf: define the two application VPCs, each with a private subnet in different AZs.
- security-vpc.tf: defines the “inspection” VPC with public subnets, NAT gateways, firewall subnets, and TGW subnets.
- network-firewall.tf: configures AWS Network Firewall, policy, and rule groups.
- transit-gateway.tf & ec2.tf: set up the shared Transit Gateway, attachments to each VPC, and EC2 instances.
- other files (main.tf, variables.tf, outputs.tf, *.tfvars): handle variables, providers, outputs, and environment-specific values.

##### Extract architecture insights from the README
- Two EC2 instances (Server-A in VPC-A, Server-B in VPC-B) must have Internet access and have their inter-VPC traffic inspected.
- A Security-VPC contains:
- Internet Gateway (IGW) & public subnets
- Two NAT Gateways (one per AZ)
- Two AWS Network Firewall subnets (one per AZ)
- Two Transit Gateway subnets (one per AZ)
- Transit Gateway with three attachments (one to each VPC) and associated route tables ensure that all traffic is routed through the firewall.

##### Main components & relationships
a. Components to represent:
- Security-VPC
– IGW + Public Subnets
– NAT Gateways (in public subnets)
– Network Firewall endpoints (in firewall subnets across AZs)
– Transit Gateway subnets & attachments
- Transit Gateway (global symbol)
- VPC-A & VPC-B (each with a private subnet and an EC2)
- EC2 Instances (Server-A, Server-B)
b. Relationships / flows:
- North-South: Internet → IGW → NAT GW → TGW → Firewall Endpoints → TGW → Private Subnet → EC2 → reverse path.
- East-West: EC2 in VPC-A → Private Route Table → TGW → Firewall Endpoints → TGW → Private Subnet in VPC-B → EC2.
c. Architectural patterns / principles:
- Hub-and-spoke: Security-VPC is the “hub” containing shared services (firewall, NAT, IGW); VPC-A and VPC-B are “spokes.”
- Transit Gateway enforces central routing.
- Multi-AZ redundancy: two firewall endpoints and two NAT gateways.
d. Key technologies / Terraform modules:
- aws_vpc, aws_subnet, aws_internet_gateway, aws_nat_gateway
- aws_networkfirewall_firewall, aws_networkfirewall_firewall_policy
- aws_ec2_instance, aws_ec2_iam_instance_profile
- aws_ec2_transit_gateway, aws_ec2_transit_gateway_vpc_attachment

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Internet
    Internet["Public Internet"]:::internet

    %% Security VPC Hub
    subgraph "Security-VPC" 
        click SecurityVPC "https://github.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall/blob/main/security-vpc.tf"
        subgraph "AZ-A"
            IGW_AA["Internet Gateway"]:::service
            NAT_AA["NAT Gateway"]:::service
            TGWENI_AA["TGW ENI"]:::tgw
            FW_EP_AA["Firewall Endpoint"]:::firewall
        end
        subgraph "AZ-B"
            IGW_AB["Internet Gateway"]:::service
            NAT_AB["NAT Gateway"]:::service
            TGWENI_AB["TGW ENI"]:::tgw
            FW_EP_AB["Firewall Endpoint"]:::firewall
        end
    end

    %% Transit Gateway
    TransitGW["Transit Gateway"]:::tgw
    click TransitGW "https://github.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall/blob/main/transit-gateway.tf"

    %% VPC A Spoke
    subgraph "VPC-A" 
        click VPC_A "https://github.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall/blob/main/vpc-a.tf"
        PrivateA["Private Subnet"]:::subnet
        ServerA["Server-A EC2"]:::instance
        click ServerA "https://github.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall/blob/main/ec2.tf"
    end

    %% VPC B Spoke
    subgraph "VPC-B"
        click VPC_B "https://github.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall/blob/main/vpc-b.tf"
        PrivateB["Private Subnet"]:::subnet
        ServerB["Server-B EC2"]:::instance
        click ServerB "https://github.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall/blob/main/ec2.tf"
    end

    %% North-South Traffic (blue)
    Internet -->|"North-South"| IGW_AA
    IGW_AA --> NAT_AA
    NAT_AA --> TransitGW
    TransitGW --> FW_EP_AA
    FW_EP_AA --> TransitGW
    TransitGW --> PrivateA
    PrivateA --> ServerA

    Internet -->|"North-South"| IGW_AB
    IGW_AB --> NAT_AB
    NAT_AB --> TransitGW
    TransitGW --> FW_EP_AB
    FW_EP_AB --> TransitGW
    TransitGW --> PrivateB
    PrivateB --> ServerB

    %% East-West Traffic (red)
    ServerA -->|"East-West"| TransitGW
    TransitGW --> FW_EP_AA
    FW_EP_AA --> TransitGW
    TransitGW --> PrivateB
    PrivateB --> ServerB

    %% Root Terraform Config
    RootConfig["Terraform Root"]:::config
    click RootConfig "https://github.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall/blob/main/main.tf"
    Variables["Variables Definitions"]:::config
    click Variables "https://github.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall/blob/main/variables.tf"
    TFVars["Env Variables"]:::config
    click TFVars "https://github.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall/blob/main/terraform.tfvars"
    Outputs["Outputs"]:::config
    click Outputs "https://github.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall/blob/main/outputs.tf"
    FirewallCode["AWS Network Firewall"]:::firewall
    click FirewallCode "https://github.com/tunlyinaung0/centralized-traffic-inspection-with-awsnetworkfirewall/blob/main/network-firewall.tf"

    %% Config relations
    RootConfig --> Variables
    RootConfig --> TFVars
    RootConfig --> Outputs
    RootConfig --> FirewallCode
    RootConfig --> TransitGW

    %% Classes
    classDef internet fill:#81C784,stroke:#388E3C,color:#000
    classDef service fill:#64B5F6,stroke:#1976D2,color:#000
    classDef tgw fill:#FFB74D,stroke:#F57C00,color:#000
    classDef firewall fill:#E57373,stroke:#D32F2F,color:#000
    classDef subnet fill:#E0E0E0,stroke:#9E9E9E,color:#000
    classDef instance fill:#BA68C8,stroke:#7B1FA2,color:#000
    classDef config fill:#FFF176,stroke:#FBC02D,color:#000
```
