> 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/app/usage.md).

# Usage

Use the App package in entry points, not inside normal feature code.

## Web entry point

A typical front controller only needs to create the app and start it:

```php
use Quantum\App\Enums\AppType;
use Quantum\App\Factories\AppFactory;

require_once __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create(AppType::WEB, dirname(__DIR__));
$app->start();
```

What happens next:

* helpers, environment, and config are loaded
* request and response services are prepared
* modules register routes
* the current request is matched and dispatched

## Console entry point

For CLI bootstraps, use the console adapter:

```php
use Quantum\App\Enums\AppType;
use Quantum\App\Factories\AppFactory;

require_once __DIR__ . '/vendor/autoload.php';

$app = AppFactory::create(AppType::CONSOLE, __DIR__);
exit($app->start() ?? 0);
```

Quantum will discover:

* framework console commands
* application commands from `shared/Commands`

## Getting runtime paths

Once the app context exists, path helpers are available anywhere helpers have been loaded:

```php
$cacheDir = public_dir() . '/cache';
$moduleRoot = modules_dir();
```

## Resetting the runtime in tests

Because the factory caches one app per type, tests that need a new base directory or a fresh boot state should destroy the cached app first.

```php
use Quantum\App\Enums\AppType;
use Quantum\App\Factories\AppFactory;

AppFactory::destroy(AppType::WEB);
$app = AppFactory::create(AppType::WEB, $fixtureProjectRoot);
```

## Common pitfalls

### Reusing the same adapter type across projects

If the same PHP process boots two different projects with the same adapter type, the second call reuses the first cached instance unless you destroy it.

### Calling path helpers too early

Helpers like `base_dir()` and `public_dir()` require `AppContext` to be set. Calling them before `AppFactory::create()` finishes will fail.

### Constructor-heavy console commands

The console adapter instantiates discovered command classes directly. If a command requires constructor arguments, it will not fit the built-in registration flow.


---

# 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/app/usage.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.
