PHPackages                             red-freak/modular-monolith-laravel-env - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. red-freak/modular-monolith-laravel-env

ActiveLibrary

red-freak/modular-monolith-laravel-env
======================================

dotenv management for modular monoliths inspired by https://github.com/avosalmon/modular-monolith-laravel

0.2.1(3y ago)33MITPHP

Since Oct 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/red-freak/modular-monolith-laravel-env)[ Packagist](https://packagist.org/packages/red-freak/modular-monolith-laravel-env)[ RSS](/packages/red-freak-modular-monolith-laravel-env/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (6)Used By (0)

> **Warning**This Package is still work in progress!

> **Warning**The package is basically functional, but there is no logic to handle the files in a repo.

Modular Monolith Laravel Env
============================

[](#modular-monolith-laravel-env)

The task of this package is to manage module dotnev-files used by the Laravel integration of [phpdotenv](https://github.com/vlucas/phpdotenv). To store these files in source control without populating its contents to tjhe public the package is also based on Laravels [environment encrypting](https://laravel.com/docs/9.x/configuration#encrypting-environment-files) by a shared secret. This way the package can also be used for [forge](https://forge.laravel.com/) or [envoyer](https://envoyer.io/) deployments.

- This package is inspired by the [Laracon Online Winter '22 talk](https://youtu.be/0Rq-yHAwYjQ?t=4129) by [Ryuta Hamasaki](https://github.com/avosalmon): "Modularising the Monolith" ([slides](https://speakerdeck.com/avosalmon/modularising-the-monolith-laracon-online-winter-2022) | [gitHub](https://github.com/avosalmon/modular-monolith-laravel)) and though of as an extension for such approaches.
-

Systemrequirements
------------------

[](#systemrequirements)

- This package is only tested with `Laravel 9`. So it requires `"vlucas/phpdotenv": "^5.4.1"`.
- The package is written in `PHP 8.1`.

Installation
------------

[](#installation)

To install you have to replace the Kernel-classes of Laravel.

#### app/Http/Kernel.php

[](#apphttpkernelphp)

```
// replace
5: use Illuminate\Foundation\Http\Kernel as HttpKernel;
```

```
// with
5: use RedFreak\ModularEnv\Foundation\Http\Kernel as HttpKernel;
```

#### app/Console/Kernel.php

[](#appconsolekernelphp)

```
// replace
6: use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
```

```
// with
6: use RedFreak\ModularEnv\Foundation\Console\Kernel as ConsoleKernel;
```

Testing
-------

[](#testing)

run in develope

```
./vendor/bin/phpunit
```

How to use
----------

[](#how-to-use)

### getting started

[](#getting-started)

The package assumes that the including package is structured following the modular monolith talk with the additional dotenv-files by this logic:

```
.
├── app
├── .env
├── ...
├── src
│    ├── ModuleOne
│    │    ├── ...
│    │    └── .env
│    ├── ...
│    └── ModuleLast
│         ├── ...
│         └── .env
└── ...
```

If your structure is different you have to implement the `ModularEnvironmentApplication`-Contract into your application. By the method `ModularEnvironmentApplication::additionalEnvFiles()` the package will recognize different paths (\* and \*\* are allowed and used like in the .gitignore).

### using the variables

[](#using-the-variables)

Variables form the default `.env` are accessed like before with the `env()`-helper.

Variables from the modules are accessed the same way with the difference that they are prefixed with the module name in SNAKE\_CASE (caps) and `__`. E.g. the Variable `HELLO=WORLD` from the file `/src/FooBar/.env` can be accessed by `env('FOO_BAR__HELLO')`.

tasks
-----

[](#tasks)

### tasks for 0.3.0 - encrypting the files

[](#tasks-for-030---encrypting-the-files)

- support for `env:encrypt` and `env:decrypt` to handle the files
- implementing `modular_env:encrypt` and `modular_env:deecrypt` to support deployment processes

### 1.0.0-alpha

[](#100-alpha)

- maybe writing additional tests
- adding a test-pipeline for gitHub
- fixing and testing of 0.3.0 in real-life-environments

### 1.0.0 - MVP

[](#100---mvp)

- fixed release of 1.0.0-alpha

### 1.1.0 - LaravelRay

[](#110---laravelray)

- support for LaravelRay

recommendations
---------------

[](#recommendations)

#### use the following in your `.gitignore`

[](#use-the-following-in-your-gitignore)

```
.env
.env.*
!.env.example
!.env*.encrypted
!.env.pipelines
/src/**/.env
/src/**/.env.*
!/src/**/.env*.encrypted
!/src/**/.env.example
```

Why do I?
---------

[](#why-do-i)

### Why do I have to replace Kernel-Classes?

[](#why-do-i-have-to-replace-kernel-classes)

I see, replacing the Kernel is a big issue. But .env-files are bootstrapped before anything else, so we have to hook something before everything else. The Kernels are present and inheriting, so it's a good point to hook in.

### Need to create my own Application class?

[](#need-to-create-my-own-application-class)

You don't have to it's just a possibility to determine a custom path-structure on your dotenv-files. The default "setting" will be to guess files in `/src/**/`.

### Need to create my own Application class if I have a custom path-structure on my .env-files?

[](#need-to-create-my-own-application-class-if-i-have-a-custom-path-structure-on-my-env-files)

The problem for this package is, that we want to hook a behaviour which is deep in the functionality of Laravel. At the moment the dotenv-files are loaded there is just a "stub" of the `Application`, there is no way to use `config` or `env`. So this seemed the best option to not produce unnecessary disk-requests. This is especially important for applications handling hundreds of requests per second.

Licence
-------

[](#licence)

This package is free to use as stated by the [LICENCE.md](LICENSE.md) under the MIT License, but you can [buy me a coffee](https://www.buymeacoffee.com/redFreak) if you want :D.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

1310d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ba07c0dca0bf37238cb052349b522be81c50a0d3c495d341c31a6435ee889cb1?d=identicon)[red-freak](/maintainers/red-freak)

---

Top Contributors

[![red-freak](https://avatars.githubusercontent.com/u/66564761?v=4)](https://github.com/red-freak "red-freak (25 commits)")

---

Tags

modular-monolith

### Embed Badge

![Health badge](/badges/red-freak-modular-monolith-laravel-env/health.svg)

```
[![Health](https://phpackages.com/badges/red-freak-modular-monolith-laravel-env/health.svg)](https://phpackages.com/packages/red-freak-modular-monolith-laravel-env)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[bacula-web/bacula-web

The open source web based reporting and monitoring tool for Bacula

1537.5k](/packages/bacula-web-bacula-web)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[doppar/framework

The Doppar Framework

366.7k8](/packages/doppar-framework)[hardcastle/xrpl_php

PHP SDK / Client for the XRP Ledger

129.7k5](/packages/hardcastle-xrpl-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
