Skip to content

Maheshroy50/mean-stack-app

Repository files navigation

MEAN Stack Dockerized Application

This is a full-stack CRUD application built with the MEAN stack (MongoDB, Express, Angular 15, Node.js). It has been fully Dockerized, optimized for production, and includes a complete CI/CD pipeline for deployment to AWS.

Features

  • Full Stack: Angular 15 Frontend + Node.js/Express Backend + MongoDB
  • Dockerized:
    • Multi-stage builds for smaller images.
    • Non-root user execution for security.
    • Production-grade Nginx configuration.
    • Docker Compose orchestration with healthchecks.
  • CI/CD Pipeline:
    • Automated Linting (ESLint).
    • Security Scanning (Trivy) for container vulnerabilities.
    • Automated Build & Push to Docker Hub.
    • Automated Deployment to AWS EC2.
  • Code Quality:
    • Integrated ESLint for both Frontend and Backend.
    • Standardized code style.

🏗️ Infrastructure Provisioning (Terraform)

You can provision the entire AWS infrastructure (VPC, Security Groups, EC2) automatically using Terraform.

Prerequisites

  1. AWS CLI installed and configured (aws configure).
  2. Terraform installed.
  3. SSH Key Pair: Create a key pair named mean-stack-key in your AWS Console (us-east-1)

Steps

  1. Navigate to the directory:

    cd terraform
  2. Initialize Terraform:

    terraform init
  3. Preview Changes:

    terraform plan
  4. Apply Infrastructure:

    terraform apply

    Type yes when prompted.

  5. Access Your Instance: After a successful apply, Terraform will output the Public IP and the SSH command.

    ssh -i mean-stack-key.pem ubuntu@<PUBLIC_IP>

☁️ Architecture & Deployment

For a detailed breakdown of the AWS Architecture (including VPC, Public Subnets, and Security Groups) and the CI/CD Pipeline, please refer to AWS_ARCHITECTURE.md.

Infrastructure Highlights

  • Custom VPC: Production-grade network isolation.
  • Public Subnet: Securely hosts the application gateway.
  • Security Groups: Firewall rules allowing HTTP and SSH access from anywhere.

CI/CD Pipeline Overview

The GitHub Actions workflow (.github/workflows/deploy.yml) performs the following:

  1. Lint: Checks code quality.
  2. Build & Scan: Builds Docker images and scans them for vulnerabilities using Trivy.
  3. Push: Pushes safe images to Docker Hub.
  4. Deploy: Connects to the AWS EC2 instance and updates the containers.

Secrets Configuration

To use the pipeline, configure the following GitHub Secrets:

  • DOCKER_USERNAME: Your Docker Hub username.
  • DOCKER_PASSWORD: Docker Access Token
  • EC2_HOST: Public IP of your EC2 instance.
  • EC2_USER: ubuntu
  • EC2_SSH_KEY: Your private SSH key.

🔍 Linting & Code Quality

We use ESLint to maintain code quality.

  • Run Backend Lint:
    cd backend
    npm run lint
  • Run Frontend Lint:
    cd frontend
    npm run lint

Screenshots

CI/CD Configuration and Execution

CI/CD Pipeline Execution

Docker Image Build and Push Process

Docker Build and Push

Application Deployment and Working UI

Application UI

Nginx Setup

Infrastructure Details

Monitoring

Prometheus

Prometheus

Grafana

Grafana

📂 Project Structure

.
├── AWS_ARCHITECTURE.md     # Architecture documentation
├── README.md              # Project documentation
├── docker-compose.yml     # Docker orchestration
├── backend/               # Node.js/Express Server
│   ├── Dockerfile         # Backend Docker image config
│   ├── .eslintrc.json     # Backend lint config
│   ├── server.js          # Entry point
│   └── ...
└── frontend/              # Angular Client
    ├── Dockerfile         # Frontend Docker image config
    ├── nginx.conf         # Nginx proxy config
    ├── .eslintrc.json     # Frontend lint config
    └── ...

Monitoring

This application is monitored using Prometheus and Grafana.

Accessing Monitoring Services

Implementation Steps

  1. Backend Instrumentation:

    • Added prom-client dependency to backend/package.json.
    • Updated backend/server.js to collect default metrics and expose them at /metrics.
  2. Prometheus Configuration:

    • Created prometheus.yml to scrape the backend service on port 8080.
  3. Docker Compose:

    • Added prometheus service using prom/prometheus image.
    • Added grafana service using grafana/grafana image.
    • Configured volumes for data persistence (prometheus_data, grafana_data).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published