2025-11-25 23:27:27 +00:00
# Onebox Project Hints
## SSL Certificate Storage (November 2025)
SSL certificates are now stored directly in the SQLite database as PEM content instead of file paths:
2026-03-24 20:08:25 +00:00
2025-11-25 23:27:27 +00:00
- `ISslCertificate` and `ICertificate` interfaces use `certPem` , `keyPem` , `fullchainPem` properties
- Database migration 8 converted the `certificates` table schema
- No filesystem storage for certificates - everything in DB
- `reverseproxy.ts` reads certificate PEM content from database
- `certmanager.ts` stores SmartACME certificates directly to database
## Architecture Notes
### Database Layer (November 2025 Refactoring)
The database layer has been refactored into a repository pattern:
**Directory Structure: **
2026-03-24 20:08:25 +00:00
2025-11-25 23:27:27 +00:00
```
ts/database/
├── index.ts # Main OneboxDatabase class (composes repositories, handles migrations)
├── types.ts # Shared types (TBindValue, TQueryFunction)
├── base.repository.ts # Base repository class
└── repositories/
├── index.ts # Repository exports
├── service.repository.ts # Services CRUD
├── registry.repository.ts # Registries + Registry Tokens
├── certificate.repository.ts # Domains, Certificates, Cert Requirements, SSL Certificates (legacy)
├── auth.repository.ts # Users, Settings
├── metrics.repository.ts # Metrics, Logs
└── platform.repository.ts # Platform Services, Platform Resources
```
**Import paths: **
2026-03-24 20:08:25 +00:00
2025-11-25 23:27:27 +00:00
- Main: `import { OneboxDatabase } from './database/index.ts'`
- Legacy (deprecated): `import { OneboxDatabase } from './classes/database.ts'` (re-exports from new location)
**API Compatibility: **
2026-03-24 20:08:25 +00:00
2025-11-25 23:27:27 +00:00
- The `OneboxDatabase` class maintains the same public API
- All methods delegate to the appropriate repository
- No breaking changes for existing code
2026-04-28 21:30:48 +00:00
## Current Migration Version: 15
2025-11-25 23:27:27 +00:00
2026-04-28 21:30:48 +00:00
Migration 15 renames the core reverse proxy platform service from `caddy` to `smartproxy` .
2025-11-26 09:36:40 +00:00
2026-04-28 21:30:48 +00:00
## Reverse Proxy (April 2026 - SmartProxy Docker Service)
2025-11-26 09:36:40 +00:00
2026-04-28 21:30:48 +00:00
The reverse proxy uses **SmartProxy ** running as a Docker Swarm service for production-grade reverse proxying with TLS termination and WebSocket handling.
2025-11-26 12:16:50 +00:00
**Architecture: **
2026-03-24 20:08:25 +00:00
2026-04-28 21:30:48 +00:00
- SmartProxy runs as Docker Swarm service (`onebox-smartproxy` ) on the overlay network
- No host binary download required - uses `code.foss.global/host.today/ht-docker-smartproxy:latest`
- Routes are pushed dynamically via the SmartProxy admin API (host port 2019)
2025-11-26 12:16:50 +00:00
- Automatic HTTPS disabled - certificates managed externally via SmartACME
- Zero-downtime configuration updates
2025-11-26 13:51:48 +00:00
- Services reached by Docker service name (e.g., `onebox-hello-world:80` )
2025-11-26 09:36:40 +00:00
**Key files: **
2026-03-24 20:08:25 +00:00
2026-04-28 21:30:48 +00:00
- `ts/classes/smartproxy.ts` - SmartProxyManager class for Docker service and Admin API
- `ts/classes/reverseproxy.ts` - Delegates to SmartProxyManager
2025-11-26 09:36:40 +00:00
**Certificate workflow: **
2026-03-24 20:08:25 +00:00
2025-11-26 09:36:40 +00:00
1. `CertRequirementManager` creates requirements for domains
2. Daemon processes requirements via `certmanager.ts`
3. Certificates stored in database (PEM content)
2026-04-28 21:30:48 +00:00
4. `reverseProxy.addCertificate()` passes PEM content to SmartProxy route config
5. SmartProxy serves TLS with the loaded certificates (no volume mounts needed)
2025-11-26 13:51:48 +00:00
**Docker Service Configuration: **
2026-03-24 20:08:25 +00:00
2026-04-28 21:30:48 +00:00
- Service name: `onebox-smartproxy`
- Image: `code.foss.global/host.today/ht-docker-smartproxy:latest`
2025-11-26 13:51:48 +00:00
- Network: `onebox-network` (overlay, attachable)
2026-04-28 21:30:48 +00:00
- Startup: SmartProxy daemon admin API listens on container port 3000, published on host port 2019
2025-11-26 13:51:48 +00:00
**Port Mapping: **
2026-03-24 20:08:25 +00:00
2025-11-26 13:51:48 +00:00
- Dev mode: HTTP on 8080, HTTPS on 8443, Admin on 2019
- Production: HTTP on 80, HTTPS on 443, Admin on 2019
- All ports use `PublishMode: 'host'` for direct binding
**Log Receiver: **
2026-03-24 20:08:25 +00:00
2026-04-28 21:30:48 +00:00
- `ProxyLogReceiver` remains the host-side access-log stream endpoint for proxy log integrations