Introducing a new way to review your PRs.

Read the announcement

combodo / itop

A simple, web based CMDB & IT Service Management tool

View on GitHub

17 documents · Updated Nov 20, 2026

docs / startup-and-module-composition

Startup and module composition

iTop starts by selecting an application environment, loading its configuration, and building the in-memory data model that serves the request. It then connects modules and extensions to shared services, events, caches, and interface-based extension points. This page gives the runtime view; see Platform runtime and extensibility for the wider platform model and Installation and upgrades for the change-time view.

Startup lifecycle

The startup lifecycle turns a request into a ready application. Environment choice comes first because it selects the configuration and module set; model startup follows because later services need the loaded classes and metadata.

Environment selection

The active environment is kept in the session when a request selects one. The default environment is used when no prior choice exists. A build environment cannot serve as a runtime target. Switching environments disables normal cache use and clears PHP code caches so that classes from the old model do not remain active. (application/startup.inc.php• L67-80, sources/…/StartupService.php• L18-51)

The startup sequence then loads the environment configuration and starts the data model. A failed database connection is reported as a startup failure rather than exposed as a raw connection error. (application/startup.inc.php• L71-80)

References: application/startup.inc.php• L67-80 sources/…/StartupService.php• L18-56

Model startup

The data model is the shared runtime description of classes, fields, states, and relations. Model startup loads configuration, core support code, environment-generated code, and configured add-ons before it restores or builds model metadata. The result is used by the user interface, services, queries, and module hooks. (core/metamodel.class.php• L5754-5796, core/metamodel.class.php• L5807-5959)

Startup is guarded so that one process does not load a second environment into the same model state. This makes the selected environment a process-wide choice for normal web execution. (core/metamodel.class.php• L5754-5767)

References: application/startup.inc.php• L71-80 core/metamodel.class.php• L5754-5796 core/metamodel.class.php• L5807-5959

Configuration model

Configuration supplies the values that shape startup and module behavior. It combines application settings with module-specific settings and makes those values available after the model is ready.

Application settings

The configuration service defines each application setting with a type and a default value. It starts from those defaults, reads the environment file, expands deployment values, converts recognized settings to their declared types, and records their source. It also checks that the file exists and can be read. (core/config.class.inc.php• L1854-1919, core/config.class.inc.php• L2038-2077, core/config.class.inc.php• L2102-2187)

Configuration loading accepts the expected settings arrays and rejects PHP errors, syntax output, or missing required data. This keeps an invalid environment file from becoming a partly initialized runtime. (core/config.class.inc.php• L2129-2184)

Deployment-specific values can use %env(NAME)% or %server(NAME)% placeholders. A placeholder can include a fallback such as %env(NAME)?:value%, and the resolver applies the same rule inside arrays. A missing value without a fallback is a configuration error. (core/config.class.inc.php• L2936-3016)

The configuration affects shared concerns such as logging, query caching, language, encryption, and access mode. Startup applies these values before it loads dictionaries and module code so that early failures use the intended settings. The application secret is generated for the process and supports protected framework state such as encrypted remember-me cookies and signed URIs. (core/metamodel.class.php• L5817-5865, core/config.class.inc.php• L2020-2027, core/config.class.inc.php• L2049-2071)

Configuration can also be rendered back to a PHP configuration file. The writer preserves selected source expressions when it can and writes application settings, module settings, and add-on entries as one configuration contract. (core/config.class.inc.php• L2568-2600, core/config.class.inc.php• L2612-2759)

References: core/config.class.inc.php• L1854-1919 core/config.class.inc.php• L2020-2077 core/config.class.inc.php• L2102-2187 core/config.class.inc.php• L2568-2759 core/config.class.inc.php• L2936-3016 core/metamodel.class.php• L5817-5865

Module settings

Module settings let a module receive values without owning the whole application configuration. A value written in the environment configuration takes priority; when it is absent, the module's declared parameter supplies the fallback. (core/config.class.inc.php• L2189-2195, core/config.class.inc.php• L2214-2245)

This split keeps module defaults with the module while allowing an environment to override them. A module can therefore use the same declared contract in more than one environment. (core/config.class.inc.php• L2214-2251)

When setup rebuilds configuration from a module directory, it orders the modules by dependency, keeps selected module values, fills missing values from module declarations, and gives active modules a chance to prepare the generated configuration. (core/config.class.inc.php• L2785-2878)

References: core/config.class.inc.php• L2189-2195 core/config.class.inc.php• L2214-2251 core/config.class.inc.php• L2785-2878

Module composition

