# Stiftung Application - Synology NAS Deployment

## Overview
This guide will help you deploy the Stiftung application on a Synology NAS using Docker.

## Prerequisites
- Synology NAS with DSM 7.0+ (recommended)
- Docker package installed from Synology Package Center
- At least 4GB RAM available
- At least 10GB free disk space
- SSH access enabled (optional but recommended)

## Quick Start
1. Copy the entire `deploy-synology` folder to your Synology NAS
2. SSH into your NAS or use File Station
3. Navigate to the deployment folder
4. Run: `docker-compose up -d`
5. Access the application at: `http://YOUR_NAS_IP:8081`

## Detailed Steps

### Step 1: Install Docker Package
1. Open **Package Center** on your Synology NAS
2. Search for "Docker"
3. Install the Docker package
4. Wait for installation to complete

### Step 2: Copy Deployment Files
1. Copy the `deploy-synology` folder to your NAS
   - Use **File Station** to upload via web interface
   - Or use **SMB/AFP** to mount and copy via network
   - Or use **SSH/SCP** for command line transfer

### Step 3: Configure Environment
1. Edit `docker-compose.yml` if needed (ports, volumes)
2. Edit `.env` file with your specific settings
3. Ensure backup directories exist and have proper permissions

### Step 4: Deploy
1. SSH into your NAS: `ssh admin@YOUR_NAS_IP`
2. Navigate to deployment folder: `cd /volume1/docker/stiftung`
3. Start the application: `docker-compose up -d`
4. Check status: `docker-compose ps`

### Step 5: Verify Deployment
1. Check container logs: `docker-compose logs web`
2. Test web access: `http://YOUR_NAS_IP:8081`
3. Verify database connection
4. Test backup functionality

## Configuration Files

### Environment Variables (.env)
- `DATABASE_URL`: PostgreSQL connection string
- `PAPERLESS_URL`: Paperless-ngx API URL
- `GRAMPSWEB_URL`: Gramps Web API URL
- `SECRET_KEY`: Django secret key
- `DEBUG`: Set to False for production

### Ports
- **8081**: Main web application
- **5432**: PostgreSQL database (internal)
- **6379**: Redis (internal)
- **5000**: Gramps Web (internal)

### Volumes
- `./data/db`: PostgreSQL data
- `./data/redis`: Redis data
- `./data/uploads`: File uploads
- `./data/backups`: Backup files
- `./data/gramps`: Gramps data

## Maintenance

### Backup
- Application creates automatic backups
- Manual backup: `docker-compose exec web python manage.py backup`
- Restore: `docker-compose exec web python manage.py restore backup_file.tar.gz`

### Updates
1. Stop containers: `docker-compose down`
2. Pull new images: `docker-compose pull`
3. Start containers: `docker-compose up -d`

### Logs
- View logs: `docker-compose logs -f [service_name]`
- Rotate logs: Configure log rotation in DSM

## Troubleshooting

### Common Issues
1. **Port conflicts**: Change ports in docker-compose.yml
2. **Permission errors**: Check folder permissions (755 for directories, 644 for files)
3. **Database connection**: Verify PostgreSQL container is running
4. **Memory issues**: Increase NAS memory or reduce container memory limits

### Support
- Check container logs: `docker-compose logs [service_name]`
- Verify container status: `docker-compose ps`
- Check resource usage in DSM Resource Monitor

## Security Notes
- Change default passwords
- Use HTTPS in production (reverse proxy with Let's Encrypt)
- Regular security updates
- Firewall configuration
- Backup encryption
