How keygen-sh/keygen-api works
Main System Components
a. API Layer
• REST API endpoints (under app/controllers/api/v1)
• Authentication & Authorization systems
• Rate limiting and request tracking
• Webhook handling
b. Core Services
• License Management
• Machine/Device Management
• User Management
• Product Management
• Release Management
• Analytics & Metrics
• Event Logging
c. Background Processing
• Sidekiq workers (under app/workers)
• Scheduled tasks
• Event broadcasting
d. Data Storage
• PostgreSQL database
• Redis for caching and Sidekiq
• S3/R2 for artifact storage
Architectural Patterns
a. Multi-tenancy Architecture
• Account isolation
• Environment separation
• Role-based access control
b. Event-Driven Architecture
• Webhook system
• Event logging
• Metrics collection
Integration Points
External service connections:
• Stripe for billing
• S3/R2 for storage
• SMTP for email delivery
• Package registry integrations (npm, RubyGems, PyPI)
Specific Design Elements
Use these visual elements:
• Blue: API endpoints
• Green: Core services
• Yellow: Background jobs
• Red: Security components
• Purple: External services
• Gray: Storage systems
b. Connection Types:
Component Relationships
Interactions:
• API Gateway → Authentication → Authorization → Controllers
• Controllers → Services → Models → Database
• Background Jobs → Services → External Services
• Event System → Webhooks → External Systems
Security Layer
Security components:
• Authentication mechanisms
• Authorization policies
• API key management
• Encryption systems
• Rate limiting
Scaling Components
Scalable components:
• Load balancers
• Database replication
• Worker pools
• Cache layers
Client Layer (Top)
• API clients
• Package managers
• Webhook consumers
Application Layer (Middle)
• API controllers
• Service objects
• Background workers
Data Layer (Bottom)
• Databases
• Caching
• File storage
• Component types
• Connection types
• Environment boundaries
• Security zones
This system design should reflect Keygen's nature as a robust, enterprise-grade licensing system with strong security, multi-tenancy, and extensibility features.