StorageLayer is a Node.js/Bun-based microservice that provides RESTful API endpoints for managing PostgreSQL database deployments on remote VPS machines via SSH. It handles database creation, deletion, table listing, and data retrieval operations securely through authenticated SSH connections.
- Framework: Elysia.js (Bun runtime)
- Database ORM: Drizzle ORM
- Authentication: JWT-based token authentication
- SSH Client: ssh2 library for remote command execution
- Database: PostgreSQL (both for metadata storage and managed databases)
- PostgreSQL Deployment: Automatically installs and configures PostgreSQL on remote VPS machines
- Database Management: Create, delete, and list databases
- Table Operations: List tables and retrieve table data from remote databases
- Security: JWT authentication, machine ownership verification, encrypted password storage
- Remote Access Configuration: Automatically configures PostgreSQL for remote connections
GET /- Health check endpoint
POST /deploy-postgres- Deploy PostgreSQL database on a VPSDELETE /delete-db/:id- Delete a deployed databaseGET /get-db- Get list of all databases for authenticated userPOST /get-tables-list- Get list of tables in a databasePOST /get-table-data- Get data from a specific table
- Runtime: Bun
- Web Framework: Elysia.js
- ORM: Drizzle ORM
- Database: PostgreSQL
- SSH: ssh2
- CSV Parsing: PapaParse
- Encryption: CryptoJS (AES)
- JWT: jsonwebtoken
PORT- Server port numberSTORAGE_LAYER_DATABASE_URL- Connection string for metadata databaseDEPLOYMENT_MANAGER_DATABASE_URL- Connection string for VPS machine registryACCESS_TOKEN_SECRET- JWT secret for token verificationENCRYPTION_KEY- AES encryption key for VPS passwords
bun installbun run devRun migrations using Drizzle Kit:
bunx drizzle-kit pushsrc/
├── controllers/ # API route handlers
├── db/ # Database configuration and schema
├── HelperClasses/ # Business logic helpers (PostgresSSHHelper)
├── middlewares/ # Authentication middleware
├── SSHClient/ # SSH connection wrapper
├── jwt/ # JWT verification utilities
├── utils/ # Utility functions
└── types/ # TypeScript type definitions
- JWT token-based authentication
- Machine ownership verification before operations
- Encrypted password storage (AES)
- SQL injection prevention through parameterized queries
- Table name validation (alphanumeric + underscore only)
- CORS protection with whitelisted origins
- Request → Authentication middleware validates JWT token
- Controller → Validates request body and verifies machine ownership
- Service → Establishes SSH connection and executes PostgreSQL commands
- Database → Updates metadata in local database
- Response → Returns success/error response to client
- VPS Machines: Requires SSH access to remote machines
- Deployment Manager Database: External database containing VPS machine registry
- Storage Layer Database: Local database for tracking deployed databases
Allowed origins:
http://localhost:5173(development)https://zyotraportal.ramkrishna.cloud(production)
[Add your license here]