πŸš€ Full Stack Deployment & Operations Overview

(Frontend + Backend + Infrastructure + CI/CD)

This document connects everything β€” from developer commits to live, monitored systems.
It shows how Git, Docker, Nginx, PostgreSQL, Redis, and systemd interact across environments, supported by CI/CD pipelines and monitoring.


🧩 1. The Complete Stack

            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚         Developer          β”‚
            β”‚   (Git + IDE + Docker)     β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚ push/build
                         β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚ Continuous Integration (CI) β”‚
     β”‚   Build β†’ Test β†’ Package    β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
                  β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚ Continuous Deployment (CD)  β”‚
     β”‚   Deploy β†’ Start Services    β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
                  β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚     Production Server       β”‚
     β”‚  (systemd + Docker + Nginx) β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
                  β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚     Monitoring & Logs        β”‚
     β”‚  (Prometheus, Grafana, ELK)  β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Everything begins with Git, moves through CI/CD automation, lands on a Dockerized host managed by systemd, and is served to the world through Nginx.


βš™οΈ 2. Environments and Their Roles

Environment Purpose Key Tools
Local Fast iteration, testing Docker Compose, local DB
Staging Full stack replica Docker Compose, CI/CD
Production Stable live system Docker, systemd, Nginx
CI Runner Automated testing GitHub Actions / GitLab CI

Golden rule:

Each environment should be identical in architecture, differing only in configuration.


🧱 3. Stack Layers Overview

Layer Component Purpose
Source Control Git Version all code and infrastructure
Build Layer Node.js, Gradle/Maven Build frontend + backend artifacts
Runtime Layer Docker Run isolated containers
Routing Layer Nginx Route external traffic
Data Layer PostgreSQL, Redis Persistent + cached data
Orchestration Layer systemd Ensure uptime and startup order
Automation Layer CI/CD Test, build, and deploy automatically
Observation Layer Prometheus, Grafana, Logs Metrics, alerts, traces

🐳 4. Docker Compose for Unified Stack

The glue that connects your local and staging environments.

version: "3.9"
services:
  nginx:
    image: nginx:latest
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    depends_on: [backend, frontend]

  frontend:
    build: ./frontend
    expose:
      - "5173"

  backend:
    build: ./backend
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/appdb
      SPRING_DATASOURCE_USERNAME: devuser
      SPRING_DATASOURCE_PASSWORD: secret
    depends_on: [postgres, redis]

  postgres:
    image: postgres:16
    volumes:
      - pg_data:/var/lib/postgresql/data

  redis:
    image: redis:7
    volumes:
      - redis_data:/data

volumes:
  pg_data:
  redis_data:

This setup runs the entire full stack locally, exactly as it would in staging or production.


πŸ” 5. CI/CD Pipeline Flow

Continuous Integration (CI) ensures your build works and tests pass. Continuous Deployment (CD) delivers it safely to your server.

Example (GitHub Actions)

name: Build & Deploy Full Stack
on:
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build backend
        run: ./gradlew build
      - name: Build frontend
        run: npm ci && npm run build
      - name: Build Docker images
        run: |
          docker build -t ghcr.io/user/backend:${{ github.sha }} backend/
          docker build -t ghcr.io/user/frontend:${{ github.sha }} frontend/
      - name: Push Images
        run: |
          docker push ghcr.io/user/backend:${{ github.sha }}
          docker push ghcr.io/user/frontend:${{ github.sha }}

  deploy:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: SSH & Deploy
        run: |
          ssh user@server "
            docker pull ghcr.io/user/backend:${{ github.sha }} &&
            docker pull ghcr.io/user/frontend:${{ github.sha }} &&
            docker compose up -d &&
            sudo systemctl reload nginx
          "

This pipeline:

  1. Builds both backend and frontend.
  2. Pushes images to a container registry.
  3. SSHes into the server and redeploys.
  4. Reloads Nginx to apply new frontend files.

