PHPackages                             tobento/apps - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tobento/apps

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tobento/apps
============

Multiple apps support. Each app will run in its own application.

2.0(7mo ago)048↓33.3%6MITPHPPHP &gt;=8.4

Since Sep 8Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/tobento-ch/apps)[ Packagist](https://packagist.org/packages/tobento/apps)[ Docs](https://www.tobento.ch)[ RSS](/packages/tobento-apps/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (5)Dependencies (8)Versions (7)Used By (6)

Apps
====

[](#apps)

Multiple apps support. Each app will run in its own application.

Table of Contents
-----------------

[](#table-of-contents)

- [Getting Started](#getting-started)
    - [Requirements](#requirements)
- [Documentation](#documentation)
    - [App](#app)
    - [Creating A New App](#creating-a-new-app)
    - [Booting Apps](#booting-apps)
    - [Apps Config](#apps-config)
    - [Directory Structure](#directory-structure)
    - [Sharing Configurations](#sharing-configurations)
    - [Accessing Apps](#accessing-apps)
    - [Console](#console)
        - [Apps List Command](#apps-list-command)
        - [Apps Command](#apps-command)
        - [Apps Create Console Command](#apps-create-console-command)
    - [Testing](#testing)
- [Credits](#credits)

---

Getting Started
===============

[](#getting-started)

Add the latest version of the apps project running this command.

```
composer require tobento/apps

```

Requirements
------------

[](#requirements)

- PHP 8.4 or greater

Documentation
=============

[](#documentation)

App
---

[](#app)

Check out the [**App Skeleton**](https://github.com/tobento-ch/app-skeleton) if you are using the skeleton.

You may also check out the [**App**](https://github.com/tobento-ch/app) to learn more about the app in general.

### Creating A New App

[](#creating-a-new-app)

To create a new app, simply extend the `AppBoot::class` and define the constants as you need it.

```
use Tobento\Apps\AppBoot;

class Backend extends AppBoot
{
    /**
     * Specify your app boots:
     */
    protected const APP_BOOT = [
        //\Tobento\App\Console\Boot\Console::class,
        //\Tobento\App\User\Web\Boot\UserWeb::class,
    ];

    /**
     * Set a unique app id. Must be lowercase and
     * only contain [a-z0-9-] characters.
     * Furthermore, do not set ids with two dashes such as 'foo--bar'
     * as supapps id will be separated by two dashes.
     */
    protected const APP_ID = 'backend';

    /**
     * You may set a slug for the routing e.g. example.com/slug/
     * Or you may set the slug to an empty string e.g. example.com/
     */
    protected const SLUG = 'admin';

    /**
     * You may set a domains for the routing e.g. ['api.example.com']
     * In addition, you may set the slug to an empty string,
     * otherwise it gets appended e.g. api.example.com/slug
     */
    protected const DOMAINS = [];

    /**
     * You may set a migration to be installed on booting e.g Migration::class
     */
    protected const MIGRATION = '';
}
```

**Allow Sub Apps**

If your app supports sub apps, set the `supportsSubapps` property to `true`.

```
use Tobento\Apps\AppBoot;

class DomainFoo extends AppBoot
{
    /**
     * Specify your app boots:
     */
    protected const APP_BOOT = [
        Backend::class,
        Frontend::class,
    ];

    /**
     * Set a unique app id. Must be lowercase and
     * only contain [a-z0-9-] characters.
     * Furthermore, do not set ids with two dashes such as 'foo--bar'
     * as supapps id will be separated by two dashes.
     */
    protected const APP_ID = 'domain-foo';

    /**
     * You may set a slug for the routing e.g. example.com/slug/
     * Or you may set the slug to an empty string e.g. example.com/
     */
    protected const SLUG = '';

    /**
     * You may set a domains for the routing e.g. ['api.example.com']
     * In addition, you may set the slug to an empty string,
     * otherwise it gets appended e.g. api.example.com/slug
     */
    protected const DOMAINS = ['example.com'];

    /**
     * @var bool
     */
    protected bool $supportsSubapps = true;
}
```

Booting Apps
------------

[](#booting-apps)

After [creating your apps](#creating-a-new-app), you will need to boot your apps:

```
use Tobento\App\AppFactory;

// Create the app:
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots:
$app->boot(DomainFoo::class);
$app->boot(DomainBar::class);
$app->boot(Backend::class);

// Adding app specific boots:
$app->booting();
$app->get(Backend::class)->addBoot(BackendSpecificBoot::class);

// Run the app:
$app->run();
```

**Example Using Apps Within A Boot**

```
use Tobento\App\Boot;

class Blog extends Boot
{
    public const BOOT = [
        Backend::class,
        Frontend::class,
    ];

    public function boot(Backend $backend, Frontend $frontend): void
    {
        $backend->addBoot(BlogBackend::class);
        $frontend->addBoot(BlogFrontend::class);
    }
}
```

Next, boot your `Blog` boot:

```
use Tobento\App\AppFactory;

// Create the app:
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots:
$app->boot(Blog::class);

// Run the app:
$app->run();
```

Apps Config
-----------

[](#apps-config)

The configuration for the apps is located in the `app/config/apps.php` file at the default App Skeleton config location.

Directory Structure
-------------------

[](#directory-structure)

The directory structure will be like:

```
your-project/
  app/ #root app
    config/
    src/
    ...
  apps/
    backend/
      config/
      views/
      ...
  public/
    apps/
      backend/
        assets/
    assets/
    index.php
  vendor/

```

Sharing Configurations
----------------------

[](#sharing-configurations)

You may share configurations between apps using the `app:root` or `app:parent` directory to point to the same directory:

In each app `config/database.php`:

```
'defaults' => [
    'pdo' => 'mysql',
    'storage' => 'file',
    'shared:storage' => 'shared:file',
],

'databases' => [
    'shared:file' => [
        'factory' => \Tobento\Service\Database\Storage\StorageDatabaseFactory::class,
        'config' => [
            'storage' => \Tobento\Service\Storage\JsonFileStorage::class,
            'dir' => directory('app:parent').'storage/database/file/',
        ],
    ],
],
```

And within your app:

```
use Tobento\Service\Database\DatabasesInterface;

$storageDatabase = $app->get(DatabasesInterface::class)->default('shared:storage');

// or
$fileDatabase = $app->get(DatabasesInterface::class)->get('shared:file');
```

Accessing Apps
--------------

[](#accessing-apps)

You may access apps from within another app by using the `AppsInterface::class` to retrieve the desired app.

```
use Tobento\Apps\AppBoot;
use Tobento\Apps\AppsInterface;
use Tobento\Service\Routing\RouterInterface;

// Boot the app if it has not booted yet:
$app->booting();

// Get the apps:
$apps = $app->get(AppsInterface::class);

// Get any desired app:
var_dump($apps->get('frontend') instanceof AppBoot);
// bool(true)

$frontendApp = $apps->get('frontend')->app();
$frontendApp->booting();

// For instance, get all frontend app routes:
$routes = $frontendApp->get(RouterInterface::class)->getRoutes();
```

**Sub Apps**

When accessing a sup app, you will need to boot the parent app first, otherwise the sub app will not be found!

```
use Tobento\Apps\AppsInterface;
use Tobento\Service\Routing\RouterInterface;

// Boot the app if it has not booted yet:
$app->booting();

// Get the apps:
$apps = $app->get(AppsInterface::class);

// Boot parent app:
$apps->get('domain-foo')->app()->booting();

// Get sub app:
$frontendApp = $apps->get('domain-foo--frontend')->app();
$frontendApp->booting();

// For instance, get all frontend app routes:
$routes = $frontendApp->get(RouterInterface::class)->getRoutes();
```

> **CAUTION**When booting multiple apps, you will need to reboot the main app using the `bootingApp` method afterwards, otherwise helper functions will use last booted app container for instance.

```
use Tobento\Apps\AppsInterface;

// Boot the app if it has not booted yet:
$app->booting();

// Get the apps:
$apps = $app->get(AppsInterface::class);

foreach($apps->all() as $appBoot) {
    $application = $appBoot->app();
    $application->booting();
    // do something
}

$apps->bootingApp($app);
```

Console
-------

[](#console)

The following commands should be run only on the root app console.

### Apps List Command

[](#apps-list-command)

The `apps:list` command provides an overview of all the apps:

```
php ap apps:list

```

### Apps Command

[](#apps-command)

With the `apps` command you can run any command within each apps.

Runs `route:list` command on all apps:

```
php ap apps route:list

```

Runs `route:list` command on the frontend and backend app only:

```
php ap apps route:list --aid=frontend --aid=backend

```

### Apps Create Console Command

[](#apps-create-console-command)

You may create for each app a console using the `apps:create-console` command.

```
php ap apps:create-console

```

Once created, the console is available at each app directory:

```
your-project/
  apps/
    backend/
      config/
      views/
      ap #console

```

Testing
-------

[](#testing)

When using the [App Testing](https://github.com/tobento-ch/app-testing) bundle, you need to return the specific app you want to test on the `createApp` method:

```
use Tobento\App\Testing\TestCase;
use Tobento\App\AppInterface;
use Tobento\Apps\AppsInterface;

final class BackendAppTest extends TestCase
{
    public function createApp(): AppInterface
    {
        $app = require __DIR__.'/../app/app.php';
        $app->booting();

        // Return the app you want to test:
        return $app->get(AppsInterface::class)->get('backend')->app();
    }
}
```

**Using The Tmp App**

```
use Tobento\App\Testing\TestCase;
use Tobento\App\AppInterface;
use Tobento\Apps\AppsInterface;

final class BackendAppTest extends TestCase
{
    public function createApp(): AppInterface
    {
        $app = $this->createTmpApp(rootDir: __DIR__.'/..');

        // Boot your apps:
        $app->boot(Backend::class);
        $app->booting();

        // Get the app you want to test:
        $app = $app->get(AppsInterface::class)->get('backend')->app();

        // You may boot additional boots for testing:
        $app->boot(\Tobento\App\Seeding\Boot\Seeding::class);

        return $app;
    }
}
```

Example using a sub app:

```
use Tobento\App\Testing\TestCase;
use Tobento\App\AppInterface;
use Tobento\Apps\AppsInterface;

final class BackendAppTest extends TestCase
{
    public function createApp(): AppInterface
    {
        $app = $this->createTmpApp(rootDir: __DIR__.'/..');

        // Boot your apps:
        $app->boot(DomainFoo::class);
        $app->booting();

        // Get and boot parent app:
        $app = $app->get(AppsInterface::class)->get('domain-foo')->app();
        $app->booting();

        // Get sub app:
        $app = $app->get(AppsInterface::class)->get('domain-foo--backend')->app();

        // You may boot additional boots for testing:
        $app->boot(\Tobento\App\Seeding\Boot\Seeding::class);

        return $app;
    }
}
```

Credits
=======

[](#credits)

- [Tobias Strub](https://www.tobento.ch)
- [All Contributors](../../contributors)

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance63

Regular maintenance activity

Popularity8

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~65 days

Recently: every ~27 days

Total

7

Last Release

227d ago

Major Versions

1.x-dev → 2.02025-10-03

PHP version history (2 changes)1.0.0PHP &gt;=8.0

2.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/055d6a1b5c2384bb179c75ab0b55914231d898fdc4dffeb30770f81200e52206?d=identicon)[TOBENTOch](/maintainers/TOBENTOch)

---

Top Contributors

[![tobento-ch](https://avatars.githubusercontent.com/u/16684832?v=4)](https://github.com/tobento-ch "tobento-ch (16 commits)")

---

Tags

packageappmultitenancytobentoapps

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tobento-apps/health.svg)

```
[![Health](https://phpackages.com/badges/tobento-apps/health.svg)](https://phpackages.com/packages/tobento-apps)
```

PHPackages © 2026

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