HexCore uses two classes to handle project configuration:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Indroic/HexCore/llms.txt
Use this file to discover all available pages before exploring further.
ServerConfig, a Pydantic model that holds all runtime settings, and LazyConfig, a flexible loader that resolves which module to read from at startup. This page covers every field available on ServerConfig, explains how LazyConfig determines the active configuration, and shows how to write a config.py file in your project root.
ServerConfig
ServerConfig is a Pydantic BaseModel that groups all HexCore settings in one place. Create an instance of it in your config.py and override only the fields you need; everything else falls back to a sensible default.
config.py
Project settings
Root directory of the project. Used internally by the CLI when resolving relative paths.
Server settings
Hostname the application server binds to.
Port the application server listens on.
Enables debug mode. Set to
False for production deployments.SQL database settings
Synchronous SQLAlchemy connection URL. Used by Alembic and any sync ORM sessions.
Asynchronous SQLAlchemy connection URL. Used for
async database sessions throughout HexCore’s infrastructure layer.MongoDB settings
Synchronous MongoDB connection URL.
Async MongoDB connection URL used by the Beanie ODM layer.
Name of the MongoDB database to connect to.
Full MongoDB URI including the database name. Useful for drivers that accept a combined connection string.
Redis settings
Full Redis connection URI used by the cache and event bus backends.
Redis server hostname.
Redis server port.
Redis logical database index.
Default TTL in seconds for cached values written by HexCore’s cache layer.
Cache settings
Active cache implementation. Must be an instance (or subclass instance) of
ICache. Swap in RedisCache() or your own implementation for production.CORS / security settings
List of allowed CORS origins. Defaults to
["*"] when debug=True.Whether to allow cookies and credentials in CORS requests.
HTTP methods allowed in CORS requests.
HTTP headers allowed in CORS requests.
Event bus
The active
EventBus implementation. Defaults to an in-process, in-memory bus. Replace with RedisEventBus, PostgresEventBus, or any custom EventBus subclass for distributed setups.Repository discovery
Python module paths HexCore scans when auto-wiring repositories into the Unit of Work. Each entry must be a dotted module path (e.g.
"src.infrastructure.repositories").v2 breaking change. In HexCore v2, repository discovery is fully explicit. If
repository_discovery_paths is left empty, no repository modules are auto-loaded and the Unit of Work will raise an explicit error rather than silently failing. Always set this field in your config.py.CQRS
Optional CQRS configuration object (
hexcore.application.cqrs.config.CQRSConfig). When None, CQRS is disabled and has no impact on existing modules.LazyConfig
LazyConfig is the configuration loader HexCore uses internally everywhere it needs settings — in the Unit of Work, in BaseDomainService, and in CLI commands. It caches the resolved ServerConfig instance after the first load, so there is no repeated import overhead.
Resolution priority
LazyConfig.get_config() walks through candidate module sources in this order and returns the first valid ServerConfig it finds:
HEXCORE_CONFIG_MODULE env var
If the
HEXCORE_CONFIG_MODULE environment variable is set to a dotted module path (e.g. myapp.settings), that module is imported first. HexCore looks for either a config attribute that is a ServerConfig instance or a ServerConfig subclass defined in the module.HEXCORE_CONFIG_MODULES env var
If
HEXCORE_CONFIG_MODULES is set, it is split on commas and each entry is tried in order.LazyConfig.set_config_modules(...)
You can provide module candidates programmatically — useful for testing or multi-tenant setups — by calling Calling
set_config_modules before the first get_config() call.set_config_modules also clears the cached instance, so the next get_config() re-resolves from scratch.Attribute lookup inside a module
Within each candidate module,LazyConfig looks for:
- A module-level attribute named
configthat is aServerConfiginstance. If the attribute is aServerConfigsubclass (not yet instantiated), it will be instantiated automatically. - A module-level class named
ServerConfigthat is a subclass ofhexcore.config.ServerConfig.
LazyConfig falls back to a default ServerConfig() with no custom settings.
Clearing the cache
Writing a config.py
Place aconfig.py in your project root (or wherever Python resolves the config module). The hexcore init command generates this file automatically; the example below shows what it produces for the hexagonal template.
config.py
config.py