---
title: "How Crest Works"
description: "The project file, the global Crest and the project Crest, the runtime, the launcher and the stubs."
version: "1.0"
---

> Documentation Index
> Fetch the complete documentation index at: https://crest.phalcon.io/llms.txt
> Use this file to discover all available pages before exploring further.

# How Crest Works

This section explains the parts of Crest that the rest of this page uses: [The project file](#the-project-file), [The global Crest and the project Crest](#the-global-crest-and-the-project-crest), [The runtime](#the-runtime), [The launcher](#the-launcher) and [Stubs](#stubs).

## The project file

Each project has a `crest.php` at its root. This is the project file. `crest new` writes it. For an existing project, `crest init` writes it (see [Adding Crest to an existing project](/1.0/existing-project)). The file holds the settings of the project, for example:

- the flavor
- the root namespace
- the front controller (the class that starts the application)
- the folders that Crest writes into
- the runtime (see [The runtime](#the-runtime))

The `bootstrap` key names the front controller (see [Commands that boot the project](/1.0/booting)). [Configuration](/1.0/configuration) shows each key.

Crest finds the project by its `crest.php`: the file that `--config` names, or the nearest `crest.php` in or above the working directory or `--directory` (see [Global options](/1.0/commands#global-options)). Without `crest.php`, Crest stops. This error is the same in both flavors:

```text
crest: no crest.php found; run 'crest init'
```

## The global Crest and the project Crest

The commands that work on the project, for example `make:controller`, `make:action` and `route:list`, need the autoloader and the Phalcon of the project. A project from `crest new` requires `phalcon/crest` as a dev dependency. Thus after `crest install` (see [The launcher](#the-launcher)) or `composer install`, it has its own Crest in `vendor/bin/crest`. A global Crest passes the project commands to this Crest, with the same arguments, and returns its exit status. This is the hand-off.

`make:controller` creates an MVC controller (see [Generating controllers](/1.0/controllers)). `make:action` creates an ADR action for a route (see [Generating actions](/1.0/actions)). `route:list` shows each route that the application answers (see [Command reference](/1.0/commands)). For example, a global Crest passes this command to `vendor/bin/crest`:

**MVC**

```bash
crest make:controller Hello
```

**ADR**

```bash
crest make:action GET /hello
```

The `about` command shows the environment and version report (see [Command reference](/1.0/commands)). In a project, run `crest` with the global Crest:

**MVC**

```bash
crest                                 # list the available commands
crest about                           # show the environment and version report
crest make:controller Company
```

**ADR**

```bash
crest                                 # list the available commands
crest about                           # show the environment and version report
crest make:action GET /company/all
```

Without a global Crest, run the Crest of the project: `vendor/bin/crest` in the project, or `./crest` on a host with docker and no PHP (see [The launcher](#the-launcher)). In this text, the container is the docker compose service `app`, a container that docker compose runs (see [The runtime](#the-runtime)). In the container, there is no global Crest, so run `vendor/bin/crest` there:

**MVC**

```bash
docker compose exec app vendor/bin/crest make:controller Hello
```

**ADR**

```bash
docker compose exec app vendor/bin/crest make:action GET /hello
```

`new`, `init`, `up`, `down`, `install` and `--version` (see [Global options](/1.0/commands#global-options)) always run in the `crest` that you type, with no hand-off. `down` stops the containers (see [The launcher](#the-launcher)). `new`, `up`, `down` and `install` run before the project has a `vendor/`. Thus run them with a Crest outside the `vendor/` of the project, for example the global Crest (see [Installation](/1.0/installation)) or the launcher `./crest` (see [The launcher](#the-launcher)).

`bin-dir` is a setting of composer (see [Configuration](/1.0/configuration)). If the project has no `<bin-dir>/crest` (by default `vendor/bin/crest`), Crest stops, as it does without `crest.php`. The messages are the same in both flavors:

```text
crest: /path/to/my-app has no vendor/bin/crest; run 'crest install' or 'composer install' first
crest: /path/to/my-app does not require phalcon/crest; run 'composer require --dev phalcon/crest'
```

The second message is for a project that does not require Crest. Add `:dev-master` to the `composer require` command of this message (see [Installation](/1.0/installation)).

## The runtime

The `runtime` key of `crest.php` says where the project commands run:

- With `['type' => 'host']`, a global Crest runs the project's `vendor/bin/crest` with the PHP of the host.
- With `['type' => 'docker', 'service' => 'app']` (what `crest new` writes), a global Crest runs `docker compose exec app vendor/bin/crest ...` in the project root. `app` is the service: a container that the compose file of the project names.

Use docker when Phalcon is only in the container. For example, a v5 project then works on a host without `ext-phalcon`. The containers must be up (`crest up`).

The docker runtime has two conditions. The compose file that `crest new` writes, `docker-compose.yml`, meets both:

- The service must mount the project folder (share it with the container), with `vendor/` in it: Crest looks for `vendor/bin/crest` on the host first.
- The `working_dir` of the service, the folder where its commands start, must be the project root: `vendor/bin/crest` runs there.

`crest install` runs composer in a docker compose service, with each runtime. With the docker runtime, composer runs in the service of the runtime. With the host runtime, composer runs in the `service` of the `runtime` key, else in `app`.

`crest serve` is the exception: it always runs on the host, because PHP's built-in server must listen there. With docker, `crest up` serves the project.

## The launcher

`./crest` is a launcher script that `crest new` writes into the project. It needs docker only: PHP on the host is not necessary.

`./crest up`, `./crest down` and `./crest install` run docker compose on the host: they start the containers, stop them, and install the dependencies. With a global Crest, `crest up` and `crest install` do the same. Crest runs `up`, `down` and `install` with docker compose in the folder of the `crest.php` that it finds (see [The project file](#the-project-file)).

All other commands of `./crest` run `vendor/bin/crest` in the service of the project (`app`, or the `--service` of `new`; see [Creating a project](/1.0/creating-a-project)):

**MVC**

```bash
./crest make:controller Hello
```

**ADR**

```bash
./crest make:action GET /hello
```

Before `./crest install`, they stop with `crest: run './crest install' first`. Without a terminal (CI, a pipe), the launcher adds `-T`, which tells `docker compose exec` not to ask for a terminal. On Windows, run `./crest` in WSL2.

The `.env` file of the project holds settings that docker compose reads, for example `APP_PORT` and the user and group IDs (`UID` and `GID`). The files that the container writes belong to the user of these IDs. With rootless docker (docker that runs without root), set `UID=0` and `GID=0` in `.env`: rootless docker maps root in the container to your user.

The Crest commands of the launcher get `CREST_HOST_ROOT`, the host folder of the project. Thus Crest shows host paths, not the paths in the container. The hand-off of a global Crest does the same.

The launcher runs `vendor/bin/crest`. If you change `vendor-dir` or `bin-dir` in `composer.json` (see [Configuration](/1.0/configuration)), change the `crest=` line at the top of `./crest`.

## Stubs

Crest generates files from stubs. A stub is a template in the Crest package, with placeholders such as `{{ flavor }}`: Crest fills in each placeholder with a value of the project. To change a stub, publish a copy with `crest stub:publish`, and edit the copy. Crest then uses your copy. `crest new` writes a project from the `project-*` stubs, for example the `project-config` stub for `crest.php`. [Custom stubs](/1.0/stubs) and [Project stubs](/1.0/stubs#project-stubs) tell where each copy goes. For the `project-config` stub, see also [Commands after `new`](/1.0/creating-a-project#commands-after-new).

Some generators also write a base: a class that Crest owns and writes again, for example `CrestControllerBase`, which your controllers extend. [Generated bases](/1.0/controllers#generated-bases) tells when Crest writes a base again.

Source: https://crest.phalcon.io/1.0/how-crest-works/index.mdx
