Skip to content

Rupeshs11/KnoxChat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

60 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ Knox Chat β€” Real-Time Chat Application

A production-ready real-time chat app built with Flask, Socket.IO, and MongoDB β€” featuring a complete DevSecOps CI/CD pipeline, GitOps with ArgoCD, Kubernetes on AWS EKS, and Infrastructure as Code with Terraform.

Python Flask MongoDB Docker Kubernetes Terraform ArgoCD CI/CD SonarCloud Nginx


✨ Features

  • πŸ’¬ Real-time messaging β€” Instant message delivery via WebSockets
  • πŸ” User authentication β€” Signup / Login with hashed passwords
  • 🏠 Chat rooms β€” Create or join any room
  • πŸ“œ Persistent messages β€” Chat history stored in MongoDB
  • πŸŒ™ WhatsApp-style dark theme β€” Clean, modern UI
  • 🐳 Dockerized β€” One-command deployment with Docker Compose
  • ☸️ Kubernetes ready β€” Full K8s manifests with Ingress, PV/PVC, ConfigMaps, Secrets
  • πŸ”’ SSL/HTTPS β€” Nginx reverse proxy with Let's Encrypt
  • �️ DevSecOps β€” Automated security scanning (SAST, SCA, Container Scanning)
  • πŸ”„ GitOps β€” ArgoCD auto-sync from Git to EKS
  • πŸ—οΈ Infrastructure as Code β€” Terraform provisions AWS infrastructure
  • πŸ“Š Monitoring β€” Prometheus & Grafana for cluster observability
  • πŸš€ CI/CD β€” 7-stage DevSecOps pipeline with GitHub Actions

πŸ—οΈ Architecture

DevSecOps & GitOps Architecture

DevSecOps Architecture

GitHub Actions Workflow

GitHub Actions Flow

ArgoCD GitOps Dashboard

ArgoCD


πŸ› οΈ Tech Stack

Layer Technology
Backend Flask, Flask-SocketIO, Gevent
Database MongoDB
Auth Werkzeug (password hashing)
Frontend HTML, CSS, JavaScript
Containerization Docker, Docker Compose
Reverse Proxy Nginx (SSL termination)
Orchestration Kubernetes (Minikube / AWS EKS)
IaC Terraform (S3 backend, DynamoDB lock)
CI/CD GitHub Actions
SAST SonarCloud
SCA OWASP Dependency-Check
Container Scanning Trivy
GitOps ArgoCD (auto-sync, self-heal)
Monitoring Prometheus & Grafana
Cloud AWS (EKS, VPC, EC2, EBS, S3, DynamoDB)

πŸ“Έ App Screenshots

Login Page Chat Room
Login Chat

�️ DevSecOps CI/CD Pipeline

A single GitHub Actions workflow (devsecops.yml) with 7 connected stages and a separate Terraform trigger:

                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β”Œβ”€β”€β”€β†’β”‚ SonarCloud  │──┐
  β”Œβ”€β”€β”€β”€β”€β”€β”         β”‚    β”‚   (SAST)    β”‚  β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ Lint │──────────    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”œβ”€β”€β”€β†’β”‚ Build │───→│ Trivy   │───→│ Push │───→│ Update K8s     β”‚
  β””β”€β”€β”€β”€β”€β”€β”˜         β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚    β”‚ Image β”‚    β”‚ Scan    β”‚    β”‚      β”‚    β”‚ Manifest       β”‚
                   └───→│ OWASP       β”‚β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚   (SCA)     β”‚                                                       β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                       β–Ό
                                                                                    ArgoCD Auto-Sync
  Manual Trigger ──→ Terraform (plan / apply / destroy)                             to EKS Cluster
Stage Tool Purpose
Lint flake8 Python code quality checks
SAST SonarCloud Source code vulnerability scanning
SCA OWASP Dependency-Check Third-party library vulnerability scanning
Build Docker Multi-stage build with non-root user
Container Scan Trivy Docker image vulnerability scanning
Push DockerHub Image registry with SHA-tagged versions
GitOps ArgoCD Auto-deploy from Git to EKS cluster
IaC Terraform Provision/destroy EKS infrastructure

EC2 Deploy Pipeline

A separate pipeline (deploy.yml) for simple EC2 Docker deployments:

Manual Trigger ──→ Terraform (creates EC2 with Docker)
Push to main   ──→ Build & Push ──→ Deploy to EC2 (SSH)

πŸ—οΈ Infrastructure as Code (Terraform)

Two separate Terraform configurations:

Config Directory Infrastructure
EKS terraform-devSecOps/ VPC, Subnets, NAT Gateway, EKS Cluster, Node Groups, EBS CSI
EC2 terraform/ EC2 Instance, Security Group, Docker (user_data)

