# shivik0505/redis_demo architecture

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

- Interactive diagram: https://gitdiagram.com/shivik0505/redis_demo
- Repository: https://github.com/shivik0505/redis_demo

## Overview

##### Project Type & Purpose
- This is an Infrastructure-as-Code (IaC) project that automates deployment of a Redis cluster on AWS.
- Uses Terraform to provision AWS networking and compute resources, Ansible to configure Redis, and Jenkins/CLI scripts for CI/CD.

##### Key Components to Model
A. AWS Network Layout
– Custom VPC (10.0.0.0/16)
– Public Subnet (10.0.1.0/24) hosting Bastion Host
– Private Subnets (10.0.2.0/24, 10.0.3.0/24, 10.0.4.0/24) each in a different AZ, hosting Redis nodes
– Internet Gateway (IGW) behind the public subnet
– NAT Gateway in the public subnet providing egress for private subnets
– Route Tables for public and private subnets
– VPC Peering connection to an optional remote VPC

B. Compute Instances
– Bastion Host (EC2, public IP)
– Redis Node 1, 2, 3 (EC2 in private subnets)

C. Security
– Security Group for Bastion (SSH/HTTP/ICMP open as per requirements)
– Security Group for Redis cluster (ports 6379, 16379–16384, SSH/ICMP within VPC)

D. IaC & Configuration Automation
– Terraform modules (vpc, subnets, security_group, instances, vpc_peering)
– Terraform root module invoking these and outputting instance IPs
– Ansible playbook & inventory (aws_ec2.yaml) that configures Redis on each node

E. CI/CD & Deployment
– Jenkins Pipeline (Jenkinsfile)
– deploy-infrastructure.sh & cleanup scripts
– aws_ec2.yaml (dynamic inventory)

##### Component Relationships & Data Flow
- User/CI triggers Terraform:
→ Terraform provisions AWS resources in correct order (VPC → Subnets → Security Groups → IGW/NAT → EC2).
- Terraform outputs IP addresses to stdout/`terraform output`.
- Ansible uses the AWS inventory file (aws_ec2.yaml) to SSH into Bastion, then onto Redis nodes for software installation and cluster setup.
- Jenkins job checks out the repo, runs deploy-infrastructure.sh (or terraform & ansible commands), monitors status, and can trigger destroy via parameters.

##### Architectural Patterns & Principles
- “Infrastructure as Code” pattern: All resources defined in Terraform modules, versioned in Git.
- Layered network design: Public bastion separated from private Redis nodes.
- Immutable infrastructure: EC2 instances configured at launch time via Ansible.
- High availability: Redis cluster nodes across three AZs.