⚑ 6. Deployment Directory Structure (on server)

/opt/app/
 β”œβ”€ docker-compose.yml
 β”œβ”€ nginx.conf
 β”œβ”€ .env
 β”œβ”€ frontend/
 β”œβ”€ backend/
 β”œβ”€ logs/
 └─ volumes/
     β”œβ”€ postgres/
     └─ redis/

systemd runs Docker as the service manager underneath:

sudo systemctl restart docker
sudo docker compose up -d

🧩 7. Nginx as the Traffic Controller

Handles requests, SSL, static serving, and proxying:

server {
    listen 80;
    server_name example.com;
    location / {
        root /usr/share/nginx/html;
        try_files $uri /index.html;
    }
    location /api/ {
        proxy_pass http://backend:8080;
    }
}

Nginx routes browser traffic β†’ frontend, and /api calls β†’ backend β†’ PostgreSQL/Redis.


🐘 8. Databases and Persistence

PostgreSQL

  • Stores structured, durable data.
  • Mounted via Docker volume (pg_data).
  • Managed by systemd through Docker.

Redis

  • In-memory caching + sessions.
  • Mounted volume for optional persistence (redis_data).
  • Communicates over internal Docker network.

🧠 9. Configuration & Secrets Management

All environments read from .env files:

DB_USER=devuser
DB_PASS=secret
REDIS_PASS=redispass
API_KEY=some_key

For production:

  • Use .env.prod with stronger creds.
  • Never commit secrets β€” use CI/CD secrets storage.

πŸ’Ύ 10. Backup & Recovery

PostgreSQL backup:

pg_dump -U devuser appdb | gzip > backup_$(date +%F).sql.gz

Redis snapshot:

redis-cli save

Automate backups with systemd timers or cron.


🧭 11. Monitoring & Logging

Tool Purpose
journalctl OS & service logs
Docker logs Container-level events
Prometheus Metrics collection
Grafana Visualization & alerts
ELK stack (Elasticsearch + Logstash + Kibana) Centralized logging

Minimal local setup:

docker run -d -p 9090:9090 prom/prometheus
docker run -d -p 3000:3000 grafana/grafana

πŸ”’ 12. Security Layers

Layer Defense
Network Nginx firewall rules, fail2ban
Transport HTTPS via Let’s Encrypt
Application Authentication, rate limiting
Data Encrypted DB connections
Access SSH keys, non-root Docker users
Secrets Environment variables in CI/CD secrets store

πŸ” 13. Continuous Maintenance Workflow

Task Tool Frequency
Code updates Git Continuous
Build & deploy CI/CD On every push
Logs review journalctl / Grafana Daily
Backup rotation systemd timer Daily/weekly
Security patches apt, Docker images Weekly
Service healthcheck systemctl, Prometheus Ongoing

🧩 14. Disaster Recovery Pattern

  1. Restore from latest DB + Redis backups.
  2. Pull latest images from registry.
  3. Deploy via docker compose up -d.
  4. Reconnect DNS / certificates.
  5. Verify via Nginx health endpoints.

Recovery time objective: minutes, not hours.


🧠 15. Developer-to-Production Mental Model

Role Tool Responsibility
Developer Git, Docker Build and test features
Integrator CI Verify builds
Deployer CD Push working containers live
Operator systemd Keep services healthy
Observer Grafana/Logs Detect issues early

βœ… 16. Summary

  • Git β†’ tracks source and triggers builds.
  • Docker β†’ standardizes runtime.
  • Nginx β†’ routes traffic to services.
  • PostgreSQL β†’ stores persistent state.
  • Redis β†’ accelerates performance.
  • systemd β†’ ensures everything starts and stays alive.
  • CI/CD β†’ automates the entire loop.
  • Monitoring tools β†’ give visibility and peace of mind.

Everything runs as a modular, reproducible, observable system β€” a fully self-contained full stack.