- Complete Deno-based architecture following nupst/spark patterns - SQLite database with full schema - Docker container management - Service orchestration (Docker + Nginx + DNS + SSL) - Registry authentication - Nginx reverse proxy configuration - Cloudflare DNS integration - Let's Encrypt SSL automation - Background daemon with metrics collection - HTTP API server - Comprehensive CLI - Cross-platform compilation setup - NPM distribution wrapper - Shell installer script Core features: - Deploy containers with single command - Automatic domain configuration - Automatic SSL certificates - Multi-registry support - Metrics and logging - Systemd integration Ready for Angular UI implementation and testing.
7.1 KiB
Onebox - Project Hints
Architecture Overview
Onebox is a Deno-based self-hosted container platform that compiles to standalone binaries. It follows the same architectural patterns as nupst and spark projects.
Core Components
-
OneboxDatabase (
ts/onebox.classes.database.ts)- SQLite-based storage
- Tables: services, registries, nginx_configs, ssl_certificates, dns_records, metrics, logs, users, settings
- Migration system for schema updates
-
OneboxDockerManager (
ts/onebox.classes.docker.ts)- Docker API integration via @apiclient.xyz/docker
- Container lifecycle management
- Network management (onebox-network bridge)
- Stats collection and logging
-
OneboxServicesManager (
ts/onebox.classes.services.ts)- High-level service orchestration
- Coordinates Docker + Nginx + DNS + SSL
- Service deployment workflow
-
OneboxRegistriesManager (
ts/onebox.classes.registries.ts)- Docker registry authentication
- Credential storage (encrypted)
- Auto-login on daemon start
-
OneboxNginxManager (
ts/onebox.classes.nginx.ts)- Nginx reverse proxy configuration
- Config file generation
- SSL enablement
- Reload and testing
-
OneboxDnsManager (
ts/onebox.classes.dns.ts)- Cloudflare API integration
- Automatic A record creation
- DNS sync and verification
-
OneboxSslManager (
ts/onebox.classes.ssl.ts)- Let's Encrypt integration via certbot
- Certificate issuance and renewal
- Expiry monitoring
-
OneboxDaemon (
ts/onebox.classes.daemon.ts)- Background monitoring loop
- Metrics collection (every 60s by default)
- SSL certificate renewal checks
- Service health monitoring
- Systemd integration
-
OneboxHttpServer (
ts/onebox.classes.httpserver.ts)- REST API endpoints
- Static file serving (for Angular UI)
- Authentication middleware
-
Onebox (
ts/onebox.classes.onebox.ts)- Main coordinator class
- Initializes all components
- Provides unified API
CLI Structure
onebox service- Service managementonebox registry- Registry credentialsonebox dns- DNS recordsonebox ssl- SSL certificatesonebox nginx- Nginx controlonebox daemon- Systemd daemononebox config- Settings managementonebox status- System status
Deployment Workflow
- User runs:
onebox service add myapp --image nginx --domain app.example.com - Service record created in database
- Docker image pulled from registry
- Container created and started
- Nginx config generated and reloaded
- DNS record created (if configured)
- SSL certificate obtained (if configured)
- Service is live!
Configuration
Settings stored in database (settings table):
cloudflareAPIKey- Cloudflare API keycloudflareEmail- Cloudflare emailcloudflareZoneID- Cloudflare zone IDacmeEmail- Let's Encrypt emailserverIP- Server public IPnginxConfigDir- Custom nginx config directoryhttpPort- HTTP server port (default: 3000)metricsInterval- Metrics collection interval (default: 60000ms)logRetentionDays- Log retention period
Data Locations
- Database:
/var/lib/onebox/onebox.db - Nginx configs:
/etc/nginx/sites-available/onebox-* - SSL certificates:
/etc/letsencrypt/live/<domain>/ - Certbot webroot:
/var/www/certbot
Development
Running Locally
# Development mode
deno task dev
# Run tests
deno task test
# Compile all binaries
deno task compile
Adding a New Feature
- Create new class in
ts/onebox.classes.<name>.ts - Add to main Onebox class in
ts/onebox.classes.onebox.ts - Add CLI commands in
ts/onebox.cli.ts - Add API endpoints in
ts/onebox.classes.httpserver.ts - Update types in
ts/onebox.types.ts - Add tests in
test/ - Update documentation
Database Migrations
Add migration logic in OneboxDatabase.runMigrations():
if (currentVersion === 1) {
this.db.query('ALTER TABLE services ADD COLUMN new_field TEXT');
this.setMigrationVersion(2);
}
TODO
Core Functionality (Complete ✓)
- Database layer with SQLite
- Docker integration
- Service management
- Registry authentication
- Nginx reverse proxy
- DNS management (Cloudflare)
- SSL certificates (Let's Encrypt)
- Background daemon
- HTTP API server
- CLI commands
- Build system
Next Steps
- Angular UI implementation
- Dashboard with service cards
- Service deployment form
- Logs viewer
- Metrics charts
- Settings page
- Authentication system (JWT)
- Login endpoint
- Token validation middleware
- Password hashing (bcrypt)
- WebSocket support for real-time logs/metrics
- Health checks for services
- Backup/restore functionality
- Multi-server support
- Load balancing
- Service templates/blueprints
Testing
- Unit tests for all managers
- Integration tests for deployment workflow
- Mock Docker API for tests
- Database migration tests
Documentation
- API documentation (OpenAPI/Swagger)
- Architecture diagram
- Deployment guide
- Troubleshooting guide
- Video tutorial
Common Issues
Docker Connection
If Docker commands fail, ensure:
- Docker daemon is running:
systemctl status docker - User has Docker permissions:
usermod -aG docker $USER - Socket exists:
ls -l /var/run/docker.sock
Nginx Issues
If nginx fails to reload:
- Check syntax:
onebox nginx test - Check logs:
journalctl -u nginx -n 50 - Verify config files exist in
/etc/nginx/sites-available/
SSL Certificate Issues
If certbot fails:
- Verify domain DNS points to server
- Check port 80 is accessible
- Verify nginx is serving
.well-known/acme-challenge/ - Check certbot logs:
journalctl -u certbot -n 50
Cloudflare DNS Issues
If DNS records aren't created:
- Verify API credentials:
onebox config show - Check zone ID matches your domain
- Verify API key has DNS edit permissions
Dependencies
Deno Packages
@std/path- Path utilities@std/fs- Filesystem operations@std/http- HTTP server@db/sqlite- SQLite database
NPM Packages (via Deno)
@push.rocks/smartdaemon- Systemd integration@apiclient.xyz/docker- Docker API client@apiclient.xyz/cloudflare- Cloudflare API client@push.rocks/smartacme- ACME/Let's Encrypt
System Dependencies
docker- Container runtimenginx- Reverse proxycertbot- SSL certificatessystemd- Service management
Release Process
- Update version in
deno.json - Update
changelog.md - Commit changes
- Run
deno task compileto build all binaries - Test binaries on each platform
- Create git tag:
git tag v1.0.0 - Push tag:
git push origin v1.0.0 - Create Gitea release and upload binaries
- Publish to npm:
pnpm publish
Notes
- Onebox requires root privileges for nginx, Docker, and port binding
- Default admin password should be changed immediately after installation
- Use
--debugflag for verbose logging - All Docker containers are on the
onebox-networkbridge - Metrics are collected every 60 seconds by default
- SSL certificates auto-renew 30 days before expiry