2026-03-31 09:53:37 +00:00
# DCRouter Storage Overview
2026-03-31 15:31:16 +00:00
DCRouter uses a **unified database layer ** backed by `@push.rocks/smartdata` for all persistent data. All data is stored as typed document classes in a single database.
2026-03-31 09:53:37 +00:00
2026-03-31 15:31:16 +00:00
## Database Modes
2026-03-31 09:53:37 +00:00
2026-03-31 15:31:16 +00:00
### Embedded Mode (default)
When no external MongoDB URL is provided, DCRouter starts an embedded `LocalSmartDb` (Rust-based MongoDB-compatible engine) via `@push.rocks/smartdb` .
2026-03-31 09:53:37 +00:00
```
2026-03-31 15:31:16 +00:00
~/.serve.zone/dcrouter/tsmdb/
2026-03-31 09:53:37 +00:00
```
2026-03-31 15:31:16 +00:00
### External Mode
Connect to any MongoDB-compatible database by providing a connection URL.
2026-03-31 09:53:37 +00:00
```typescript
2026-03-31 15:31:16 +00:00
dbConfig: {
mongoDbUrl: 'mongodb://host:27017',
dbName: 'dcrouter',
2026-03-31 09:53:37 +00:00
}
```
2026-03-31 15:31:16 +00:00
## Configuration
2026-03-31 09:53:37 +00:00
```typescript
2026-03-31 15:31:16 +00:00
dbConfig: {
enabled: true, // default: true
mongoDbUrl: undefined, // default: embedded LocalSmartDb
storagePath: '~/.serve.zone/dcrouter/tsmdb', // default (embedded mode only)
dbName: 'dcrouter', // default
cleanupIntervalHours: 1, // TTL cleanup interval
}
2026-03-31 09:53:37 +00:00
```
2026-03-31 15:31:16 +00:00
## Document Classes
2026-03-31 09:53:37 +00:00
2026-03-31 15:31:16 +00:00
All data is stored as smartdata document classes in `ts/db/documents/` .
2026-03-31 09:53:37 +00:00
2026-03-31 15:31:16 +00:00
| Document Class | Collection | Unique Key | Purpose |
|---|---|---|---|
| `StoredRouteDoc` | storedRoutes | `id` | Programmatic routes (created via API) |
| `RouteOverrideDoc` | routeOverrides | `routeName` | Hardcoded route enable/disable overrides |
| `ApiTokenDoc` | apiTokens | `id` | API tokens (hashed secrets, scopes, expiry) |
| `VpnServerKeysDoc` | vpnServerKeys | `configId` (singleton) | VPN server Noise + WireGuard keypairs |
| `VpnClientDoc` | vpnClients | `clientId` | VPN client registrations |
| `AcmeCertDoc` | acmeCerts | `domainName` | ACME certificates and keys |
| `ProxyCertDoc` | proxyCerts | `domain` | SmartProxy TLS certificates |
| `CertBackoffDoc` | certBackoff | `domain` | Per-domain cert provision backoff state |
| `RemoteIngressEdgeDoc` | remoteIngressEdges | `id` | Edge node registrations |
| `VlanMappingsDoc` | vlanMappings | `configId` (singleton) | MAC-to-VLAN mapping table |
| `AccountingSessionDoc` | accountingSessions | `sessionId` | RADIUS accounting sessions |
| `CachedEmail` | cachedEmails | `id` | Email metadata (TTL: 30 days) |
| `CachedIPReputation` | cachedIPReputation | `ipAddress` | IP reputation results (TTL: 24 hours) |
2026-03-31 09:53:37 +00:00
2026-03-31 15:31:16 +00:00
## Architecture
2026-03-31 09:53:37 +00:00
2026-03-31 15:31:16 +00:00
```
DcRouterDb (singleton)
├── LocalSmartDb (embedded, Rust) ─── or ─── External MongoDB
└── SmartdataDb (ORM)
└── @Collection (() => getDb())
├── StoredRouteDoc
├── RouteOverrideDoc
├── ApiTokenDoc
├── VpnServerKeysDoc / VpnClientDoc
├── AcmeCertDoc / ProxyCertDoc / CertBackoffDoc
├── RemoteIngressEdgeDoc
├── VlanMappingsDoc / AccountingSessionDoc
├── CachedEmail (TTL)
└── CachedIPReputation (TTL)
2026-03-31 09:53:37 +00:00
```
2026-03-31 15:31:16 +00:00
### TTL Cleanup
2026-03-31 09:53:37 +00:00
2026-03-31 15:31:16 +00:00
`CacheCleaner` runs on a configurable interval (default: 1 hour) and removes expired documents where `expiresAt < now()` .
2026-03-31 09:53:37 +00:00
2026-03-31 15:31:16 +00:00
## Disabling
2026-03-31 09:53:37 +00:00
2026-03-31 15:31:16 +00:00
For tests or lightweight deployments without persistence:
2026-03-31 09:53:37 +00:00
```typescript
2026-03-31 15:31:16 +00:00
dbConfig: { enabled: false }
2026-03-31 09:53:37 +00:00
```