Backend API server for Rukhalt Backup Management System.
- 🔐 JWT-based authentication
- 🗄️ PostgreSQL database with migrations
- 📦 Object storage (S3-compatible) backup management
- 🐘 PostgreSQL database backup and restore
- 🖥️ VPS file system backup via SSH/SFTP
- ⏰ Scheduled backup jobs
- 📊 Dashboard with metrics and alerts
- 🔍 Audit logging
- 🔄 Hot reload in development
- Language: Go 1.23
- Framework: Gin
- Database: PostgreSQL 15
- ORM: GORM
- Migrations: Goose
- CLI: Cobra
- Cache: Redis
- Docker & Docker Compose
- Go 1.23+ (for local development)
- Make (optional, for convenience)
- Clone the repository and navigate to server directory:
cd rukhalt/server- Copy environment file:
cp .env.example .env- Start development environment:
make devThis will:
- Start PostgreSQL database
- Run migrations automatically
- Start the API server with hot reload
- Start Redis cache
- Start a test PostgreSQL instance
- Access the API:
- API: http://localhost:8080
- Health Check: http://localhost:8080/health
make help # Show all available commands
make dev # Start development environment
make logs # View server logs
make dev-down # Stop development environment
make dev-clean # Stop and remove all volumes
# Database Migrations
make migrate-up # Run pending migrations
make migrate-down # Rollback last migration
make migrate-status # Show migration status
make migrate-create NAME=feature_name # Create new migration
make migrate-reset # Reset and rerun all migrations
# Local Development (without Docker)
make run # Run server locally
make build # Build binary
make test # Run tests
make deps # Update dependencies
# Database
make db-shell # Connect to database shellserver/
├── cmd/ # CLI commands
│ ├── main.go # Entry point
│ ├── root.go # Root command
│ ├── serve.go # Serve command
│ ├── migrate.go # Migration commands
│ └── server.go # Server initialization
├── internal/ # Internal packages
│ ├── config/ # Configuration
│ ├── handlers/ # HTTP handlers
│ ├── middleware/ # HTTP middleware
│ ├── models/ # Database models
│ ├── repository/ # Data access layer
│ └── services/ # Business logic
├── migrations/ # Database migrations
├── Dockerfile # Multi-stage Docker build
├── docker-compose.yml # Development environment
├── Makefile # Build automation
└── go.mod # Go dependencies
The server includes a CLI for various operations:
# Start the server
./rukhalt serve
# Run migrations
./rukhalt migrate up
./rukhalt migrate down
./rukhalt migrate status
./rukhalt migrate create add_feature
# Show version
./rukhalt --version
# Show help
./rukhalt --helpPOST /api/v1/auth/login- User loginPOST /api/v1/auth/register- User registrationPOST /api/v1/auth/refresh- Refresh token
GET /api/v1/dashboard/stats- Get statisticsGET /api/v1/dashboard/metrics- Get metricsGET /api/v1/dashboard/alerts- Get alerts
GET /api/v1/backup/jobs- List backup jobsPOST /api/v1/backup/jobs- Create backup jobGET /api/v1/backup/jobs/:id- Get backup jobPUT /api/v1/backup/jobs/:id- Update backup jobDELETE /api/v1/backup/jobs/:id- Delete backup jobPOST /api/v1/backup/jobs/:id/run- Run backup job
POST /api/v1/backups- Create backupGET /api/v1/backups- List backupsDELETE /api/v1/backups/:id- Delete backupPOST /api/v1/backups/:id/cancel- Cancel backupGET /api/v1/backups/:id/file- Download backupPOST /api/v1/backups/restore- Restore backup
- PostgreSQL:
/api/v1/postgres/instances - VPS:
/api/v1/vps/instances - Object Storage:
/api/v1/rustfs/instances
GET /api/v1/audit/logs- Get audit logsGET /api/v1/audit/logs/me- Get user's audit logsGET /api/v1/audit/stats- Get audit statistics
See .env.example for all available configuration options.
Migrations are managed using Goose. Migration files are in migrations/ directory.
make migrate-create NAME=add_users_tableThis creates two files:
migrations/YYYYMMDDHHMMSS_add_users_table.sql
Edit the file to add your SQL:
-- +goose Up
CREATE TABLE users (
id BIGSERIAL PRIMARY KEY,
username TEXT NOT NULL
);
-- +goose Down
DROP TABLE users;make migrate-up # Apply pending migrations
make migrate-status # Check migration status
make migrate-down # Rollback last migrationBuild production image:
docker build --target prod -t rukhalt-server:latest .Run with docker-compose (create a separate prod compose file):
docker compose -f docker-compose.prod.yml up -dThe development environment uses Air for hot reload. Any changes to .go files will automatically rebuild and restart the server.
- Create migration if database changes are needed
- Update models in
internal/models/ - Add repository methods in
internal/repository/ - Implement business logic in
internal/services/ - Create handlers in
internal/handlers/ - Register routes in
cmd/server.go
MIT