Registry Pattern
Relevant source files
The following files were used as context for generating this wiki page:
The Registry Pattern in flext-auth provides a centralized mechanism for managing authentication and authorization components, including metadata, plugins, and domain-specific lookup operations. It serves as a structural foundation that decouples the definition of authentication services from their execution and discovery.
By utilizing this pattern, the system ensures that components such as FlextAuthRegistryLookup and FlextAuthRegistryMutation can interact through a standardized interface defined in FlextAuthRegistryBase. This organization facilitates lazy loading and modular extension of the authentication framework.
Sources: src/flext_auth/_registry/__init__.py, src/flext_auth/_registry/base.py
Registry Architecture
The registry is divided into specialized modules, each responsible for a distinct aspect of the authentication lifecycle. The base module provides the core abstractions, while other modules implement specific capabilities like data retrieval and state modification.
Core Components
The registry system is composed of several key classes exported through the package initializer:
| Component | Description |
|---|---|
FlextAuthRegistryBase | The base class providing common structures for all registry implementations. |
FlextAuthRegistryLookup | Handles read-only operations, searching, and identification of auth entities. |
FlextAuthRegistryMutation | Manages state-changing operations such as creating or updating identities. |
FlextAuthRegistryMetadata | Stores and retrieves structural information about registered auth providers. |
FlextAuthRegistryPlugins | Manages the lifecycle and integration of external authentication plugins. |
Sources: src/flext_auth/_registry/__init__.py:13-25
Relationship Diagram
The following diagram illustrates the structural relationship between the base registry and its specialized implementations.
This hierarchy ensures that all specialized registry modules adhere to a common architectural standard while providing distinct logic for lookup, mutation, and plugin management.
Sources: src/flext_auth/_registry/__init__.py, src/flext_auth/_registry/base.py
Implementation Details
Lazy Loading Integration
The registry utilizes flext_core.lazy to optimize performance. Imports for registry components are deferred until they are explicitly accessed. This is achieved via build_lazy_import_map and install_lazy_exports.
_LAZY_IMPORTS = build_lazy_import_map(
{
".base": ("FlextAuthRegistryBase",),
".lookup": ("FlextAuthRegistryLookup",),
".metadata": ("FlextAuthRegistryMetadata",),
".mutation": ("FlextAuthRegistryMutation",),
".plugins": ("FlextAuthRegistryPlugins",),
},
)
Sources: src/flext_auth/_registry/__init__.py:26-34
Domain Constants Interaction
The registry implementations rely on FlextAuthConstants for type-safe validation and standardized identifiers. These constants define valid token types, provider types (JWT, LDAP, SAML), and role types (Admin, User, Guest).
- Provider Types: Defines the backend authentication mechanisms the registry can manage.
- Role Types: Standardized roles used during registry mutations to assign permissions.
- Algorithms: Enumerates supported JWT algorithms (HS256, RS256) used in metadata registration.
Sources: src/flext_auth/history.json: "constants.py"
Operation Flow
The flow of information through the registry typically starts with a lookup to verify existing state before applying a mutation or loading a plugin.
The diagram shows how requests are routed through specific registry interfaces depending on whether they are read or write operations.
Sources: src/flext_auth/_registry/lookup.py, src/flext_auth/_registry/mutation.py
Summary
The Registry Pattern in flext-auth centralizes the management of authentication domain logic. By separating concerns into base, lookup, mutation, and plugin modules, the architecture provides a scalable and maintainable way to handle enterprise authentication requirements. It integrates tightly with flext-core lazy loading utilities and domain constants to ensure strict typing and optimal resource usage.