# Deployment Guide

This document describes how to deploy the Radionica 3D platform to a production server.

## Production Environment
The recommended production setup uses:
- **OS**: Linux (Ubuntu 22.04+).
- **Reverse Proxy**: Nginx.
- **Process Manager**: Systemd (for the backend).
- **SSL**: Let's Encrypt (Certbot).

## Build Process

### 1. Build Frontend
The frontend must be built as a set of static files.
```bash
# In project root
npm run build
```
This command:
1. Generates translations.
2. Generates the sitemap.
3. Compiles the Vue app.
4. Performs SSG (Prerendering) for SEO-sensitive pages.
5. Outputs to the `dist/` directory.

### 2. Prepare Backend
Ensure all production dependencies are installed and the environment variables are set in `.env.production`.

## Deployment Scripts
- `build_frontend.sh`: Automates the frontend build process on the server. It handles atomic deployments by using symlinks (e.g., swapping a `dist` symlink to a new timestamped folder).
- `server_update.sh`: Pulls the latest code, builds the frontend, and restarts the backend services.

## Systemd Services
The backend should run as a persistent service. Example configurations are provided in:
- `radionica-backend.service`: Runs the FastAPI server via Uvicorn.
- `radionica-deploy.service`: A listener service for automated deployment triggers (if used).

## Nginx Configuration
The `nginx.conf` file in the root is the source of truth for the web server configuration. Key features:
- Redirects HTTP to HTTPS.
- Serves static assets from `dist/public/`.
- Proxies API requests (`/api/`) and WebSockets (`/ws/`) to the FastAPI backend.
- Handles history-mode routing for the SPA by falling back to `index.html`.

## Persistence
- **Database**: Ensure `backend/database.db` is backed up regularly.
- **Uploads**: The `backend/uploads/` directory must persist between deployments. Use a Docker volume or a dedicated persistent path.

## Monitoring
- Check `server_debug.log` (if enabled) for backend issues.
- Monitor Nginx access/error logs for traffic and routing problems.
