Core Features
- Unified Configuration API: A single interface (
ConfigStore) for all configuration CRUD (Create, Read, Update, Delete) operations. - Multiple Backend Support: Out-of-the-box support for SQLite and PostgreSQL, with an extensible architecture for adding new database backends.
- Comprehensive Data Management: Manages a wide range of configuration data, including:
- Provider and key settings
- Virtual keys and governance rules (budgets, rate limits)
- Customer and team information for multi-tenancy
- Plugin configurations
- Vector store and log store settings
- Model pricing information
- Transactional Operations: Ensures data consistency by supporting atomic transactions for complex configuration changes.
- Database Migrations: Integrated migration system to manage schema evolution across different versions of Bifrost.
- Environment Variable Handling: Securely manages sensitive data like API keys by storing references to environment variables instead of raw values.
Architecture
The ConfigStore is designed around theConfigStore interface, which defines all the methods for interacting with the configuration data. The primary implementation is RDBConfigStore, which uses GORM as an ORM to communicate with relational databases.
Supported Backends
- SQLite: The default, file-based database, perfect for local development, testing, and single-node deployments. It requires no external services.
- PostgreSQL: A robust, production-grade database suitable for large-scale, high-availability deployments.
Initialization
The ConfigStore is initialized at startup based on the provided configuration.ConfigStore:
Connection Pool Configuration
For PostgreSQL backends, you can configure the database connection pool to optimize performance based on your workload:- MaxIdleConns: Maximum number of idle connections in the pool (default: 5)
- MaxOpenConns: Maximum number of open connections to the database (default: 50)
Data Models
The ConfigStore manages a variety of data models, which are defined as GORM tables in theframework/configstore/tables directory. Some of the key models include:
TableVirtualKey: Represents a virtual key with its associated governance rules, keys, and metadata.TableProvider&TableKey: Store provider-specific configurations and the physical API keys.TableBudget&TableRateLimit: Define spending limits and request rate limits for governance.TableCustomer&TableTeam: Enable multi-tenant configurations.TableModelPricing: Caches model pricing information for cost calculation.TablePlugin: Stores configuration for loaded plugins.
Usage
TheConfigStore interface provides a rich set of methods for managing Bifrost’s configuration.
Managing Virtual Keys
Managing Providers
Executing Transactions
For operations that require multiple database writes, you can use a transaction to ensure atomicity.Migrations
The ConfigStore includes a migration system to handle database schema changes between Bifrost versions. Migrations are automatically applied at startup, ensuring the database schema is always up-to-date. This process is managed by themigrator package and is transparent to the user.
The ConfigStore is a powerful and flexible component that provides the backbone for Bifrost’s dynamic configuration capabilities. Its support for multiple backends and transactional operations makes it suitable for both small-scale and large-scale, production environments.
