High-level overview
- Purpose: Backend service for automated deployments of web services and static sites to user VPS machines. Provides REST endpoints to trigger deployments, list projects, delete projects and get activity logs. Also exposes a WebSocket endpoint for live deployment logs.
- Language & runtime: TypeScript targeting Bun/Node (uses Elysia framework, Bun server types present)
- Primary integrations:
- PostgreSQL (via
drizzle-orm+postgresandpgPool) - SSH to user VPS (custom
SSHClientusingssh2) - Nginx + Certbot actions executed over SSH
- S3-compatible storage for artifact URLs (
@aws-sdk/client-s3)
- PostgreSQL (via
Quick start
- Create a
.envwith required variables (see Codebase docs below for full list). Important env keys:PORT,DATABASE_URL,DEPLOY_DATABASE_URL,BASE_DIR,ACCESS_TOKEN_SECRET,ENCRYPTION_KEY,S3_REGION,S3_ENDPOINT,ACCESS_KEY_ID,SECRET_ACCESS_KEY. - Install dependencies and run the service (project uses Bun in many scripts but works under node):
# using npm (example)
npm install
npm run build
node build/index.jsOr with Bun (if used in this workspace):
bun install
bun run src/index.tsMain endpoints (summary)
GET /- Health checkPOST /deploy-webservice- Trigger a webservice deployment (protected)GET /get-projects- List deployments for authenticated user (protected)DELETE /delete-project/:id- Delete a deployed project (protected)GET /get-activity-logs- List activity logs (protected)WS /deploy-logs- WebSocket for streaming logs during deployment (requires token+machineId query params)
Security & data
- Authentication: cookie-based access token validated by
verifyTokens. Protected routes usecheckAuthmiddleware. - DB operations use parameterized queries or
drizzle-orm(prevents SQL injection when used correctly). - VPS credentials stored encrypted and decrypted with
ENCRYPTION_KEYusing AES.
Where to look next
- Server entrypoint: src/index.ts
- Controllers: src/controllers
- SSH interactions: src/SSHClient/SSHClient.ts
- Repo actions and deployment orchestration: src/repoActions
- DB schema: src/db/schema.ts
For full per-file documentation, see CODEBASE_DOCUMENTATION.md
Automated deployment backend for VPS servers, built with Elysia and Bun. It supports secure deployments, real-time logs via WebSocket, S3 file downloads, Nginx configuration, and SSL certificate management.
- REST API for deployment, build, repo management
- WebSocket for real-time deployment logs
- SSH automation for remote VPS operations
- S3 integration for build artifact download
- Nginx config & SSL certificate automation
- JWT-based authentication
- Credential encryption/decryption
Main entrypoint. Sets up Elysia server, routes, WebSocket, authentication, and deployment controller.
Handles deployment requests:
- Authenticates user
- Fetches VPS credentials from DB (
db/pool.ts) - Decrypts password (
utils/decryptPassword.ts) - Connects via SSH (
SSHClient/SSHClient.ts) - Clones repo (
repoActions/cloneBuildRepo.ts) - Installs dependencies, builds project
- Downloads build artifacts from S3 (
bucket/generateDownloadUrl.ts) - Streams logs via WebSocket (
ws/socketManager.ts) - Configures Nginx and installs SSL certificates
cloneBuildRepo.ts: Clones repo, runs install/build commands, streams logsgetRepoName.ts: Extracts repo name from URLrunRepo.ts: Starts built repo on VPS, streams logs
SSH client abstraction for command execution, sequential runs, and log streaming.
generateDownloadUrl.ts: Generates S3 pre-signed URLs for build artifact downloads3.ts: S3 client setup
decryptPassword.ts: Decrypts encrypted VPS passwordscheckUrl.ts: Validates repo URLsgeneratedDeploymentId.ts,generateId.ts: Generates unique deployment IDsgetCredentials.ts: Fetches VPS credentials from DBverifyMachine.ts: Validates machine for WebSocket log streaming
socketManager.ts: Publishes logs to WebSocket clientsstore.ts: Stores server instance for WebSocket publishing
JWT authentication middleware for API and WebSocket
Verifies JWT tokens for authentication
Database connection pool for credential and deployment data
Type definitions for status codes and shared types
Deploys a build to a specified VPS.
- Body:
{ "vpsId": "string", "repoUrl": "string", "deploymentId": "string" } - Functionality:
- Authenticates user
- Fetches VPS credentials
- Connects via SSH
- Clones repo, installs dependencies, builds project
- Downloads build from S3
- Configures Nginx, installs SSL
- Streams logs via WebSocket (
deploymentId) - Cleans up on failure
Health check endpoint.
WebSocket endpoint for real-time deployment logs.
- Query:
token,machineId - On connect:
- Authenticates user and machine
- Subscribes client to a unique
deploymentId - Sends logs for that deployment
-
Nginx Configuration: After deployment, the service can update Nginx configs on the VPS to route traffic to the deployed app.
- Example command:
sudo cp /home/ubuntu/deployments/<buildId>/nginx.conf /etc/nginx/sites-available/<site> sudo ln -s /etc/nginx/sites-available/<site> /etc/nginx/sites-enabled/ sudo systemctl reload nginx
- Example command:
-
SSL Certificate Installation: Uses Certbot to install SSL certificates for the deployed domain.
- Example command:
sudo certbot --nginx -d yourdomain.com --non-interactive --agree-tos -m admin@yourdomain.com
- Example command:
- Generates a pre-signed S3 URL for build artifacts
- Downloads the file on the VPS using
curl:curl -L "<presigned_url>" -o /home/ubuntu/deployments/<buildId>/app.zip
- Uses JWT tokens for API and WebSocket authentication
- Machine validation for secure log streaming
bun run devOpen http://localhost:3000/ in your browser.
Create a .env file with:
PORT=3000
ENCRYPTION_KEY=your_encryption_key
ENCRYPTION_ALGORITHM=AES
AWS_REGION=your-region
AWS_ACCESS_KEY_ID=your-key
AWS_SECRET_ACCESS_KEY=your-secret
AWS_BUCKET_NAME=your-bucket
- Run the service on your server
- Point Nginx to the Bun app port
- Use Certbot for SSL
MIT