Modules are the units that add data-model behavior and related resources to iTop. Runtime composition discovers the available modules, chooses the applicable version, removes modules declared as unavailable, and orders the rest so that dependencies are ready first.

Module declarations

Each module declaration identifies a module and describes its label, dependencies, setup status, model files, data files, and optional installer. The declaration is metadata for composition; it does not by itself mean that every optional module is active. (setup/modulediscovery.class.inc.php• L78-103, datamodels/…/module.itop-structure.php• L3-51)

The module reader examines declarations without running their full module code during discovery. It accepts the supported declaration form, extracts the module identity and settings, and rejects malformed files. This lets setup inspect available modules before it commits to a composition. (setup/…/ModuleFileReader.php• L69-113)

References: setup/modulediscovery.class.inc.php• L78-103 setup/…/ModuleFileReader.php• L69-113 datamodels/…/module.itop-structure.php• L3-51

Module discovery

Module discovery scans configured module roots and identifies files that follow the module declaration convention. It records the module metadata and keeps the newest discovered version for a module name. It can also ignore modules that belong to extensions marked as removed. (setup/modulediscovery.class.inc.php• L121-199, setup/modulediscovery.class.inc.php• L258-294, setup/modulediscovery.class.inc.php• L407-450)

The same discovery result supports setup analysis and model assembly. A caller can request all visible candidates or a dependency-ordered set for a selected group of modules. (setup/modulediscovery.class.inc.php• L280-328)

References: setup/modulediscovery.class.inc.php• L121-199 setup/modulediscovery.class.inc.php• L258-328 setup/modulediscovery.class.inc.php• L407-450

Dependency ordering

Dependency ordering produces a deterministic module sequence in which a module's prerequisites appear first. The resolver reports unresolved dependencies when the caller requires a complete composition. This prevents a partial module set from being treated as a valid installation or model. (setup/…/moduledependencysort.class.inc.php• L34-107)

The order also gives stable results when several modules can load at the same point. Missing dependencies remain visible as module-specific setup errors instead of failing later as unrelated class or model errors. (setup/…/moduledependencysort.class.inc.php• L56-106)

References: setup/…/moduledependencysort.class.inc.php• L34-107 setup/modulediscovery.class.inc.php• L201-230

Extension registration

Extensions add behavior by making classes available to known extension points. iTop keeps a map of extension class names by interface, then creates plugin instances only when a consumer asks for them.

Extension class registration

During model preparation, iTop groups instantiable declared classes under supported extension interfaces. These groups cover model hooks, login and UI hooks, query changes, event setup, and module lifecycle actions. (core/metamodel.class.php• L7029-7071)

The older MetaModel::EnumPlugins and MetaModel::GetPlugins APIs expose the registered groups. The plugin manager can filter a group by a parent type and returns either all matching instances or one named instance. (core/metamodel.class.php• L6802-6827, core/pluginmanager.class.inc.php• L28-87)

References: core/metamodel.class.php• L6802-6827 core/metamodel.class.php• L7029-7071 application/…/iModuleExtension.php• L1-16

Plugin instantiation

Plugin construction is lazy at the interface level. The first request for an interface creates its instantiable classes and stores the result for later requests. A class that cannot be loaded or cannot be instantiated does not become an active plugin. (core/pluginmanager.class.inc.php• L35-64, core/plugininstanciationmanager.class.inc.php• L8-25)

This model keeps startup work focused on the extension points that the running request needs. It also means that a plugin contract must provide a usable class before its consumer asks for it. (core/plugininstanciationmanager.class.inc.php• L10-24)

References: core/pluginmanager.class.inc.php• L35-87 core/plugininstanciationmanager.class.inc.php• L8-25

Startup services

Startup services connect the ready model to runtime behavior. They use explicit startup hooks or service registration so that modules can add behavior without changing the central request flow.

Model startup hooks

After the model selects its database and loads its classes, module handlers receive a model-started hook. The event service starts after this point because its own setup classes depend on the loaded model and extension classes. (core/modulehandler.class.inc.php• L20-50, core/metamodel.class.php• L5785-5796)

The startup order is therefore a contract: model-dependent hooks run after model preparation, and event registration runs after interface discovery can see the relevant classes. (core/metamodel.class.php• L5777-5795)

References: core/modulehandler.class.inc.php• L20-50 core/metamodel.class.php• L5777-5796

Event registration

An event setup class is a module extension point that registers event descriptions and listeners. At startup, the event service discovers every class implementing iEventServiceSetup, creates it, and calls its registration method. (sources/…/iEventServiceSetup.php• L10-25, sources/…/EventService.php• L40-55)

