π 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:
- Builds both backend and frontend.
- Pushes images to a container registry.
- SSHes into the server and redeploys.
- 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:
π§© 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
systemdthrough 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:
For production:
- Use
.env.prodwith stronger creds. - Never commit secrets β use CI/CD secrets storage.
πΎ 10. Backup & Recovery¶
PostgreSQL backup:¶
Redis snapshot:¶
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:
π 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¶
- Restore from latest DB + Redis backups.
- Pull latest images from registry.
- Deploy via
docker compose up -d. - Reconnect DNS / certificates.
- 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.