<p>Manually updating the <code>project.yaml</code> file is not recommended, in my opinion, especially if adding your own custom settings. It is not intended for manual editing and can be rebuilt from the database, if prompted to.</p>
<p>There's also a risk that your code will not have any effect if project config is in read-only mode.</p>
<p>Instead, I would create a config settings file in the <code>/config</code> directory and pull in the settings, similar to how the plugins service does (another reason I prefer plugins over modules):</p>
<pre class="lang-php prettyprint-override"><code>$settings = Craft::$app-&gt;getConfig()-&gt;getConfigFromFile($this-&gt;id);
</code></pre>
<p>This method is much easier to manage, changes are easier to track via version control, and it allows for environment-aware settings.</p>
<p>See: <a href="https://github.com/craftcms/cms/blob/d927d5662e9bfc61b9c3bc5d02dba8d24a7c36a5/src/services/Plugins.php#L965-L968" rel="nofollow noreferrer">https://github.com/craftcms/cms/blob/d927d5662e9bfc61b9c3bc5d02dba8d24a7c36a5/src/services/Plugins.php#L965-L968</a></p>

CC BY-SA 4.0
2021-11-12T19:07:56.190Z
Still improving my understanding here but it seems that if you save settings to project config using `Craft::$app->getProjectConfig()->set('modules.module-name.settingName', true)` that key/value pair does get added to the `projectconfig` table in the db and get rebuilt when I hit "Rebuild" in the project config utility.
Ben Parizek
CC BY-SA 4.0
2021-11-13T09:54:41.067Z
Yes, it looks like it does get added to the DB and therefore persists, since the `rebuild()` method starts off with the loaded project config and overrides certain things, but leaves your changes in place:
https://github.com/craftcms/cms/blob/98826245da3823762c10a64110ad5fab55890d74/src/services/ProjectConfig.php#L1227

I still believe that a config settings file is a much more appropriate place to store what appears to be a setting, and have updated my answer with some further reasons.
Ben Croker
CC BY-SA 4.0
2021-10-13T08:11:48.737Z
2021-11-13T09:54:37.877Z
2021-11-13T09:54:37.877Z
Ben Croker
<p>I can add a custom setting to the Project Config like so:</p>
<pre><code>Craft::$app-&gt;getProjectConfig()-&gt;set('modules.module-name.settingName', true);
</code></pre>
<p>In the <code>project.yaml</code> file that would get saved at the top level:</p>
<h4>config/project/project.yaml</h4>
<pre><code>dateModified: 1633752346
plugins:
    plugin-name:
        edition: pro
modules:
    module-name:
        settingName: true
</code></pre>
<p>Is this safe to do? Does Craft care if there are custom settings at the top level of the <code>project.yaml</code> file? Would Craft ever overwrite these during some other action?</p>
<p>Are there any naming or placement conventions I should follow if I have custom project config settings that don't fit into the 'plugins' category?</p>

<modules><projectconfig><project.yaml>
Where can a module safely store Project Config settings?
# Where can a module safely store Project Config settings?

(Asked by: username_0 on 2021-10-09)

I can add a custom setting to the Project Config like so:
Craft::$app->getProjectConfig()->set('modules.module-name.settingName', true);

In the project.yaml file that would get saved at the top level:
config/project/project.yaml
dateModified: 1633752346
plugins:
    plugin-name:
        edition: pro
modules:
    module-name:
        settingName: true

Is this safe to do? Does Craft care if there are custom settings at the top level of the project.yaml file? Would Craft ever overwrite these during some other action?
Are there any naming or placement conventions I should follow if I have custom project config settings that don't fit into the 'plugins' category?

**Tags:** modules, projectconfig, project.yaml

---

## 1 answers

### Answer by username_1 on 2021-10-13. Score: 1

Manually updating the project.yaml file is not recommended, in my opinion, especially if adding your own custom settings. It is not intended for manual editing and can be rebuilt from the database, if prompted to.
There's also a risk that your code will not have any effect if project config is in read-only mode.
Instead, I would create a config settings file in the /config directory and pull in the settings, similar to how the plugins service does (another reason I prefer plugins over modules):
$settings = Craft::$app->getConfig()->getConfigFromFile($this->id);

This method is much easier to manage, changes are easier to track via version control, and it allows for environment-aware settings.
See: https://github.com/craftcms/cms/blob/d927d5662e9bfc61b9c3bc5d02dba8d24a7c36a5/src/services/Plugins.php#L965-L968

> **Comments:**
> **username_0**: Still improving my understanding here but it seems that if you save settings to project config using `Craft::$app->getProjectConfig()->set('modules.module-name.settingName', true)` that key/value pair does get added to the `projectconfig` table in the db and get rebuilt when I hit "Rebuild" in the project config utility.  
> **username_1**: Yes, it looks like it does get added to the DB and therefore persists, since the `rebuild()` method starts off with the loaded project config and overrides certain things, but leaves your changes in place: https://github.com/craftcms/cms/blob/98826245da3823762c10a64110ad5fab55890d74/src/services/ProjectConfig.php#L1227  I still believe that a config settings file is a much more appropriate place to store what appears to be a setting, and have updated my answer with some further reasons.  

---

