# zxkane/snat architecture

> Architecture diagram of the GitHub repository zxkane/snat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zxkane/snat
- Repository: https://github.com/zxkane/snat

## Overview

##### Main Components

a) Core Components:
- VPC (as input/integration point)
- NAT Instances (in Public Subnets)
- Route Tables
- Supported External Services (GitHub, Google, Cloudflare)

b) Implementation Components:
- CDK Construct Layer
- Runtime Components (Shell Scripts)
- Configuration Management

##### Specific Elements

a) Components:
- Use rectangles for AWS resources (VPC, NAT instances, Route Tables)
- Use hexagons for external services (GitHub, Google, Cloudflare)
- Use rounded rectangles for construct components

b) Connections:

- Blue: AWS resources
- Green: Construct components
- Gray: External services
- Yellow: Configuration elements

##### Important Relationships to Highlight

- How the construct integrates with existing VPC
- Demonstrate the relationship between NAT instances and route tables
- Traffic flow patterns to external services
- Initialization process using shell scripts

##### Technical Details to Note

- Amazon Linux 2 AMI usage
- Public subnet placement
- Integration points with NAT gateways
- Route table modification flow

- The ability to work alongside NAT gateways
- Selective traffic routing capabilities
- Integration with existing VPC infrastructure
- Runtime configuration through shell scripts

Remember to include version information and any relevant AWS service quotas that might affect the deployment.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Consumer
        CDKStack["CDK Stack"]
        ExistingVPC["Existing VPC"]
    end

    subgraph ConstructLayer
        SimpleNAT["SimpleNAT Construct"]:::construct
        ConfigMgmt["Configuration Management"]:::config
        InstanceMgmt["Instance Management"]:::construct
        RouteMgmt["Route Management"]:::construct
    end

    subgraph RuntimeLayer
        NATConfig["NAT Configuration"]:::runtime
        ShellScripts["Shell Scripts"]:::runtime
        SystemDService["SystemD Service"]:::runtime
    end

    subgraph NetworkLayer
        PublicSubnets["Public Subnets"]:::network
        RouteTable["Route Tables"]:::network
        NATInstances["NAT Instances"]:::network
    end

    subgraph ExternalServices
        GitHub["GitHub"]:::external
        Google["Google"]:::external
        Cloudflare["Cloudflare"]:::external
    end

    %% Connections
    CDKStack --> SimpleNAT
    ExistingVPC --> SimpleNAT
    SimpleNAT --> ConfigMgmt
    SimpleNAT --> InstanceMgmt
    SimpleNAT --> RouteMgmt
    InstanceMgmt --> NATInstances
    RouteMgmt --> RouteTable
    ConfigMgmt -.-> NATConfig
    NATConfig --> ShellScripts
    ShellScripts --> SystemDService
    NATInstances --> PublicSubnets
    RouteTable -.-> NATInstances
    NATInstances -.-> GitHub
    NATInstances -.-> Google
    NATInstances -.-> Cloudflare

    %% Click Events
    click SimpleNAT "https://github.com/zxkane/snat/blob/main/src/index.ts"
    click ShellScripts "https://github.com/zxkane/snat/blob/main/src/snat.sh"
    click SystemDService "https://github.com/zxkane/snat/blob/main/src/snat.service"
    click CDKStack "https://github.com/zxkane/snat/blob/main/example/src/main.ts"

    %% Styling
    classDef construct fill:#90EE90,stroke:#333,stroke-width:2px
    classDef config fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef runtime fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef network fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Construct Component"]:::construct
        L2["Configuration"]:::config
        L3["Runtime Component"]:::runtime
        L4["Network Resource"]:::network
        L5["External Service"]:::external
        L6["--> Direct Dependency"]
        L7["-.-> Runtime Flow"]
    end
```
