Principle:24kchengYe MemoMind Plugin Extension Architecture
| Knowledge Sources | |
|---|---|
| Domains | Software_Architecture, Extensibility |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Software architecture pattern that enables runtime customization of application behavior through dynamically loaded extension modules configured via environment variables.
Description
The Plugin Extension Architecture decouples core application logic from optional features by defining abstract extension base classes and a controlled context API. Extensions are loaded at startup from environment variables (e.g., `HINDSIGHT_API_TENANT_EXTENSION=mypackage:MyExtension`) — no code changes needed. Each extension receives a controlled `ExtensionContext` providing safe access to system internals (database pool, memory engine, migration runner) rather than direct access.
The pattern solves the problem of making a package customizable without forking: users configure extensions purely via environment variables, and the extension base classes (Extension, HttpExtension, MCPExtension, TenantExtension, OperationValidatorExtension) define specific hooks for different customization points (HTTP endpoints, MCP tools, authentication, operation validation).
Usage
Use this principle when designing a system that must support optional features deployed by different users. Key design decisions:
- Extension points defined as ABCs with specific hooks
- Controlled context API instead of direct internal access
- Environment-variable-based configuration (zero code changes)
- Lifecycle management (on_startup, on_shutdown)
Theoretical Basis
The pattern combines the Strategy Pattern (pluggable behavior) with Dependency Injection (context provides dependencies) and Template Method (base class defines lifecycle, subclasses override hooks):
# Abstract base defines the lifecycle and hooks
class Extension(ABC):
def __init__(self, config: dict[str, str]): ...
def set_context(self, context: ExtensionContext) -> None: ...
async def on_startup(self) -> None: ... # Override point
async def on_shutdown(self) -> None: ... # Override point
# Loader discovers and instantiates from env vars
def load_extension(prefix: str, base_class: type[T]) -> T | None:
ext_path = os.getenv(f"HINDSIGHT_API_{prefix}_EXTENSION")
module_path, class_name = ext_path.split(":")
# ... import, instantiate, call set_context
Related Pages
- Implementation:24kchengYe_MemoMind_Extension
- Implementation:24kchengYe_MemoMind_ExtensionContext
- Implementation:24kchengYe_MemoMind_load_extension
- Implementation:24kchengYe_MemoMind_HttpExtension
- Implementation:24kchengYe_MemoMind_MCPExtension
- Implementation:24kchengYe_MemoMind_TenantExtension
- Implementation:24kchengYe_MemoMind_OperationValidatorExtension