Application Bootstrap

The ui.app module contains the dependency wiring for the full application. create_application() is the single function that assembles all services, registries, and the Qt window, then returns a ready-to-run application.

Wiring Diagram

graph TD
    R["SqliteGraphRepository(:memory:)"]
    E["GraphEngine(repository)"]
    TR["TypeRegistry"]
    MR["ModuleRegistry"]
    ML["ModuleLoader"]
    GS["GraphService(engine, type_registry)"]
    WS["WorkspaceService()"]
    EB["AppEventBus"]
    MW["MainWindow(module_registry, graph_service, workspace_service, event_bus)"]

    R --> E
    E --> GS
    TR --> GS
    ML --> TR
    ML --> MR
    GS --> MW
    WS --> MW
    MR --> MW
    EB --> MW

Runtime Module Loading

create_application() no longer imports concrete modules directly. It loads them through ModuleLoader, which reads modules.yaml and then registers loaded graph types into TypeRegistry and loaded descriptors into ModuleRegistry.

Lookup order:

  1. KNOWLEDGE_PLATFORM_MODULES_FILE
  2. ~/.knowledge_platform/modules.yaml
  3. the packaged default config

Example:

version: 1
strict: true
modules:
  - id: outline
    enabled: true
    source: entry_point

Host Persistence Model

The bootstrap still creates an in-memory repository for the initial engine, but the running app switches GraphService over to the selected workspace repository when a workspace is created or opened. In practice, user graphs persist in the workspace SQLite file.

API Reference

knowledge_platform.ui.app.create_application

create_application() -> tuple[QApplication, MainWindow]

Wire all services and return a ready-to-run application.

Returns:

Type Description
QApplication

A tuple of (:class:QApplication, :class:MainWindow). Call

MainWindow

app.exec() to enter the Qt event loop.

Source code in src/knowledge_platform/ui/app.py
def create_application() -> tuple[QApplication, MainWindow]:
    """Wire all services and return a ready-to-run application.

    Returns:
        A tuple of (:class:`QApplication`, :class:`MainWindow`).  Call
        ``app.exec()`` to enter the Qt event loop.
    """
    _configure_logging()

    # ------------------------------------------------------------------
    # Persistence + engine (in-memory for now; swap for a real path later)
    # ------------------------------------------------------------------
    repository = SqliteGraphRepository(":memory:")
    engine = GraphEngine(repository)

    # ------------------------------------------------------------------
    # Type registry + module registration
    # ------------------------------------------------------------------
    type_registry = TypeRegistry()
    module_registry = ModuleRegistry()

    ModuleLoader().register_into(type_registry, module_registry)

    # ------------------------------------------------------------------
    # Services
    # ------------------------------------------------------------------
    graph_service = GraphService(engine, type_registry)
    workspace_service = WorkspaceService()

    # ------------------------------------------------------------------
    # Qt application
    # ------------------------------------------------------------------
    app = QApplication.instance() or QApplication(sys.argv)
    event_bus = AppEventBus()

    window = MainWindow(
        module_registry=module_registry,
        graph_service=graph_service,
        workspace_service=workspace_service,
        event_bus=event_bus,
    )
    window.load_modules()
    window.show()

    logger.info("application.started")
    return app, window