Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Add configurable dev paths and centralize path management

Juan Denis5113c85e99c4
diff --git a/.gitignore b/.gitignore
index 7f7547dd..b7f8e9d5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,3 +55,6 @@ new_templates/
*.test
*.out
/template-icons
+
+# Dev data directory (local development path overrides)
+backend/dev-data/
diff --git a/backend/.env.example b/backend/.env.example
index cfde4dab..8230c85e 100644
--- a/backend/.env.example
+++ b/backend/.env.example
@@ -28,3 +28,12 @@ SERVERKIT_ENCRYPTION_KEY=dSenbMzCii4PMYP3Bb_N9jdqm6pa_TOD4l9yAwhhSBA=
# GitHub Repository for agent releases (owner/repo format)
# This is used to fetch the latest agent version for the downloads page
SERVERKIT_GITHUB_REPO=jhd3197/ServerKit
+
+# Dev path overrides (uncomment for local development)
+# Production defaults are absolute Linux paths (/var/serverkit, /etc/serverkit, etc.)
+# SERVERKIT_DIR=./dev-data
+# SERVERKIT_CONFIG_DIR=./dev-data/config
+# SERVERKIT_LOG_DIR=./dev-data/logs
+# SERVERKIT_BACKUP_DIR=./dev-data/backups
+# SERVERKIT_CACHE_DIR=./dev-data/cache
+# SERVERKIT_QUARANTINE_DIR=./dev-data/quarantine
diff --git a/backend/app/api/apps.py b/backend/app/api/apps.py
index c88e4294..7582751b 100644
--- a/backend/app/api/apps.py
+++ b/backend/app/api/apps.py
@@ -6,6 +6,7 @@ from app import db
from app.models import Application, User
from app.services.docker_service import DockerService
from app.services.log_service import LogService
+from app import paths
apps_bp = Blueprint('apps', __name__)
@@ -384,7 +385,7 @@ def delete_app(app_id):
# Delete the app folder
try:
- if app.root_path and app.root_path.startswith('/var/serverkit/apps/'):
+ if app.root_path and app.root_path.startswith(paths.APPS_DIR):
if os.path.exists(app.root_path):
shutil.rmtree(app.root_path)
cleanup_results['folder'] = {'success': True}
diff --git a/backend/app/api/backups.py b/backend/app/api/backups.py
index 856b2ebc..b6ea26b3 100644
--- a/backend/app/api/backups.py
+++ b/backend/app/api/backups.py
@@ -1,7 +1,9 @@
+import os
from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity
from app.models import User, Application
from app.services.backup_service import BackupService
+from app import paths
backups_bp = Blueprint('backups', __name__)
@@ -166,7 +168,7 @@ def restore_database():
def delete_backup(backup_path):
"""Delete a backup."""
# Ensure path is within backup directory
- full_path = f"/var/backups/serverkit/{backup_path}"
+ full_path = os.path.join(paths.SERVERKIT_BACKUP_DIR, backup_path)
result = BackupService.delete_backup(full_path)
return jsonify(result), 200 if result['success'] else 400
diff --git a/backend/app/api/docker.py b/backend/app/api/docker.py
index 9a681fc9..52123a05 100644
--- a/backend/app/api/docker.py
+++ b/backend/app/api/docker.py
@@ -2,7 +2,7 @@ from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity
from app.models import User, Application
from app.services.docker_service import DockerService
-from app import db
+from app import db, paths
docker_bp = Blueprint('docker', __name__)
@@ -570,7 +570,7 @@ def cleanup_all_apps():
import shutil
import os
- apps_dir = '/var/serverkit/apps'
+ apps_dir = paths.APPS_DIR
results = []
# Get all apps from database
diff --git a/backend/app/paths.py b/backend/app/paths.py
new file mode 100644
index 00000000..d3d1fbb7
--- /dev/null
+++ b/backend/app/paths.py
@@ -0,0 +1,19 @@
+import os
+
+# Base directories (override via env vars; defaults = production)
+SERVERKIT_DIR = os.environ.get('SERVERKIT_DIR', '/var/serverkit')
+SERVERKIT_CONFIG_DIR = os.environ.get('SERVERKIT_CONFIG_DIR', '/etc/serverkit')
+SERVERKIT_LOG_DIR = os.environ.get('SERVERKIT_LOG_DIR', '/var/log/serverkit')
+SERVERKIT_BACKUP_DIR = os.environ.get('SERVERKIT_BACKUP_DIR', '/var/backups/serverkit')
+SERVERKIT_CACHE_DIR = os.environ.get('SERVERKIT_CACHE_DIR', '/var/cache/serverkit')
+SERVERKIT_QUARANTINE_DIR = os.environ.get('SERVERKIT_QUARANTINE_DIR', '/var/quarantine')
+
+# Derived paths
+APPS_DIR = os.path.join(SERVERKIT_DIR, 'apps')
+DEPLOYMENTS_DIR = os.path.join(SERVERKIT_DIR, 'deployments')
+TEMPLATES_DIR = os.path.join(SERVERKIT_CONFIG_DIR, 'templates')
+BUILD_LOG_DIR = os.path.join(SERVERKIT_LOG_DIR, 'builds')
+BUILD_CACHE_DIR = os.path.join(SERVERKIT_CACHE_DIR, 'builds')
+DB_BACKUP_DIR = os.path.join(SERVERKIT_BACKUP_DIR, 'databases')
+WP_BACKUP_DIR = os.path.join(SERVERKIT_BACKUP_DIR, 'wordpress')
+SNAPSHOT_DIR = os.path.join(SERVERKIT_BACKUP_DIR, 'snapshots')
diff --git a/backend/app/services/backup_service.py b/backend/app/services/backup_service.py
index 7a403642..a96542b6 100644
--- a/backend/app/services/backup_service.py
+++ b/backend/app/services/backup_service.py
@@ -11,12 +11,14 @@ import threading
import time
import schedule
+from app import paths
+
class BackupService:
"""Service for automated backups of applications and databases."""
- BACKUP_BASE_DIR = '/var/backups/serverkit'
- CONFIG_DIR = '/etc/serverkit'
+ BACKUP_BASE_DIR = paths.SERVERKIT_BACKUP_DIR
+ CONFIG_DIR = paths.SERVERKIT_CONFIG_DIR
BACKUP_CONFIG = os.path.join(CONFIG_DIR, 'backups.json')
# Backup types
diff --git a/backend/app/services/build_service.py b/backend/app/services/build_service.py
index 13c5c1b7..0ede960f 100644
--- a/backend/app/services/build_service.py
+++ b/backend/app/services/build_service.py
@@ -21,14 +21,16 @@ from datetime import datetime
from typing import Dict, List, Optional, Callable, Generator
from pathlib import Path
+from app import paths
+
class BuildService:
"""Service for building applications from source code."""
- CONFIG_DIR = '/etc/serverkit'
+ CONFIG_DIR = paths.SERVERKIT_CONFIG_DIR
BUILD_CONFIG = os.path.join(CONFIG_DIR, 'builds.json')
- BUILD_LOG_DIR = '/var/log/serverkit/builds'
- BUILD_CACHE_DIR = '/var/cache/serverkit/builds'
+ BUILD_LOG_DIR = paths.BUILD_LOG_DIR
+ BUILD_CACHE_DIR = paths.BUILD_CACHE_DIR
# Default build timeout (10 minutes)
DEFAULT_TIMEOUT = 600
diff --git a/backend/app/services/database_service.py b/backend/app/services/database_service.py
index 009f8597..23ab8d25 100644
--- a/backend/app/services/database_service.py
+++ b/backend/app/services/database_service.py
@@ -5,11 +5,13 @@ import string
import json
from datetime import datetime
+from app import paths
+
class DatabaseService:
"""Service for managing MySQL/MariaDB and PostgreSQL databases."""
- BACKUP_DIR = '/var/backups/serverkit/databases'
+ BACKUP_DIR = paths.DB_BACKUP_DIR
# ==================== MYSQL/MARIADB ====================
diff --git a/backend/app/services/db_sync_service.py b/backend/app/services/db_sync_service.py
index 02231fad..c9593647 100644
--- a/backend/app/services/db_sync_service.py
+++ b/backend/app/services/db_sync_service.py
@@ -15,11 +15,13 @@ from datetime import datetime, timedelta
from typing import Dict, List, Optional
from pathlib import Path
+from app import paths
+
class DatabaseSyncService:
"""Service for database cloning, transformation, and sync operations."""
- SNAPSHOT_DIR = '/var/backups/serverkit/snapshots'
+ SNAPSHOT_DIR = paths.SNAPSHOT_DIR
TEMP_DIR = '/tmp/serverkit_db_sync'
@classmethod
diff --git a/backend/app/services/deployment_service.py b/backend/app/services/deployment_service.py
index 0249c808..03b73764 100644
--- a/backend/app/services/deployment_service.py
+++ b/backend/app/services/deployment_service.py
@@ -22,12 +22,13 @@ from app.models.application import Application
from app.services.build_service import BuildService
from app.services.docker_service import DockerService
from app.services.git_service import GitService
+from app import paths
class DeploymentService:
"""Service for orchestrating deployments."""
- DEPLOYMENT_DIR = '/var/serverkit/deployments'
+ DEPLOYMENT_DIR = paths.DEPLOYMENTS_DIR
@classmethod
def create_deployment(cls, app_id: int, user_id: int = None,
@@ -135,7 +136,7 @@ class DeploymentService:
if build_result.get('build_log'):
# Store build log path for later retrieval
- log_dir = f"/var/log/serverkit/builds/{app_id}"
+ log_dir = os.path.join(paths.BUILD_LOG_DIR, str(app_id))
log_file = f"build-{deployment.created_at.isoformat().replace(':', '-')}.json"
deployment.build_log_path = os.path.join(log_dir, log_file)
diff --git a/backend/app/services/environment_docker_service.py b/backend/app/services/environment_docker_service.py
index 78dabbb3..e3316b19 100644
--- a/backend/app/services/environment_docker_service.py
+++ b/backend/app/services/environment_docker_service.py
@@ -12,12 +12,13 @@ import shutil
import subprocess
from typing import Dict
from app.services.template_service import TemplateService
+from app import paths
class EnvironmentDockerService:
"""Service for managing per-environment Docker Compose stacks."""
- APPS_DIR = '/var/serverkit/apps'
+ APPS_DIR = paths.APPS_DIR
# Docker Compose template for a WordPress environment
COMPOSE_TEMPLATE = """services:
diff --git a/backend/app/services/file_service.py b/backend/app/services/file_service.py
index d1fd4c0d..051a2e0a 100644
--- a/backend/app/services/file_service.py
+++ b/backend/app/services/file_service.py
@@ -23,11 +23,14 @@ else:
# Use Windows-specific logic or a placeholder
grp = None
+from app import paths
+
+
class FileService:
"""Service for file system operations."""
# Allowed root directories for browsing (security)
- ALLOWED_ROOTS = ['/home', '/var/www', '/opt', '/srv', '/var/log', '/var/serverkit']
+ ALLOWED_ROOTS = ['/home', '/var/www', '/opt', '/srv', '/var/log', paths.SERVERKIT_DIR]
# File extensions that can be edited in browser
EDITABLE_EXTENSIONS = {
diff --git a/backend/app/services/git_service.py b/backend/app/services/git_service.py
index f0484fe6..01dc809c 100644
--- a/backend/app/services/git_service.py
+++ b/backend/app/services/git_service.py
@@ -8,13 +8,15 @@ from datetime import datetime
from typing import Dict, List, Optional
from pathlib import Path
+from app import paths
+
class GitService:
"""Service for Git deployment and webhooks."""
- CONFIG_DIR = '/etc/serverkit'
+ CONFIG_DIR = paths.SERVERKIT_CONFIG_DIR
DEPLOY_CONFIG = os.path.join(CONFIG_DIR, 'deployments.json')
- DEPLOY_LOG = '/var/log/serverkit/deployments.log'
+ DEPLOY_LOG = os.path.join(paths.SERVERKIT_LOG_DIR, 'deployments.log')
@classmethod
def get_config(cls) -> Dict:
@@ -517,7 +519,7 @@ class GitService:
except Exception as e:
return {'error': str(e)}
- WEBHOOK_LOG = '/var/log/serverkit/webhooks.log'
+ WEBHOOK_LOG = os.path.join(paths.SERVERKIT_LOG_DIR, 'webhooks.log')
@classmethod
def log_webhook(cls, app_id: int, provider: str, headers: List, payload: bytes) -> None:
diff --git a/backend/app/services/log_service.py b/backend/app/services/log_service.py
index 38ad7808..441b4a90 100644
--- a/backend/app/services/log_service.py
+++ b/backend/app/services/log_service.py
@@ -6,6 +6,8 @@ from datetime import datetime
import threading
import queue
+from app import paths
+
class LogService:
"""Service for log management and streaming."""
@@ -24,7 +26,7 @@ class LogService:
# Allowed directories for log file access (path traversal protection)
ALLOWED_LOG_DIRECTORIES = [
'/var/log',
- '/var/serverkit',
+ paths.SERVERKIT_DIR,
'/var/www',
'/home',
'/opt',
@@ -150,7 +152,7 @@ class LogService:
"""
# Check if this is a Docker-based app
docker_compose_paths = [
- f'/var/serverkit/apps/{app_name}/docker-compose.yml',
+ f'{paths.APPS_DIR}/{app_name}/docker-compose.yml',
f'/var/www/{app_name}/docker-compose.yml',
]
diff --git a/backend/app/services/monitoring_service.py b/backend/app/services/monitoring_service.py
index 207841ea..57fd9a18 100644
--- a/backend/app/services/monitoring_service.py
+++ b/backend/app/services/monitoring_service.py
@@ -11,14 +11,15 @@ import threading
import time
from .notification_service import NotificationService
+from app import paths
class MonitoringService:
"""Service for system monitoring and alerts."""
- CONFIG_DIR = '/etc/serverkit'
+ CONFIG_DIR = paths.SERVERKIT_CONFIG_DIR
ALERTS_CONFIG = os.path.join(CONFIG_DIR, 'alerts.json')
- ALERTS_LOG = '/var/log/serverkit/alerts.log'
+ ALERTS_LOG = os.path.join(paths.SERVERKIT_LOG_DIR, 'alerts.log')
# Default thresholds
DEFAULT_THRESHOLDS = {
diff --git a/backend/app/services/notification_service.py b/backend/app/services/notification_service.py
index 2085e97c..911659e4 100644
--- a/backend/app/services/notification_service.py
+++ b/backend/app/services/notification_service.py
@@ -19,11 +19,13 @@ from datetime import datetime
from typing import Dict, List, Optional
from pathlib import Path
+from app import paths
+
class NotificationService:
"""Service for sending notifications to various channels."""
- CONFIG_DIR = '/etc/serverkit'
+ CONFIG_DIR = paths.SERVERKIT_CONFIG_DIR
NOTIFICATIONS_CONFIG = os.path.join(CONFIG_DIR, 'notifications.json')
# Severity colors (hex for Discord, named for Slack)
diff --git a/backend/app/services/security_service.py b/backend/app/services/security_service.py
index 0af9a217..1d0d8fbb 100644
--- a/backend/app/services/security_service.py
+++ b/backend/app/services/security_service.py
@@ -19,16 +19,17 @@ from typing import Dict, List, Optional
from pathlib import Path
from .notification_service import NotificationService
+from app import paths
class SecurityService:
"""Service for security scanning and monitoring."""
- CONFIG_DIR = '/etc/serverkit'
+ CONFIG_DIR = paths.SERVERKIT_CONFIG_DIR
SECURITY_CONFIG = os.path.join(CONFIG_DIR, 'security.json')
INTEGRITY_DB = os.path.join(CONFIG_DIR, 'file_integrity.json')
- SCAN_LOG = '/var/log/serverkit/security_scans.log'
- ALERTS_LOG = '/var/log/serverkit/security_alerts.log'
+ SCAN_LOG = os.path.join(paths.SERVERKIT_LOG_DIR, 'security_scans.log')
+ ALERTS_LOG = os.path.join(paths.SERVERKIT_LOG_DIR, 'security_alerts.log')
# Scan status tracking
_current_scan = None
@@ -50,7 +51,7 @@ class SecurityService:
'scan_paths': ['/var/www', '/home'],
'exclude_paths': ['/var/www/cache', '*.log'],
'scan_on_upload': True,
- 'quarantine_path': '/var/quarantine',
+ 'quarantine_path': paths.SERVERKIT_QUARANTINE_DIR,
'max_file_size': 100 * 1024 * 1024, # 100MB
'scheduled_scan': {
'enabled': False,
@@ -376,7 +377,7 @@ class SecurityService:
def quarantine_file(cls, file_path: str) -> Dict:
"""Move infected file to quarantine."""
config = cls.get_config()
- quarantine_path = config.get('clamav', {}).get('quarantine_path', '/var/quarantine')
+ quarantine_path = config.get('clamav', {}).get('quarantine_path', paths.SERVERKIT_QUARANTINE_DIR)
if not os.path.exists(file_path):
return {'success': False, 'error': 'File not found'}
@@ -414,7 +415,7 @@ class SecurityService:
def get_quarantined_files(cls) -> Dict:
"""List quarantined files."""
config = cls.get_config()
- quarantine_path = config.get('clamav', {}).get('quarantine_path', '/var/quarantine')
+ quarantine_path = config.get('clamav', {}).get('quarantine_path', paths.SERVERKIT_QUARANTINE_DIR)
if not os.path.exists(quarantine_path):
return {'success': True, 'files': []}
@@ -440,7 +441,7 @@ class SecurityService:
def delete_quarantined_file(cls, filename: str) -> Dict:
"""Permanently delete a quarantined file."""
config = cls.get_config()
- quarantine_path = config.get('clamav', {}).get('quarantine_path', '/var/quarantine')
+ quarantine_path = config.get('clamav', {}).get('quarantine_path', paths.SERVERKIT_QUARANTINE_DIR)
file_path = os.path.join(quarantine_path, filename)
if not os.path.exists(file_path):
diff --git a/backend/app/services/template_service.py b/backend/app/services/template_service.py
index 1c6d54ae..68ddef25 100644
--- a/backend/app/services/template_service.py
+++ b/backend/app/services/template_service.py
@@ -24,14 +24,16 @@ from typing import Dict, List, Optional, Any
from pathlib import Path
import requests
+from app import paths
+
class TemplateService:
"""Service for managing and deploying application templates."""
- CONFIG_DIR = '/etc/serverkit'
- TEMPLATES_DIR = '/etc/serverkit/templates'
+ CONFIG_DIR = paths.SERVERKIT_CONFIG_DIR
+ TEMPLATES_DIR = paths.TEMPLATES_DIR
LOCAL_TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'templates')
- INSTALLED_DIR = '/var/serverkit/apps'
+ INSTALLED_DIR = paths.APPS_DIR
TEMPLATE_CONFIG = os.path.join(CONFIG_DIR, 'templates.json')
# Default template repository
diff --git a/backend/app/services/wordpress_service.py b/backend/app/services/wordpress_service.py
index 1808832b..f2a27986 100644
--- a/backend/app/services/wordpress_service.py
+++ b/backend/app/services/wordpress_service.py
@@ -8,13 +8,15 @@ from datetime import datetime
from typing import Dict, List, Optional
from pathlib import Path
+from app import paths
+
class WordPressService:
"""Service for WordPress installation and management."""
WP_CLI_PATH = '/usr/local/bin/wp'
WP_DOWNLOAD_URL = 'https://wordpress.org/latest.tar.gz'
- BACKUP_DIR = '/var/backups/serverkit/wordpress'
+ BACKUP_DIR = paths.WP_BACKUP_DIR
# Security headers for wp-config.php
SECURITY_CONSTANTS = '''
@@ -628,7 +630,7 @@ RewriteRule ^wp-content/uploads/.*\\.php$ - [F]
# ========================================
WP_APP_NAME = 'serverkit-wordpress'
- WP_CONFIG_DIR = '/etc/serverkit'
+ WP_CONFIG_DIR = paths.SERVERKIT_CONFIG_DIR
WP_CONFIG_FILE = os.path.join(WP_CONFIG_DIR, 'wordpress.json')
@classmethod
diff --git a/backend/app/services/workflow_service.py b/backend/app/services/workflow_service.py
index 3a981366..0c0b8f8e 100644
--- a/backend/app/services/workflow_service.py
+++ b/backend/app/services/workflow_service.py
@@ -11,13 +11,14 @@ from app import db
from app.models import Workflow, Application, Domain, User
from app.services.docker_service import DockerService
from app.services.database_service import DatabaseService
+from app import paths
class WorkflowService:
"""Service for deploying workflows to infrastructure."""
# Base path for app deployments
- APP_BASE_PATH = '/var/serverkit/apps'
+ APP_BASE_PATH = paths.APPS_DIR
@staticmethod
def deploy_workflow(workflow_id, user_id):
diff --git a/backend/config.py b/backend/config.py
index 82d9c33c..5e04c691 100644
--- a/backend/config.py
+++ b/backend/config.py
@@ -24,7 +24,7 @@ class Config:
JWT_REFRESH_TOKEN_EXPIRES = timedelta(days=30)
# CORS - Allow both dev server and Flask server
- CORS_ORIGINS = os.environ.get('CORS_ORIGINS', 'http://localhost:5173,http://localhost:5000,http://127.0.0.1:5173,http://127.0.0.1:5000').split(',')
+ CORS_ORIGINS = os.environ.get('CORS_ORIGINS', 'http://localhost:5173,http://localhost:5274,http://localhost:5000,http://127.0.0.1:5173,http://127.0.0.1:5274,http://127.0.0.1:5000').split(',')
class DevelopmentConfig(Config):
diff --git a/frontend/vite.config.js b/frontend/vite.config.js
index c483b80a..f75e81b4 100644
--- a/frontend/vite.config.js
+++ b/frontend/vite.config.js
@@ -5,6 +5,7 @@ import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
server: {
+ port: 5274,
// Enable polling for WSL (Windows filesystem doesn't support inotify)
watch: {
usePolling: true,
diff --git a/scripts/dev/start.sh b/scripts/dev/start.sh
index e0bf2607..3415f449 100644
--- a/scripts/dev/start.sh
+++ b/scripts/dev/start.sh
@@ -6,7 +6,7 @@ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
echo "Starting ServerKit..."
echo " Backend: http://localhost:5000"
-echo " Frontend: http://localhost:5173"
+echo " Frontend: http://localhost:5274"
echo ""
cd "$PROJECT_ROOT/backend"