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 is HexCore’s central Pydantic configuration model. It carries database URLs, Redis settings, CORS rules, the active cache backend, the event bus, repository discovery paths, and optional CQRS wiring — all in one place. LazyConfig is the lazy loader that resolves a ServerConfig instance from your project’s config module at runtime, with environment-variable overrides.
ServerConfig
hexcore.config.ServerConfig
Inherits from pydantic.BaseModel with arbitrary_types_allowed=True. All fields have sensible defaults; override only what you need.
Project fields
Root directory of the project. Used by utilities that need to resolve paths relative to the project root.
Server fields
Bind address for the HTTP server (e.g.
"0.0.0.0" for all interfaces).TCP port the server listens on.
Enables debug mode. When
True, CORS allow_origins defaults to ["*"].Database fields
Synchronous SQLAlchemy database URL. Used by any tooling that requires a synchronous engine (e.g. Alembic migrations).
Asynchronous SQLAlchemy database URL. Read by
get_engine() in the SQLAlchemy session utilities to create the AsyncEngine.Synchronous MongoDB connection string.
Asynchronous MongoDB connection string.
Default MongoDB database name.
Full MongoDB URI including the database name. Read by
init_beanie_documents() when initialising Beanie.Redis fields
Full Redis URL. Read by
RedisCache and RedisEventBus when creating connections.Redis host. Available as a convenience field when building the URI programmatically.
Redis TCP port.
Redis logical database index.
Default TTL in seconds for
RedisCache.set() when no explicit expire is passed.CORS / security fields
List of allowed CORS origins. Defaults to
["*"] in debug mode, ["http://localhost:{port}"] in production.Whether the browser is allowed to send cookies/credentials in cross-origin requests.
HTTP methods allowed in CORS preflight responses.
HTTP request headers allowed in CORS preflight responses.
Cache field
The active cache backend instance. Must implement
hexcore.infrastructure.cache.ICache. Swap to RedisCache() for production. See ICache reference.Event bus field
The active event bus instance. Defaults to the simple
InMemoryEventBus from hexcore.infrastructure.events. For distributed deployments replace with RedisEventBus, PostgresEventBus, or RabbitMQEventBus. See Event Bus Implementations.Repository discovery field
Set of Python package paths (dotted module names) that HexCore will scan for
BaseSQLAlchemyRepository and BaseBeanieRepository subclasses. When empty, no auto-discovery occurs. Example: {"myapp.infrastructure.repositories"}.CQRS field
Optional CQRS configuration block. When
None, CQRS features are disabled and have no performance impact on non-CQRS services. See CQRSConfig below.Deprecated
The
event_dispatcher field and constructor argument are deprecated aliases for event_bus. HexCore emits a DeprecationWarning when they are used. Migrate to event_bus.LazyConfig
hexcore.config.LazyConfig
Class-level lazy loader that resolves and caches a ServerConfig instance from your project’s configuration module. All resolution is deferred until get_config() is first called.
Resolution priority
Whenget_config() is called, LazyConfig tries candidate module paths in this order:
| Priority | Source | Description |
|---|---|---|
| 1 | HEXCORE_CONFIG_MODULE env var | Single module path, e.g. "myapp.settings" |
| 2 | HEXCORE_CONFIG_MODULES env var | Comma-separated list, e.g. "myapp.prod_settings,myapp.settings" |
| 3 | LazyConfig.set_config_modules(...) | Programmatically set list |
| 4 | Default | "config" (looks for config.py in the working directory) |
LazyConfig looks for:
- An attribute named
configthat is an instance (or subclass) ofServerConfig. - A class named
ServerConfigthat subclasses the baseServerConfig.
ServerConfig() (all defaults).
Class methods
Sets the list of candidate module paths and clears the cache, forcing re-resolution on the next
get_config() call.Clears the cached
ServerConfig instance without changing the candidate list. Useful in tests to force re-resolution between test cases.Resolves and returns the cached
ServerConfig instance. Thread-safe for read-heavy workloads; the first call performs the import resolution.Typical project setup
CQRSConfig
hexcore.application.cqrs.config.CQRSConfig
Declarative CQRS configuration. Set as ServerConfig.cqrs to enable the CQRS subsystem.
Master switch for the CQRS subsystem. Setting to
False disables all CQRS wiring regardless of other fields.Configuration for the query bus.
Configuration for the CQRS event bus (separate from
ServerConfig.event_bus).Dotted import path of a custom serialiser class (e.g.
"myapp.serializers.MsgPackSerializer"). When None, PydanticSerializer is used.BusConfig
hexcore.application.cqrs.config.BusConfig
Configuration for a single CQRS bus (command, query, or event). Frozen Pydantic model.
Dotted import path of the bus implementation class (e.g.
"hexcore.infrastructure.cqrs.redis_bus.RedisEventBus"). When None, the default in-memory implementation is used.Ordered list of dotted import paths for middleware classes. Middlewares are applied in list order (index 0 runs first, closest to the handler).
Arbitrary key-value options forwarded to the bus backend’s constructor or to individual middlewares.
MiddlewareConfig
hexcore.application.cqrs.config.MiddlewareConfig
Configuration for an individual middleware. Frozen Pydantic model.
When
False, the middleware is skipped entirely during pipeline construction.Execution order hint. Lower values run closer to the bus entry point (before the handler).
Arbitrary options for the middleware (e.g.
{"max_retries": 3}).