This lets a module add event behavior at the point where the model is fully started. The registered listeners then participate in later application actions through the common event service. (sources/…/TemporaryObjectsEvents.php• L24-55, sources/…/EventService.php• L81-100)

References: sources/…/iEventServiceSetup.php• L10-25 sources/…/EventService.php• L40-55 sources/…/TemporaryObjectsEvents.php• L24-55

Service access

The service locator is the shared access point for services that need one process-wide registration. A service is registered under a name and retrieved by that name; an unknown name raises a dependency error. (sources/…/ServiceLocator.php• L12-63, sources/…/DIException.php• L8-19)

This provides a small dependency injection boundary for code that needs replaceable shared services. For example, form services register a model reflection service, and form-related code retrieves that service without constructing its own copy. (sources/…/FormBlockService.php• L19-35)

References: sources/…/ServiceLocator.php• L12-63 sources/…/DIException.php• L8-19 sources/…/FormBlockService.php• L19-35

Cache coordination

Caches reduce repeated model and discovery work, but they must follow the selected environment and data model. iTop uses environment-aware cache identity, disables cache use when the environment changes, and resets stale code and model data when needed.

Model and query caches

Configuration controls whether query results and model metadata can use shared caches. Startup enables the permitted query cache and can restore model structures from the environment-specific cache; otherwise it rebuilds those structures and stores them for later requests. (core/metamodel.class.php• L5842-5853, core/metamodel.class.php• L5885-5951)

The cache identity includes the application root and environment. This keeps data from one environment from being used as another environment's model. (core/metamodel.class.php• L6010-6024)

References: core/metamodel.class.php• L5842-5853 core/metamodel.class.php• L5885-5951 core/metamodel.class.php• L6010-6024

Data-model-dependent cache

The data-model-dependent cache stores small PHP-readable values in named pools. It has no time-based expiry; recompiling iTop invalidates it by changing the model cache context. File writes use a lock so concurrent requests do not write the same entry at once. (sources/…/DataModelDependantCache.php• L9-18, sources/…/DataModelDependantCache.php• L37-61)

Consumers can read, test, delete, or clear entries by pool. This gives runtime discovery services a cache that follows the model rather than a general-purpose time cache. (sources/…/DataModelDependantCache.php• L80-169)

References: sources/…/DataModelDependantCache.php• L9-18 sources/…/DataModelDependantCache.php• L37-61 sources/…/DataModelDependantCache.php• L80-169

Cache reset

Cache reset removes dictionary, application, user-rights, PHP opcode, and data-model-dependent cache state for an environment. It is used when model or environment changes make old runtime state unsafe. (core/metamodel.class.php• L6858-6887)

Environment switching follows the same safety rule on a smaller path: it disables cache use for that startup and clears PHP code caches before loading the new environment. (sources/…/StartupService.php• L26-43)

References: core/metamodel.class.php• L6858-6887 sources/…/StartupService.php• L26-43

Interface discovery

Interface discovery finds concrete iTop classes that implement a requested interface. It joins Composer class maps with already loaded classes, filters out library and test paths, and returns classes that can be used by the caller.

Class discovery

The discovery service reads class maps from core and environment extensions. It uses reflection to exclude interfaces, abstract classes, traits, aliases, and classes that do not implement the requested interface. (sources/…/InterfaceDiscovery.php• L45-105, sources/…/InterfaceDiscovery.php• L108-204)

The result is broader than the older fixed list of plugin interfaces. It supports runtime contracts such as controllers, form block factories, and event setup classes when those classes are present in the active environment. (sources/…/InterfaceDiscovery.php• L60-64, sources/…/EventService.php• L46-53)

References: sources/…/InterfaceDiscovery.php• L45-105 sources/…/InterfaceDiscovery.php• L108-204 sources/…/EventService.php• L46-53

Discovery cache modes

Interface discovery has three cache modes: no cache, dynamic cache, and static cache. Production-like environments use a static result. Development environments use no cache by default, while the developer_mode.interface_cache.enabled setting enables a result that is rebuilt when class-map files change. (core/config.class.inc.php• L1805-1812, sources/…/InterfaceDiscovery.php• L27-30, sources/…/InterfaceDiscovery.php• L229-253, sources/…/InterfaceDiscovery.php• L314-325)

Cached class names are checked again before they are returned. This prevents a stale entry from exposing a class that is no longer loadable. (sources/…/InterfaceDiscovery.php• L255-276)

