Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:24kchengYe MemoMind Plugin Extension Architecture

From Leeroopedia
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

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment