Deployment
This guide covers deploying SnapCart to a production server using Docker Compose or a manual server setup.
Docker Deployment (Recommended)
Docker Compose bundles the backend, frontend, and MySQL database into a single orchestrated setup.
Prerequisites
- Docker 24+
- Docker Compose 2.x
- A server with at least 2 GB RAM and 10 GB disk
Steps
- Clone the repository on your server:
git clone https://github.com/your-org/snapcart.git
cd snapcart
- Create production configuration:
cp backend/src/main/resources/application.example.yml backend/src/main/resources/application.yml
Edit application.yml with your production database credentials, JWT secret, SMTP settings, and storage configuration.
- Create the frontend environment file:
cp frontend/.env.example frontend/.env
Edit .env:
VITE_API_BASE_URL=https://api.yourdomain.com
VITE_APP_NAME=SnapCart
- Start the stack:
docker compose up -d
Docker Compose will:
- Pull/build the backend image and run Flyway migrations
- Build and serve the frontend
- Start MySQL and wait for it to be healthy before starting the backend
- Check running containers:
docker compose ps
Stopping and Restarting
docker compose down # stop without removing volumes
docker compose down -v # stop and delete all data (irreversible)
docker compose restart # restart all services
Manual Server Deployment
1. Install dependencies
# Java 17
sudo apt install openjdk-17-jdk -y
# MySQL 8
sudo apt install mysql-server -y
# Node.js 20
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install nodejs -y
2. Configure MySQL
CREATE DATABASE snapcart CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'snapcart'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON snapcart.* TO 'snapcart'@'localhost';
FLUSH PRIVILEGES;
3. Build and deploy the backend
cd backend
mvn clean package -DskipTests
java -jar target/snapcart-backend.jar
For production, run the JAR as a systemd service:
# /etc/systemd/system/snapcart.service
[Unit]
Description=SnapCart Backend
After=network.target mysql.service
[Service]
User=snapcart
ExecStart=/usr/bin/java -jar /opt/snapcart/snapcart-backend.jar
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl enable snapcart
sudo systemctl start snapcart
4. Build and deploy the frontend
cd frontend
npm install
npm run build
The built assets are in frontend/dist/. Serve them with Nginx:
server {
listen 80;
server_name yourdomain.com;
root /opt/snapcart/frontend/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
SSL / HTTPS
Use Certbot with Let's Encrypt for a free SSL certificate:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com
Certbot automatically modifies your Nginx config to redirect HTTP to HTTPS and renews the certificate every 90 days.
Post-Deployment Checklist
- Change all demo passwords (
superadmin@demo.io,admin@demo.io,finance@demo.io) - Switch payment gateways from sandbox to production mode
- Configure SMTP and test email delivery
- Set
VITE_API_BASE_URLto your production API domain - Enable and configure SSL
- Set up automated MySQL backups
- Configure a firewall to block all ports except 80, 443, and SSH