Both use S3 backend for remote state and DynamoDB for state locking.


πŸ”„ GitOps with ArgoCD

ArgoCD continuously monitors the k8s/ directory and auto-syncs changes to EKS:

  • Auto-Sync β€” Detects Git changes and deploys automatically
  • Self-Heal β€” Reverts any manual cluster changes back to Git
  • Pruning β€” Deletes resources removed from Git
  • Rollback β€” One-click rollback to any previous version

The CI pipeline updates k8s/knoxchat-deployment.yml with the new image tag on every push. ArgoCD detects this change and deploys the new version.


πŸ“Š Monitoring & Observability

Prometheus & Grafana deployed via Helm for full cluster monitoring:

  • Prometheus β€” Metrics collection from all pods and nodes
  • Grafana β€” Pre-configured dashboards for Kubernetes monitoring
  • Node Exporter β€” Host-level metrics (CPU, memory, disk)
Namespace & Nodes Node Monitoring
Namespace Node View

πŸš€ Deployment Guide

Option 1: Local Development

git clone https://github.com/Rupeshs11/RealTime-ChatApp-.git
cd RealTime-ChatApp-

python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate
pip install -r requirements.txt

echo "MONGO_URI=mongodb://localhost:27017/knox_chat" > .env
echo "SECRET_KEY=your-secret-key" >> .env

python app.py

Open http://localhost:5000


Option 2: Docker Compose (Local)

docker-compose up -d

Open http://localhost:5000


Option 3: EC2 Production (with SSL)

Step 1: Build & Push Docker Image

docker build -t rupeshs11/knox-chat:latest .
docker login
docker push rupeshs11/knox-chat:latest

Step 2: Setup EC2 Instance

# SSH into EC2
ssh -i "your-key.pem" ubuntu@<EC2-IP>

# Install Docker
sudo apt-get update
sudo apt-get install -y docker.io docker-compose-plugin
sudo usermod -aG docker ubuntu

Step 3: Point Domain to EC2

In your DNS provider, add an A Record:

<Domain>  β†’  <EC2-Public-IP>

Step 4: Get SSL Certificate

sudo apt-get install -y certbot
sudo certbot certonly --standalone -d <Domain> -d <SubDomain>

Step 5: Copy Files & Deploy

scp -i "your-key.pem" docker-compose.prod.yml ubuntu@<EC2-IP>:~/knoxchat/
scp -i "your-key.pem" -r nginx/ ubuntu@<EC2-IP>:~/knoxchat/

ssh -i "your-key.pem" ubuntu@<EC2-IP>
cd ~/knoxchat

echo "MONGO_URI=mongodb://mongodb:27017/knox_chat" > .env
echo "SECRET_KEY=$(python3 -c 'import secrets; print(secrets.token_hex(32))')" >> .env
echo "DB_NAME=knox_chat" >> .env

docker compose -f docker-compose.prod.yml up -d

Step 6: Verify

docker compose -f docker-compose.prod.yml ps
docker compose -f docker-compose.prod.yml logs knox-chat
curl -I https://<Domain>

Open https://


Option 4: Kubernetes (Minikube)

Step 1: Start Minikube

minikube start --driver=docker
minikube addons enable ingress

Step 2: Deploy All Resources

kubectl apply -f k8s/namespace.yml
kubectl apply -f k8s/configmap.yml
kubectl apply -f k8s/secrets.yml
kubectl apply -f k8s/mongo-pv.yml
kubectl apply -f k8s/mongo-pvc.yml
kubectl apply -f k8s/mongo-deployment.yml
kubectl apply -f k8s/mongo-service.yml
kubectl apply -f k8s/knoxchat-deployment.yml
kubectl apply -f k8s/knoxchat-service.yml
kubectl apply -f k8s/ingress.yml

Step 3: Access the App

Add to hosts file (C:\Windows\System32\drivers\etc\hosts):

127.0.0.1 knoxchat.com
minikube tunnel

Open http://knoxchat.com


Option 5: AWS EKS (Full DevSecOps)

See DEVSECOPS-GUIDE.md for the complete step-by-step guide.

Quick steps:

  1. Setup GitHub Secrets (Docker, AWS, SonarCloud)
  2. Terraform Apply (creates EKS cluster)
  3. Install ArgoCD on EKS
  4. Apply ArgoCD Application manifest
  5. Install Nginx Ingress Controller
  6. Push code β†’ Pipeline runs β†’ ArgoCD deploys

πŸ“ Project Structure

