---
title: "Adding Crest to an Existing Project"
description: "Add Crest to a project that exists: crest init writes the project file, crest.php."
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.

# Adding Crest to an Existing Project

For an existing project, `crest init` writes `crest.php` (see [The project file](/1.0/how-crest-works#the-project-file)). If the project does not require Crest yet, add it as a dev dependency first. The `composer require` command needs the version `dev-master` (see [Installation](/1.0/installation)). The commands are the same in both flavors:

```bash
composer require --dev phalcon/crest:dev-master
crest init
```

`init` writes `crest.php` in the nearest folder with a `composer.json`. The psr-4 map is the `autoload.psr-4` part of `composer.json`: it gives a folder to each namespace prefix, for example `"App\\": "src/"`. The generators (the `make:*` commands) get their namespaces from this map. Thus `init` needs a psr-4 entry in `composer.json`. Without one, `init` stops and tells you to add one, for example `"App\\": "app/"`, and to run `composer dump-autoload`.

`init` asks these questions, in this order. For each question, it proposes a value that it finds in the project:

1. The namespace. The proposal is the namespace of the first psr-4 entry whose folder exists. The answer must be in the psr-4 map (`App\Api` under `"App\\": "src/"` is). The other proposals follow the answer: its folder is the psr-4 folder of the longest prefix, for example `src/Api`.
2. The flavor: `mvc` or `adr`. For each flavor, `init` counts the default folders of that flavor (item 4) that the project has. It proposes the flavor with the most. A tie gives `mvc`. A project with `src/Controllers`, `src/Providers` and `themes/vokuro` gets `mvc`. `--flavor` answers the question.
3. The front controller: `<namespace>\AppFront` when `AppFront.php` is in the folder of the namespace. Answer `none` for no front controller.
4. A folder for each path of the flavor (the `paths` key of `crest.php`; see [Configuration](/1.0/configuration)). The MVC paths are `command`, `controller`, `form`, `model`, `module`, `provider` and `views`. The ADR paths are `action`, `command`, `middleware`, `provider`, `repository` and `responder`. The question says if the folder exists. A class folder is in the folder of the namespace. An answer must be a relative folder in a psr-4 folder. Its folder names must give a usable namespace: `src/my-actions` gives `App\my-actions`, which PHP cannot use. `init` removes a leading `./`.

   `views` holds no classes. It is a relative folder in the project, with no psr-4 check. Each part of the answer must be a folder name. Thus `init` refuses an absolute folder, an empty part (`//`), `.` and `..`. The proposal is `themes/default`. When that folder does not exist and `themes/` has one folder only, `init` proposes that folder (`themes/vokuro` in [vokuro][vokuro]). The answer `none` is a project with no views: `init` writes `'views' => false` (see [The MVC project](/1.0/creating-a-project#the-mvc-project)).
5. The runtime (see [The runtime](/1.0/how-crest-works#the-runtime)). The proposal is docker when the project has `compose.yaml`, `compose.yml`, `docker-compose.yaml` or `docker-compose.yml`. For docker, `init` also asks for the service. The proposal is `app`, or the first service.
6. The database: `none`, `mariadb`, `mysql`, `pgsql` or `sqlite`. The proposal is `none`. `--database` answers the question. For another answer, `init` adds the database after it writes `crest.php`, as `make:database` does (see [Adding a database](/1.0/database)). When the `provider` folder already has `DbProvider.php`, `init` stops before it writes a file, unless `--force`. `init` does not start the front controller to look for a `db` service: it runs before the project has its autoloader.

Press Enter to accept a proposal. `--no-interaction` accepts all the proposals (see [Global options](/1.0/commands#global-options)). `--force` overwrites an existing `crest.php`. If the project does not require Crest, `init` prints the `composer require` line. Add `:dev-master` to that line (see [Installation](/1.0/installation)).

For an MVC project, `init` also writes the `models` key of `crest.php` (see [Configuration](/1.0/configuration)). It writes `'camelCase' => false`, so the models of the project keep their property names. It also writes `'getSet' => false`, so the properties of the models stay public. See [Names](/1.0/models#names) and [Getters and setters](/1.0/models#getters-and-setters).

`init` asks no question for the view engine. When the views folder, or a folder in it, has a `.volt` file, `init` writes `'templateEngine' => 'volt'` (see [Volt](/1.0/creating-a-project#volt)). Else it writes no key, which is `phtml`.

[vokuro]: https://github.com/phalcon/vokuro

Source: https://crest.phalcon.io/1.0/existing-project/index.mdx
