# csye-6225-spring-2025/webapp architecture

> Architecture diagram of the GitHub repository csye-6225-spring-2025/webapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/csye-6225-spring-2025/webapp
- Repository: https://github.com/csye-6225-spring-2025/webapp

## Overview

##### Project Type & Purpose
- This is a cloud-native, full-stack web application (“webapp”) built with Node.js/Express on the backend and a Webpack-bundled frontend.
- It provides real-time health metric tracking and analytics, secure user sessions (JWT), and persists data in MySQL (Sequelize ORM).
- Designed for multi-cloud (AWS EC2 Auto-Scaling Group + GCP Compute), with immutable infrastructure via Packer, Terraform provisioning, and CI/CD via GitHub Actions.

##### File Structure & Architectural Clues
- Root: index.js (Express app entry point), webpack.config.js (frontend build), packer.pkr.hcl (AMI builds), CI workflows (.github/workflows).
- /routes: HTTP API layers (fileRoutes.js, healthz.js).
- /models: Sequelize models (FileMetadata, HealthCheck).
- /utils: Logging (CloudWatch agent integration) & metrics instrumentation.
- /config: Environment and service configuration (config.json).
- /tests: Integration tests (invoked in CI).
- deploy scripts: setup_application.sh, install_dependencies.sh.
- Monitoring: amazon-cloudwatch-agent.json for node-level logs/metrics shipping.
- Artifact pipeline: webapp.zip in /artifact, produced by Webpack & CI.

##### Key Architectural Patterns & Components
- Separation of concerns (controllers/routes, models, utilities).
- Stateless, horizontally scalable Express instances behind a load balancer.
- Packer-built golden images for AWS AMI & GCP Compute.
- Terraform-managed networking (VPC), compute (EC2, GCE), database (RDS MySQL), and storage (S3).
- GitHub Actions pipelines: lint/test → packer build → Terraform apply → deploy.
- Centralized logging & metrics via AWS CloudWatch.
- JWT/session layer for security; secrets via .env and AWS Secrets Manager.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients" 
        direction TB
        Clients["Web/Mobile Clients"]:::client
    end

    Clients -->|"HTTPS"| DNS["Route53 & ACM"]:::client

    %% AWS Cloud
    subgraph "AWS Cloud" 
        direction TB
        LB["AWS ALB"]:::compute
        subgraph "Auto-Scaling Group"
            direction TB
            ExprAWS["Express App"]:::compute
            subgraph "App Code"
                direction TB
                Index["index.js"]:::compute
                FileRoutes["fileRoutes.js"]:::compute
                Healthz["healthz.js"]:::compute
                FileModel["FileMetadata.js"]:::data
                HealthModel["HealthCheck.js"]:::data
                Config["config.json"]:::devops
                Logger["logger.js"]:::devops
                Metrics["metrics.js"]:::devops
            end
        end
        RDS["RDS MySQL"]:::data
        S3["S3 Bucket"]:::data
        CW["CloudWatch"]:::devops
        SM["Secrets Manager"]:::devops

        DNS --> LB
        LB --> ExprAWS
        ExprAWS -->|"Sequelize DB Query"| RDS
        ExprAWS -->|"File Upload"| S3
        ExprAWS -->|"Log/Metric Stream"| CW
        ExprAWS -->|"Fetch Secrets"| SM
        ExprAWS --> Index
        ExprAWS --> FileRoutes
        ExprAWS --> Healthz
        ExprAWS --> FileModel
        ExprAWS --> HealthModel
        ExprAWS --> Config
        ExprAWS --> Logger
        ExprAWS --> Metrics
    end

    %% GCP Cloud
    subgraph "GCP Cloud"
        direction TB
        LB2["GCP Load Balancer"]:::compute
        subgraph "Instance Group"
            direction TB
            ExprGCP["Express App"]:::compute
        end
        LB2 --> ExprGCP
        ExprGCP -->|"Sequelize DB Query"| RDS
        ExprGCP -->|"Log/Metric Stream"| CW
        ExprGCP -->|"Fetch Secrets"| SM
    end

    DNS --> LB2

    %% CI/CD Pipeline
    subgraph "CI/CD (GitHub Actions)"
        direction TB
        GH["GitHub Actions"]:::devops
        Tests["Integration Tests"]:::devops
        Pack["Packer Build"]:::devops
        PkTest["Packer Validation"]:::devops
        TF["Terraform Apply"]:::devops
        Webpack["Webpack Build"]:::devops
        Artifact["webapp.zip"]:::devops
        Scripts["Deploy Scripts"]:::devops
        CWAgent["amazon-cloudwatch-agent.json"]:::devops

        GH -->|run tests| Tests
        GH -->|build AMI| Pack
        GH -->|validate AMI| PkTest
        GH -->|provision infra| TF
        GH -->|bundle frontend| Webpack
        Webpack --> Artifact
        GH -->|deploy scripts| Scripts
        ExprAWS -->|install agent| CWAgent
        ExprGCP -->|install agent| CWAgent
    end

    %% Styles
    classDef client fill:#AEDFF7,stroke:#333,stroke-width:1px
    classDef compute fill:#D5F5E3,stroke:#333,stroke-width:1px
    classDef data fill:#F9E79F,stroke:#333,stroke-width:1px
    classDef devops fill:#D5D8DC,stroke:#333,stroke-width:1px

    %% Click Events
    click Index "https://github.com/csye-6225-spring-2025/webapp/blob/main/index.js"
    click FileRoutes "https://github.com/csye-6225-spring-2025/webapp/blob/main/routes/fileRoutes.js"
    click Healthz "https://github.com/csye-6225-spring-2025/webapp/blob/main/routes/healthz.js"
    click FileModel "https://github.com/csye-6225-spring-2025/webapp/blob/main/models/FileMetadata.js"
    click HealthModel "https://github.com/csye-6225-spring-2025/webapp/blob/main/models/HealthCheck.js"
    click Config "https://github.com/csye-6225-spring-2025/webapp/blob/main/config/config.json"
    click Logger "https://github.com/csye-6225-spring-2025/webapp/blob/main/utils/logger.js"
    click Metrics "https://github.com/csye-6225-spring-2025/webapp/blob/main/utils/metrics.js"
    click Pack "https://github.com/csye-6225-spring-2025/webapp/blob/main/.github/workflows/packer-ci.yml"
    click PkTest "https://github.com/csye-6225-spring-2025/webapp/blob/main/.github/workflows/packer-test.yml"
    click Webpack "https://github.com/csye-6225-spring-2025/webapp/blob/main/.github/workflows/webpack.yml"
    click Pack "https://github.com/csye-6225-spring-2025/webapp/blob/main/packer.pkr.hcl"
    click Scripts "https://github.com/csye-6225-spring-2025/webapp/blob/main/install_dependencies.sh"
    click Scripts "https://github.com/csye-6225-spring-2025/webapp/blob/main/setup_application.sh"
    click CWAgent "https://github.com/csye-6225-spring-2025/webapp/blob/main/amazon-cloudwatch-agent.json"
    click Tests "https://github.com/csye-6225-spring-2025/webapp/blob/main/tests/integration.test.js"
    click Artifact "https://github.com/csye-6225-spring-2025/webapp/blob/main/artifact/webapp.zip"
```
