Search documentation of phoenix_kit

# PhoenixKit.ModuleRegistry (phoenix_kit v1.7.87)

Copy Markdown View Source

Runtime registry of all PhoenixKit modules (internal and external).

External modules are auto-discovered from beam files via `PhoenixKit.ModuleDiscovery`. Any dep that depends on `:phoenix_kit` and uses `use PhoenixKit.Module` is found automatically — no config line needed.

## External Module Registration

External hex packages are auto-discovered. Just add the dep:

    {:phoenix_kit_hello_world, "~> 0.1.0"}

For explicit registration (backwards compatible):

    config :phoenix_kit, :modules, [PhoenixKitHelloWorld]

## Runtime Registration

    PhoenixKit.ModuleRegistry.register(MyModule)
    PhoenixKit.ModuleRegistry.unregister(MyModule)

## Query API

    ModuleRegistry.all_modules()           # All registered module atoms
    ModuleRegistry.enabled_modules()       # Only currently enabled
    ModuleRegistry.all_admin_tabs()        # Collect admin tabs from all modules
    ModuleRegistry.all_settings_tabs()     # Collect settings tabs
    ModuleRegistry.all_user_dashboard_tabs() # Collect user dashboard tabs
    ModuleRegistry.all_children()          # Collect supervisor child specs
    ModuleRegistry.all_permission_metadata() # Collect permission metadata
    ModuleRegistry.feature_enabled_checks()  # Build {mod, :enabled?} map
    ModuleRegistry.get_by_key("tickets")   # Find module by key

## Summary

### Functions

all_admin_tabs()

Collect all admin tabs from all registered modules.

all_children()

Collect all supervisor child specs from all registered modules.

all_feature_keys()

Returns all feature module key strings from registered modules.

all_modules()

Returns all registered module atoms.

all_permission_metadata()

Collect permission metadata from all registered modules.

all_route_modules()

Collect route modules from all registered modules.

all_settings_tabs()

Collect all settings tabs from all registered modules.

all_user_dashboard_tabs()

Collect all user dashboard tabs from all registered modules.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

dependency_warnings()

Returns dependency warnings for the Modules page.

enabled_modules()

Returns all registered modules that are currently enabled.

feature_enabled_checks()

Build a feature_enabled_checks map from registered modules.

get_by_key(key)

Find a registered module by its key string.

initialized?()

Check if the registry has been initialized.

modules_with_migrations()

Collect modules that have versioned migrations.

not_installed_packages()

Returns known external PhoenixKit packages that are not currently installed.

permission_descriptions()

Returns permission descriptions map from registered modules.

permission_icons()

Returns permission icons map from registered modules.

permission_labels()

Returns permission labels map from registered modules.

register(module)

Register a module that implements PhoenixKit.Module behaviour.

start_link(opts \\ [])
static_children()

Collect supervisor child specs from the static module list.

unregister(module)

Unregister a module.

## Functions

# all_admin_tabs()

    @spec all_admin_tabs() :: [PhoenixKit.Dashboard.Tab.t()]

Collect all admin tabs from all registered modules.

Note: iterates all modules and calls `admin_tabs/0` on each call. For cached access in rendering paths, use `PhoenixKit.Dashboard.Registry.get_admin_tabs/0`.

# all_children()

    @spec all_children() :: [Supervisor.child_spec()]

Collect all supervisor child specs from all registered modules.

# all_feature_keys()

    @spec all_feature_keys() :: [String.t()]

Returns all feature module key strings from registered modules.

# all_modules()

    @spec all_modules() :: [module()]

Returns all registered module atoms.

# all_permission_metadata()

    @spec all_permission_metadata() :: [PhoenixKit.Module.permission_meta()]

Collect permission metadata from all registered modules.

# all_route_modules()

    @spec all_route_modules() :: [module()]

Collect route modules from all registered modules.

# all_settings_tabs()

    @spec all_settings_tabs() :: [PhoenixKit.Dashboard.Tab.t()]

Collect all settings tabs from all registered modules.

# all_user_dashboard_tabs()

    @spec all_user_dashboard_tabs() :: [PhoenixKit.Dashboard.Tab.t()]

Collect all user dashboard tabs from all registered modules.

# child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# dependency_warnings()

    @spec dependency_warnings() :: [map()]

Returns dependency warnings for the Modules page.

Each warning is a map: %{module: module(), module_name: String.t(), requires_key: String.t()}

Called on Modules page render — computes live (not hot path).

# enabled_modules()

    @spec enabled_modules() :: [module()]

Returns all registered modules that are currently enabled.

# feature_enabled_checks()

    @spec feature_enabled_checks() :: %{required(String.t()) => {module(), atom()}}

Build a feature_enabled_checks map from registered modules.

Returns `%{"customer_service" => {PhoenixKit.Modules.CustomerService, :enabled?}, ...}`

# get_by_key(key)

    @spec get_by_key(String.t()) :: module() | nil

Find a registered module by its key string.

# initialized?()

    @spec initialized?() :: boolean()

Check if the registry has been initialized.

# modules_with_migrations()

    @spec modules_with_migrations() :: [{String.t(), module()}]

Collect modules that have versioned migrations.

Returns a list of `{module_name, migration_module}` tuples for all registered modules that implement `migration_module/0` and return a non-nil value.

# not_installed_packages()

    @spec not_installed_packages() :: [map()]

Returns known external PhoenixKit packages that are not currently installed.

Used by the admin Modules page to inform users about available packages they can add as dependencies.

# permission_descriptions()

    @spec permission_descriptions() :: %{required(String.t()) => String.t()}

Returns permission descriptions map from registered modules.

# permission_icons()

    @spec permission_icons() :: %{required(String.t()) => String.t()}

Returns permission icons map from registered modules.

# permission_labels()

    @spec permission_labels() :: %{required(String.t()) => String.t()}

Returns permission labels map from registered modules.

# register(module)

    @spec register(module()) :: :ok

Register a module that implements PhoenixKit.Module behaviour.

# start_link(opts \\ [])

# static_children()

    @spec static_children() :: [Supervisor.child_spec()]

Collect supervisor child specs from the static module list.

This does NOT require the GenServer to be running, making it safe to call from the PhoenixKit.Supervisor init (before the registry starts).

# unregister(module)

    @spec unregister(module()) :: :ok

Unregister a module.