Commands

osdd:start

Convert a fresh Laravel project to layers.

osdd:start replaces the app/, database/ and config/ folders of a fresh Laravel project with two layers.

php artisan osdd:start

It asks for confirmation before it changes anything (default: no):

osdd:start deletes app/, config/ and database/ (database/database.sqlite is kept). Continue?
Run it once, on a fresh project. It refuses to run when functional/users or technical/osdd already exists, so it cannot run twice.

Options

OptionDescription
--forceDelete app/, config/ and database/ without asking. Required without a terminal.
--composer-updateRun composer update functional/users technical/osdd without asking.
--no-composer-updateSkip composer update without asking.

Without a terminal (CI, a script, a coding agent) or with -n, the command fails and changes nothing unless you pass --force, and it skips composer update unless you pass --composer-update:

php artisan osdd:start --force --composer-update

What it does

Creates the users layer

functional/users holds:

  • src/Models/User.php, the User model
  • database/factories/UserFactory.php
  • database/seeders/UsersSeeder.php
  • database/migrations/0001_01_01_000000_create_users_table.php, the skeleton migration: users, password_reset_tokens and sessions
  • src/Providers/UsersServiceProvider.php

The provider loads the layer's migrations and seeder, and points Laravel's default auth provider to the layer's model:

functional/users/src/Providers/UsersServiceProvider.php
public function register(): void
{
    config(['auth.providers.users.model' => User::class]);
}

auth()->user() and the guards return a Functional\Users\Models\User.

Creates the osdd layer

technical/osdd holds:

  • config/osdd.php, the OSDD configuration
  • database/migrations/0001_01_01_000001_create_cache_table.php (cache, cache_locks)
  • database/migrations/0001_01_01_000002_create_jobs_table.php (jobs, job_batches, failed_jobs)
  • src/Providers/OsddServiceProvider.php

Technical\Osdd\Providers\OsddServiceProvider overrides the package defaults with config/osdd.php, loads the two migrations, and binds LayersSeeder as the default seeder. The database session, cache and queue drivers of a fresh project keep working after php artisan migrate, and db:seed, migrate --seed and RefreshDatabase with $seed = true run the layer seeders.

Registers both layers

The root composer.json gets a path repository for ./functional/* and ./technical/*, and requires functional/users and technical/osdd. Each layer's composer.json lists its provider under extra.laravel.providers.

Cleans bootstrap/providers.php

The command removes the App\Providers\... entries from bootstrap/providers.php: their classes are deleted with app/, and Laravel discovers the layer providers through Composer. The providers of installed packages listed there stay.

Deletes the legacy folders

  • app/
  • config/
  • everything in database/ except database/database.sqlite and database/.gitignore, so the default SQLite connection keeps working

It also removes the Database\Factories\ and Database\Seeders\ entries from the autoload and autoload-dev sections of the root composer.json.

The App\ autoload entry stays: Laravel reads it to find the application namespace. Keep it, even though no code lives in app/ anymore.

Runs composer update

In a terminal, the command asks whether to run composer update functional/users technical/osdd (default: yes). Otherwise it prints the command: run it before the next artisan command. When the update runs and fails, osdd:start exits with 1; the layers stay in place.

composer update runs the file named by the COMPOSER_BINARY environment variable when it exists, else composer.phar in the project root, both with the PHP binary that runs artisan; otherwise composer from the PATH.

Result

functional/
  users/
    composer.json
    src/
      Models/User.php
      Providers/UsersServiceProvider.php
    database/
      factories/UserFactory.php
      migrations/0001_01_01_000000_create_users_table.php
      seeders/UsersSeeder.php
technical/
  osdd/
    composer.json
    config/osdd.php
    database/
      migrations/0001_01_01_000001_create_cache_table.php
      migrations/0001_01_01_000002_create_jobs_table.php
    src/
      Providers/OsddServiceProvider.php
database/
  database.sqlite
bootstrap/
  providers.php
composer.json

Then create the tables:

php artisan migrate
After osdd:start, the cache, jobs, batches, failed jobs and sessions tables already exist in a layer. Add the notifications table with php artisan osdd:notifications-table --layer=technical/osdd if you need it.