> For the complete documentation index, see [llms.txt](https://quantumphp.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumphp.gitbook.io/docs/packages/module/overview.md).

# Overview

The Module package lets Quantum discover feature modules at boot time and scaffold new modules from built-in templates.

Use it when your application is split into `modules/<ModuleName>` directories and each module owns its own routes, config, and optional assets.

## What the package handles

The package has two responsibilities:

* `ModuleLoader` reads `shared/config/modules.php`, registers module dependencies, and exposes route closures for enabled modules.
* `ModuleManager` copies a module template into `modules/<ModuleName>`, optionally copies assets, and updates the shared module registry.

## Typical module layout

The loader expects these paths:

```
shared/config/modules.php
modules/<ModuleName>/routes/routes.php
modules/<ModuleName>/config/dependencies.php
```

Enabled modules need `routes/routes.php`. `config/dependencies.php` is optional.

## How module enabling works

`shared/config/modules.php` must return an array keyed by module name. Each item can include:

* `enabled` — whether the module's routes should be loaded
* `prefix` — stored in config for the rest of the framework to use

Example:

```php
return [
    'Blog' => [
        'prefix' => 'blog',
        'enabled' => true,
    ],
    'Admin' => [
        'prefix' => 'admin',
        'enabled' => false,
    ],
];
```

`enabled` controls both route loading and dependency loading.

## Important behavior to rely on

* Module dependencies are registered only for modules whose config has a truthy `enabled` value.
* Module routes are loaded only for modules whose config has a truthy `enabled` value.
* Each route file returns a `Closure`.
* Enabled modules without a route file raise a `ModuleException` during route loading.

## Built-in templates

`ModuleManager` scaffolds from `src/Module/Templates/<TemplateName>`.

Templates shipped in the package include:

* `DefaultApi`
* `DefaultWeb`
* `DemoApi`
* `DemoWeb`
* `Toolkit`

These templates vary in size. Some create controllers, config, and routes. Others also include models, services, views, translations, or static assets.

## When to use this package directly

Most applications will interact with modules through Quantum bootstrapping or CLI commands. Use the package classes directly when you are:

* building custom project scaffolding
* writing installation flows
* inspecting module route definitions programmatically
* generating modules from your own automation


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantumphp.gitbook.io/docs/packages/module/overview.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