##### Essential Elements Checklist
[ ] Clear labels on all AWS resources (VPC, subnets, EC2).
– Network vs. Compute vs. Automation tools
[ ] AZ markers on each private subnet.
[ ] Text notes for security group rules (port ranges).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% AWS Cloud Boundary
    subgraph "AWS Cloud" 
        style AWSCloud fill:#E0F7FA,stroke:#0288D1,stroke-width:2px
        subgraph "Custom VPC (10.0.0.0/16)"
            style VPC fill:#E1F5FE,stroke:#0277BD,stroke-width:1px
            %% Public Subnet
            subgraph "Public Subnet (10.0.1.0/24)"
                style PublicSubnet fill:#B3E5FC,stroke:#01579B,stroke-width:1px
                IGW["Internet Gateway"]:::network
                NAT["NAT Gateway"]:::network
                Bastion["Bastion Host (EC2)"]:::bastion
                IGW ---|attached to| PublicSubnet
                NAT ---|egress for| PublicSubnet
            end
            %% Private Subnets
            subgraph "Private Subnets Layer"
                style PrivateLayer fill:none,stroke:none
                subgraph "AZ1: Private Subnet (10.0.2.0/24)"
                    style AZ1 fill:#B3E5FC,stroke:#01579B
                    Redis1["Redis Node 1 (EC2)"]:::ec2
                end
                subgraph "AZ2: Private Subnet (10.0.3.0/24)"
                    style AZ2 fill:#B3E5FC,stroke:#01579B
                    Redis2["Redis Node 2 (EC2)"]:::ec2
                end
                subgraph "AZ3: Private Subnet (10.0.4.0/24)"
                    style AZ3 fill:#B3E5FC,stroke:#01579B
                    Redis3["Redis Node 3 (EC2)"]:::ec2
                end
                NAT -->|provides egress| AZ1
                NAT -->|provides egress| AZ2
                NAT -->|provides egress| AZ3
            end
            %% Route Tables
            RTPub["Route Table (Public)"]:::network
            RTPriv["Route Table (Private)"]:::network
            RTPub ---|routes to IGW| IGW
            RTPriv ---|routes via NAT| NAT
            %% VPC Peering
            VPCPeer["VPC Peering"]:::network
            VPCPeer -.->|"peer to remote VPC"| AWS_External[(External VPC)]
        end
    end

    %% External Tools & Processes
    subgraph "Automation & CI/CD"
        style Tools fill:none,stroke:none
        Terraform["Terraform Modules"]:::terraform
        Ansible["Ansible Playbook & Inventory"]:::ansible
        Jenkins["Jenkins CI/CD Pipeline"]:::jenkins
        CLI["Developer CLI"]:::cli
        DeployScript["deploy-infrastructure.sh"]:::script
        CleanupScripts["cleanup-aws-resources.sh\nquick-cleanup.sh\ncleanup-conflicts.sh"]:::script
        Keypair["create-keypair.sh"]:::script
        Inventory["aws_ec2.yaml"]:::ansible

        Jenkins -->|"Terraform apply/destroy"| Terraform
        Terraform -->|"Provision AWS Resources"| AWSCloud
        Ansible -.->|"SSH via Bastion"| Bastion
        CLI -.->|"invoke"| DeployScript
        DeployScript --> Terraform
        DeployScript --> Ansible
    end

    %% Click Events for Terraform Modules
    click TerraformRoot "https://github.com/shivik0505/redis_demo/blob/main/terraform/main.tf"
    click TerraformRoot "https://github.com/shivik0505/redis_demo/blob/main/terraform/provider.tf"
    click TerraformRoot "https://github.com/shivik0505/redis_demo/blob/main/terraform/backend.tf"
    click TerraformRoot "https://github.com/shivik0505/redis_demo/blob/main/terraform/variable.tf"
    click TerraformRoot "https://github.com/shivik0505/redis_demo/blob/main/terraform/output.tf"
    click VPCModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/vpc/main.tf"
    click VPCModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/vpc/variable.tf"
    click VPCModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/vpc/output.tf"
    click SubnetsModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/subnets/main.tf"
    click SubnetsModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/subnets/variable.tf"
    click SubnetsModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/subnets/output.tf"
    click SGModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/security_group/main.tf"
    click SGModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/security_group/variable.tf"
    click SGModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/security_group/output.tf"
    click InstancesModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/instances/main.tf"
    click InstancesModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/instances/variable.tf"
    click InstancesModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/instances/output.tf"
    click PeeringModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/vpc_peering/main.tf"
    click PeeringModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/vpc_peering/variable.tf"
    click PeeringModule "https://github.com/shivik0505/redis_demo/blob/main/terraform/vpc_peering/output.tf"

    %% Click Events for Ansible & Scripts
    click Ansible "https://github.com/shivik0505/redis_demo/blob/main/playbook.yml"
    click Ansible "https://github.com/shivik0505/redis_demo/tree/main/ansible/"
    click Inventory "https://github.com/shivik0505/redis_demo/blob/main/aws_ec2.yaml"
    click Jenkins "https://github.com/shivik0505/redis_demo/tree/main/Jenkinsfile"
    click DeployScript "https://github.com/shivik0505/redis_demo/blob/main/deploy-infrastructure.sh"
    click CleanupScripts "https://github.com/shivik0505/redis_demo/blob/main/cleanup-aws-resources.sh"
    click CleanupScripts "https://github.com/shivik0505/redis_demo/blob/main/quick-cleanup.sh"
    click CleanupScripts "https://github.com/shivik0505/redis_demo/blob/main/cleanup-conflicts.sh"
    click Keypair "https://github.com/shivik0505/redis_demo/blob/main/create-keypair.sh"

    %% Class Definitions
    classDef network fill:#FFE082,stroke:#FFA000,stroke-width:1px
    classDef ec2 fill:#CFD8DC,stroke:#90A4AE,stroke-width:1px
    classDef bastion fill:#A5D6A7,stroke:#388E3C,stroke-width:1px
    classDef terraform fill:#FFCCBC,stroke:#D84315,stroke-width:1px,stroke-dasharray: 5 2
    classDef ansible fill:#FFCCBC,stroke:#BF360C,stroke-width:1px,stroke-dasharray: 5 2
    classDef jenkins fill:#D1C4E9,stroke:#6A1B9A,stroke-width:1px
    classDef cli fill:#E0E0E0,stroke:#424242,stroke-width:1px,stroke-dasharray: 2 2
    classDef script fill:#E8F5E9,stroke:#2E7D32,stroke-width:1px

    %% Assign Terraform module nodes to variables for clicks
    class TerraformRoot,TerrraformModuleFill terraform
    class VPCModule terraform
    class SubnetsModule terraform
    class SGModule terraform
    class InstancesModule terraform
    class PeeringModule terraform
```
