# ramyadav08/three_tier_archietecture_terraform_github_action architecture

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

- Interactive diagram: https://gitdiagram.com/ramyadav08/three_tier_archietecture_terraform_github_action
- Repository: https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action

## Overview

##### Project type and purpose
- This is a three-tier web application with full Infrastructure-as-Code (IaC) using Terraform and an automated deployment pipeline via GitHub Actions.
- The three tiers are:
– Web tier: React single-page application (SPA) served by Nginx on EC2
– App tier: Node.js/Express transaction service on EC2
– Data tier: AWS RDS (e.g., MySQL) and S3 for storage

##### File structure
- Top-level CI/CD:
– .github/workflows/deploy.yaml → GitHub Action to plan/apply Terraform, build artifacts, deploy to EC2.
- Terraform-Code directory:
– main.tf, provider.tf, variables.tf, terraform.tfvars → root configuration
– modules/ → reusable modules for vpc, sg (Security Groups), ec2, iam, rds, s3
– userdata.sh → bootstraps EC2 instances (e.g., installs Docker, Nginx, Node.js)
- application-code directory:
– web-tier/ → React app (create-react-app structure: public/, src/, package.json)
– app-tier/ → Node.js service (index.js, TransactionService.js, DbConfig.js) plus nginx.conf
- app-server-commands & web-server-commands → likely remote scripts or directives for each EC2 server

##### Key insights from README
- Minimal description, but project name “three_tier_archietecture_terraform_github_action” confirms the three-tier IaC pattern + CI/CD integration.

##### Detailed capture of essential elements
- Security Groups guarding EC2 and RDS.
- IAM role associations (e.g., EC2 role → S3 access).
- Don’t omit the nginx.conf proxy between web and app.
- Terraform→Apply step in the CI/CD flow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        direction TB
        GH["GitHub Actions CI/CD Pipeline"]:::pipeline
        subgraph "Application Code"
            direction TB
            WebTier["React SPA"]:::app
            AppTier["Node.js/Express Service"]:::app
            NginxCfg["nginx.conf"]:::app
        end
        GH -->|"build & deploy code"| WebTier
        GH -->|"build & deploy code"| AppTier
        GH -->|"use nginx config"| NginxCfg
    end

    %% AWS Infrastructure
    subgraph "AWS Cloud"
        direction TB
        subgraph "Terraform Root Configuration"
            direction TB
            TFMain["main.tf"]:::aws
            TFProv["provider.tf"]:::aws
            TFVar["variables.tf"]:::aws
            TFTfvars["terraform.tfvars"]:::aws
        end
        subgraph "Terraform Modules"
            direction TB
            VPC["VPC Module"]:::aws
            SG["Security Groups Module"]:::aws
            EC2Mod["EC2 Module"]:::aws
            IAM["IAM Module"]:::aws
            RDSMod["RDS Module"]:::aws
            S3Mod["S3 Module"]:::aws
        end
        TFMain --> VPC
        TFMain --> SG
        TFMain --> EC2Mod
        TFMain --> IAM
        TFMain --> RDSMod
        TFMain --> S3Mod

        EC2Mod --> UserData["userdata.sh"]:::aws

        subgraph "VPC"
            direction TB
            subgraph "Public Subnet"
                direction TB
                WebEC2["EC2 Web Tier\n(Nginx + React)"]:::awsCompute
            end
            subgraph "Private Subnet"
                direction TB
                AppEC2["EC2 App Tier\n(Node.js/Express)"]:::awsCompute
                RDS["RDS (MySQL)"]:::db
            end
        end

        S3["S3 Bucket"]:::storage
        WebEC2 -->|"API calls"| AppEC2
        AppEC2 -->|"CRUD operations"| RDS
        AppEC2 -->|"S3 access via IAM role"| S3
    end

    %% User and Deployment Flow
    Browser["Client Browser"]:::external
    Browser -->|"HTTPS"| WebEC2
    GH -->|"provision infra"| TFMain

    %% Server Commands
    WebServerCmd["Web Server Commands"]:::aws
    AppServerCmd["App Server Commands"]:::aws
    EC2Mod --> WebServerCmd
    EC2Mod --> AppServerCmd

    %% Click Events
    click GH "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/blob/main/.github/workflows/deploy.yaml"
    click TFMain "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/blob/main/Terraform-Code/main.tf"
    click TFProv "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/blob/main/Terraform-Code/provider.tf"
    click TFVar "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/blob/main/Terraform-Code/variables.tf"
    click TFTfvars "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/blob/main/Terraform-Code/terraform.tfvars"
    click VPC "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/tree/main/Terraform-Code/modules/vpc"
    click SG "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/tree/main/Terraform-Code/modules/sg"
    click EC2Mod "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/tree/main/Terraform-Code/modules/ec2"
    click IAM "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/tree/main/Terraform-Code/modules/iam"
    click RDSMod "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/tree/main/Terraform-Code/modules/rds"
    click S3Mod "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/tree/main/Terraform-Code/modules/s3"
    click UserData "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/blob/main/Terraform-Code/modules/ec2/userdata.sh"
    click WebTier "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/tree/main/application-code/web-tier"
    click AppTier "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/tree/main/application-code/app-tier"
    click NginxCfg "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/blob/main/application-code/nginx.conf"
    click WebServerCmd "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/tree/main/web-server-commands"
    click AppServerCmd "https://github.com/ramyadav08/three_tier_archietecture_terraform_github_action/tree/main/app-server-commands"

    %% Styles
    classDef pipeline fill:#f39c12,stroke:#e67e22,color:#fff;
    classDef aws fill:#3498db,stroke:#2980b9,color:#fff;
    classDef awsCompute fill:#5dade2,stroke:#2980b9,color:#fff;
    classDef app fill:#2ecc71,stroke:#27ae60,color:#fff;
    classDef db fill:#9b59b6,stroke:#8e44ad,color:#fff;
    classDef storage fill:#1abc9c,stroke:#16a085,color:#fff;
    classDef external fill:#ecf0f1,stroke:#bdc3c7,color:#2c3e50;
```
