System Architecture
KeyBox is a distributed license management system built on a three-tier architecture:API Request Flow
When a client validates a license, KeyBox follows this request flow:Validation Endpoint
The validation controller implements a two-tier lookup strategy:~/workspace/source/apps/server/src/controllers/redisLicense.controller.ts
Redis cache hits serve validation requests in sub-millisecond time, significantly reducing database load.
Validation Process
KeyBox performs comprehensive validation checks in this order:1. License Existence
1. License Existence
Verifies the license key exists in the database.
2. Machine ID Verification
2. Machine ID Verification
Checks if the license is bound to the correct machine (if activated).
3. Status Verification
3. Status Verification
Checks the current license status:
- PENDING: License created but not yet activated
- ACTIVE: License is valid and active
- EXPIRED: License has passed expiration date
- REVOKED: License manually revoked by developer
4. Expiration Check
4. Expiration Check
For active licenses, validates the current date against
expiresAt.Caching Strategy
KeyBox uses Redis for intelligent license caching:Cache Configuration
~/workspace/source/apps/server/src/cache/license.cache.ts
Cache Operations
Write-Through Caching
When MongoDB is queried, results are immediately cached to Redis with a 7-day TTL
Cache Invalidation
Cache is invalidated when license state changes (activation, revocation, expiration)
License Creation Flow
When a new license is created:~/workspace/source/apps/server/src/controllers/license.controller.ts
New licenses start with
PENDING status and transition to ACTIVE only upon first activation.Automated License Expiration
KeyBox includes a cron job for automatic license expiration:~/workspace/source/apps/server/src/api/cron/expired-licenses.ts
The cron job runs on Vercel’s infrastructure and is protected by the
x-vercel-cron header to prevent unauthorized execution.Performance Characteristics
| Operation | With Redis | Without Redis |
|---|---|---|
| License Validation | < 1ms | 50-100ms |
| Cache Hit Rate | ~95% | 0% |
| Database Load | 5% of requests | 100% of requests |
Security Considerations
- All API endpoints require authentication via JWT middleware
- Machine IDs are hashed using SHA-256 for privacy
- License keys are unique and indexed for fast lookups
- Rate limiting prevents brute-force validation attempts
- Cron endpoints are protected by Vercel’s authentication headers
Next Steps
License Lifecycle
Learn about license states and transitions
Machine Binding
Understand device-level license enforcement