RealTime-ChatApp/
β”œβ”€β”€ app.py                        # Flask app with auth + Socket.IO
β”œβ”€β”€ config.py                     # Environment config loader
β”œβ”€β”€ requirements.txt              # Python dependencies
β”œβ”€β”€ Dockerfile                    # Multi-stage, non-root, health check
β”œβ”€β”€ docker-compose.yml            # Local dev setup
β”œβ”€β”€ docker-compose.prod.yml       # Production setup (Nginx + SSL)
β”œβ”€β”€ sonar-project.properties      # SonarCloud configuration
β”œβ”€β”€ .env.example                  # Environment variables template
β”‚
β”œβ”€β”€ nginx/                        # Nginx reverse proxy config
β”œβ”€β”€ templates/                    # HTML templates (login, signup, chat)
β”œβ”€β”€ static/                       # CSS + JavaScript
β”‚
β”œβ”€β”€ k8s/                          # Kubernetes manifests
β”‚   β”œβ”€β”€ namespace.yml
β”‚   β”œβ”€β”€ configmap.yml
β”‚   β”œβ”€β”€ secrets.yml
β”‚   β”œβ”€β”€ mongo-storageclass.yml    # EBS StorageClass for EKS
β”‚   β”œβ”€β”€ mongo-pv.yml / mongo-pvc.yml
β”‚   β”œβ”€β”€ mongo-deployment.yml / mongo-service.yml
β”‚   β”œβ”€β”€ knoxchat-deployment.yml / knoxchat-service.yml
β”‚   β”œβ”€β”€ ingress.yml
β”‚   └── argocd/
β”‚       └── application.yml       # ArgoCD app definition
β”‚
β”œβ”€β”€ terraform/                    # EC2 Infrastructure (Terraform)
β”‚   β”œβ”€β”€ provider.tf / variables.tf
β”‚   β”œβ”€β”€ main.tf / outputs.tf
β”‚
β”œβ”€β”€ terraform-devSecOps/          # EKS Infrastructure (Terraform)
β”‚   β”œβ”€β”€ provider.tf / variables.tf
β”‚   β”œβ”€β”€ vpc.tf / eks.tf / outputs.tf
β”‚
β”œβ”€β”€ monitoring/                   # Prometheus & Grafana
β”‚   β”œβ”€β”€ prometheus-values.yml
β”‚   └── setup.md
β”‚
β”œβ”€β”€ docs/                         # Guides & Documentation
β”‚   β”œβ”€β”€ DEVSECOPS-KNOWLEDGE.md    # Concepts & Interview prep
β”‚   β”œβ”€β”€ EC2-DEPLOY-GUIDE.md       # EC2 pipeline quick setup
β”‚   └── argocd-setup.md           # ArgoCD installation guide
β”‚
β”œβ”€β”€ .github/workflows/            # CI/CD Pipelines
β”‚   β”œβ”€β”€ devsecops.yml             # DevSecOps + EKS pipeline
β”‚   └── deploy.yml                # EC2 deploy pipeline
β”‚
β”œβ”€β”€ architecture/                 # Architecture diagrams
β”œβ”€β”€ grafana-stats/                # Grafana monitoring screenshots
└── screenshots/                  # App screenshots

☸️ Kubernetes Resources

Resource Name Purpose
Namespace knoxchat Isolates all resources
ConfigMap knoxchat-config MONGO_URI, DB_NAME
Secret knoxchat-secrets SECRET_KEY (base64 encoded)
StorageClass ebs-sc EBS gp3 dynamic provisioning (EKS)
PV + PVC mongodb-pv/pvc Persistent MongoDB storage
Deployment mongo-deployment MongoDB pod (1 replica)
Deployment knoxchat-deployment App pod with health probes
Service mongo-service Internal MongoDB access
Service knoxchat-service Internal app access (port 5000)
Ingress knoxchat-ingress External access via Nginx

πŸ” Environment Variables

Variable Description
MONGO_URI MongoDB connection string
SECRET_KEY Flask session secret key
DB_NAME Database name (default: knox_chat)

GitHub Secrets Required

Secret Pipeline Purpose
DOCKER_USERNAME Both Docker Hub login
DOCKER_PASSWORD Both Docker Hub access token
SONAR_TOKEN DevSecOps SonarCloud SAST analysis
AWS_ACCESS_KEY_ID Both Terraform AWS access
AWS_SECRET_ACCESS_KEY Both Terraform AWS access
AWS_REGION Both AWS region
EC2_HOST EC2 Deploy EC2 public IP
EC2_SSH_KEY EC2 Deploy EC2 private key (PEM)
SECRET_KEY EC2 Deploy Flask session secret

πŸ’‘ How to Use

  1. Open the app β†’ Sign up with a username and password
  2. Login with your credentials
  3. Enter a room name (share it with friends!)
  4. Start chatting β€” messages persist across refreshes

About

πŸ’¬ Real-time chat app built with Flask & Socket.IO, deployed on AWS EC2 with automated CI/CD using GitHub Actions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors