@x12i/xronox-router
v2.3.1
Published
Request routing and tenant resolution for Xronox with dynamic provisioning support
Maintainers
Readme
@x12i/xronox-router
Request routing and tenant resolution for Xronox with dynamic provisioning support.
🚀 Env-Ready Component (ERC 2.0)
This component supports zero-config initialization via environment variables using @x12i/env.
Quick Start
# 1. Install the package
npm install @x12i/xronox-router
# 2. Copy .env.example to .env (if using zero-config mode)
cp node_modules/@x12i/xronox-router/.env.example .env
# 3. Fill in required values in .env
# MONGO_URI=mongodb://localhost:27017
# S3_ENDPOINT=http://localhost:9000
# S3_REGION=us-east-1
# S3_ACCESS_KEY=your-access-key
# S3_SECRET_KEY=your-secret-key
# 4. Use with zero config!
import { BridgeRouter } from '@x12i/xronox-router';
const router = new BridgeRouter(); // Auto-discovers from process.envConfiguration Priority
The router supports 3-tier configuration priority:
Tier 1: Explicit Config (Advanced Mode) - Pass configuration directly to constructor
const router = new BridgeRouter({ dbConnections: { primary: { mongoUri: 'mongodb://...' } }, spacesConnections: { s3: { /* ... */ } }, databases: { /* ... */ } });Tier 2: Config File - Place
xronox.config.jsonin your project root{ "xronox": { "dbConnections": { "primary": { "mongoUri": "ENV.MONGO_URI" } }, "spacesConnections": { "s3-primary": { "endpoint": "ENV.S3_ENDPOINT", "region": "ENV.S3_REGION", "accessKey": "ENV.S3_ACCESS_KEY", "secretKey": "ENV.S3_SECRET_KEY" } }, "databases": { /* ... */ } } }Location:
xronox.config.jsonin project root (same directory aspackage.json)Tier 3: Environment Variables (Zero-Config Mode) - Auto-discover from
.envfileconst router = new BridgeRouter(); // Uses environment variables
Advanced Mode (Programmatic Configuration)
import { BridgeRouter } from '@x12i/xronox-router';
const router = new BridgeRouter({
dbConnections: {
primary: { mongoUri: 'mongodb://localhost:27017' }
},
spacesConnections: {
s3: {
endpoint: 'http://localhost:9000',
region: 'us-east-1',
accessKey: 'minioadmin',
secretKey: 'minioadmin'
}
},
databases: {
metadata: {
genericDatabase: {
dbConnRef: 'primary',
spaceConnRef: 's3',
dbName: 'athenix_metadata',
recordsBucket: 'metadata-records'
},
domainsDatabases: [],
tenantDatabases: []
}
},
hashAlgo: 'rendezvous'
});
const backend = router.route(ctx);
console.log(`Routed to: ${backend.mongoUri}`);Features
- Consistent hashing (Rendezvous/Jump Hash)
- Multi-tier architecture support
- Dynamic tenant provisioning
- Template-based naming
- Multi-bucket support
- Storage adapter abstraction
- ERC 2.0 compliant - Zero-config initialization
Logging
By default, @x12i/xronox-router emits error-only logs (quiet by default).
To enable richer local logs (debug/info/warn), set:
ENABLE_XRONOX_ROUTER_LOGXER=true
XRONOX_ROUTER_LOGS_LEVEL=debug- If
ENABLE_XRONOX_ROUTER_LOGXERis missing/empty/not"true"→ rich logging is disabled and the effective level is forced toerror. - If
ENABLE_XRONOX_ROUTER_LOGXER=true→XRONOX_ROUTER_LOGS_LEVELcontrols the effective level:debug | info | warn | error | off
- Legacy support:
XRONOX_ROUTER_LOG_LEVELis used only ifXRONOX_ROUTER_LOGS_LEVELis not set.
Environment Variables
See .env.example for the complete list of required and optional variables with descriptions.
Required Variables
MONGO_URI- MongoDB connection URI (required by mongodb package)S3_ENDPOINT- S3-compatible storage endpoint URL (required by @aws-sdk/client-s3)S3_REGION- AWS region for S3 storage (required by @aws-sdk/client-s3)S3_ACCESS_KEY- S3 access key ID (required by @aws-sdk/client-s3)S3_SECRET_KEY- S3 secret access key (required by @aws-sdk/client-s3, sensitive)
Optional Variables
All database names and bucket names have defaults. See .env.example for full list.
ERC 2.0 Compliance
- ✅ Auto-discovers configuration from environment variables
- ✅ Type-safe with automatic coercion and validation
- ✅ All dependency requirements documented (ERC and non-ERC)
- ✅ Transitive requirements automatically merged
- ✅ Automatic manifest and
.env.examplegeneration
Dependencies
- ✅ @x12i/logxer (ERC 2.0) - requirements auto-merged
- ℹ️ mongodb (non-ERC) - requirements manually documented
- ℹ️ @aws-sdk/client-s3 (non-ERC) - requirements manually documented
- ℹ️ @azure/storage-blob (non-ERC) - requirements manually documented
- ✅ @x12i/env (Configuration engine)
Verification
Verify ERC 2.0 compliance:
npx @x12i/env erc-verifyDocumentation
See specification.md for complete API documentation.
License
MIT