References: core/config.class.inc.php• L1805-1812 sources/…/InterfaceDiscovery.php• L27-30 sources/…/InterfaceDiscovery.php• L229-276 sources/…/InterfaceDiscovery.php• L314-325

Runtime composition flow

The runtime composition flow moves from environment choice to model readiness and then to extension use. The following diagram shows the main dependency order rather than every startup action.

flowchart TD
    A[Request] --> B[Select environment]
    B --> C[Load configuration]
    C --> D[Load core and environment autoloaders]
    D --> E[Discover and order modules]
    E --> F[Build or restore data model]
    F --> G[Register startup hooks and events]
    G --> H[Discover or instantiate extensions]
    H --> I[Serve application behavior]
    F --> J[Coordinate model-dependent caches]
    J --> H

The key boundary is model readiness. Services that inspect classes or metadata must run after the model and its active module set are available. Configuration values are resolved before this boundary so that module selection, cache policy, and early startup behavior use the active environment's settings. (application/startup.inc.php• L67-80, core/metamodel.class.php• L5754-5796, core/config.class.inc.php• L2121-2212)

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to environment selection must also preserve cache isolation and PHP code-cache clearing.
  • Changes to module declaration fields must remain readable by setup discovery and usable by dependency ordering.
  • Changes to module dependencies must be checked against both selected-module setup analysis and full model assembly.
  • Changes to extension interfaces must update the registration or discovery path that supplies their implementations.
  • Changes to startup order must preserve the model-before-event-discovery relationship.
  • Changes to class maps, generated environment autoloaders, or the interface cache setting must preserve interface discovery and its cache validity checks.
  • Changes to cache identity or reset behavior must cover model metadata, dictionaries, user rights, and PHP code state as one consistency boundary.
  • Changes to service names must update every producer and consumer because lookup uses exact string identifiers.
  • Changes to configuration setting types or placeholder syntax must preserve value conversion, array expansion, fallback behavior, and configuration-file write-back.
  • Changes to configuration loading or application secret creation must preserve the settings contract and the secret used by framework-protected state.
  • Changes to module settings or configuration generation must preserve explicit environment overrides and the fallback values declared by active modules.

Important failure modes

TriggerConsequenceGuard
A request selects a build environmentStartup refuses to load that environmentStartupService rejects environment names ending in -build.
A selected module has an unmet dependencySetup or model composition cannot produce a complete ordered module setDependency ordering reports the affected modules and missing dependencies.
A module declaration is malformed or unreadableThe module is not available for composition or setupModuleFileReader validates the declaration and reports a module-file error.
A module or model class map is staleInterface-based hooks may be missing or point to classes that cannot loadEnvironment changes disable cache use; discovery checks cached class names before return.
A required service name is not registeredThe consuming operation stops with a dependency errorRegister the service before use and keep the name contract unchanged.
Startup runs after a second environment was selected in the same processThe process keeps its first model and does not load the second oneModel startup is one-shot; use a separate process for a different environment.
The configuration file is missing, unreadable, or invalidStartup cannot obtain the settings needed to build the selected runtimeConfiguration loading checks file access, required arrays, PHP errors, and output noise.
A configuration placeholder has no matching environment or server value and no fallbackConfiguration loading stops before the selected runtime can startUse a present value or add the %env(NAME)?:fallback% or %server(NAME)?:fallback% form supported by ConfigPlaceholdersResolver.
A module setting is removed while its active module still expects itThe module receives an unexpected null or default valueKeep environment overrides aligned with the module's declared parameter contract.

Key files

FileWhy to read it
application/startup.inc.phpShows the request-level handoff from session and environment selection to model startup.
sources/…/StartupService.phpDefines environment selection and the cache safety rule for switching environments.
core/metamodel.class.phpShows the model startup boundary, cache use, startup hooks, and plugin access.
core/config.class.inc.phpExplains typed application settings, environment and server placeholder expansion, module settings, runtime secrets, configuration write-back, module configuration generation, and the development interface-cache setting.
setup/modulediscovery.class.inc.phpDefines module scanning, version choice, filtering, and dependency-ordered results.
setup/…/moduledependencysort.class.inc.phpShows how the module graph becomes a stable load order and how missing links fail.
sources/…/InterfaceDiscovery.phpDefines runtime interface discovery and its cache modes.
sources/…/DataModelDependantCache.phpDefines the cache boundary used by model-dependent discovery data.
core/pluginmanager.class.inc.phpShows how registered extension classes become on-demand plugin instances.
sources/…/ServiceLocator.phpShows the shared service registration and lookup boundary.
sources/…/EventService.phpShows how discovered event setup classes register runtime events and listeners.