Skip to content

Create a Module

Koakademy extensions are Composer packages delivered in a tested application image. The marketplace lists releases and manages installed module availability. School licenses apply only to paid capabilities.

The working starter is in extensions/starter. It demonstrates school notes with tenant isolation, policies, validation, permissions, migrations, an Inertia page, a Filament plugin, a Livewire component, and class-based queue work.

From a development checkout:

Terminal window
composer install
php artisan modules:validate --all
composer test:extensions
php artisan wayfinder:generate --no-interaction
npm run build

The extension suite also includes tests under Modules/*/tests, so bundled modules’ own tests run alongside the Composer package lifecycle checks.

The starter is a development-only Composer path dependency installed at vendor/koakademy/school-notes-starter. Production --no-dev builds omit it. The integration suite deliberately enables vendor discovery instead of copying the example into Modules/.

To manage module switches, set MODULE_MARKETPLACE_ENABLED=true; the registry URL can remain blank for local work. To explore the screen, run migrations and php artisan modules:sync-permissions, enable SchoolNotes in Extensions & licenses, and assign its two permissions to the intended staff. Select an active school. The page is under /administrators/school-notes.

Copy extensions/starter into a separate repository. Use your own Composer vendor and repository owner. Rename the following consistently:

  • Composer package name, PHP namespace, module name, alias, and provider class.
  • Permission names, table names, route names, page identifiers, and navigation entries.
  • The Wayfinder controller import after generating routes in the host.
  • Author, version, core requirements, repository, and homepage metadata.

A package may be named school-tools/campus-notes while its module name is CampusNotes. Directory discovery must not depend on those names being identical. Each module name, alias, and Composer identity must be unique across local and vendor modules.

Develop the new repository with a host Composer path repository:

Terminal window
composer config repositories.campus-notes path ../campus-notes
composer require school-tools/campus-notes:0.1.0
php artisan modules:validate --all
php artisan migrate
php artisan modules:sync-permissions
php artisan wayfinder:generate --no-interaction
npm run build

For an unrenamed copy of the starter, override the host’s extension-starter path repository instead of installing a second module with the same identity. Composer path repositories can use symlinks while developing; release builds should use the tested tagged package. If the package is mirrored, reinstall it after changing its source.

module.json
composer.json
app/Providers/CampusNotesServiceProvider.php
app/Http/Controllers/
app/Http/Requests/
app/Models/
app/Policies/
app/Jobs/
app/Filament/*Plugin.php
config/navigation.php
database/migrations/
resources/assets/js/Pages/
tests/
.github/workflows/ci.yml

The manifest declares a semantic version, unique identity, requirements, compatibility, and providers. requires.modules maps module names to Composer version constraints. Optional permissions lists explicit permission names; optional capabilities describes enterprise capabilities. Do not add commercial requirements to a free community feature.

Composer declares PSR-4 mappings and Laravel provider discovery. For the starter contract, extend App\Modules\ExtensionServiceProvider and implement moduleName(). Put that provider under app/Providers; the base provider loads its package routes, views, and migrations. Add package-specific boot configuration in the protected bootExtension() hook. Registration is independent of enabled state, so cached routes remain predictable. ensure.module guards access on each request.

Keep the provider class in both manifest metadata and Composer discovery. Laravel deduplicates registrations of the same provider. Never perform feature work, send mail, or depend on an authenticated user while registering or booting the provider.

Module availability is only the first check. Validate the user’s permission through policies or Form Requests and require an authorized active school before querying records.

The starter uses TenantContext and BelongsToSchool, and explicitly sets the school on writes. Never accept an authoritative school_id from an untrusted form. Queue jobs carry the school identifier explicitly and apply an explicit school filter.

Declare custom permission names in module.json. Run modules:sync-permissions during a release. It creates permissions idempotently without assigning them to staff roles. Role grants are a separate administrator decision. The existing role seeder also discovers policies from installed package paths.

For paid functionality, also apply the enterprise capability checks. A valid license does not replace permission or tenant authorization.

The browser and SSR builds discover resources/assets/js/Pages/**/*.tsx in local and Composer-installed modules. Use the same Inertia page identifier in the controller and navigation configuration. Register menu entries in config/navigation.php under admin, with requiredPermission and inertiaPage.

The host sends each module’s actual frontend directory to navigation. It does not derive vendor paths from module names. Build-time discovery means new or changed frontend files require an asset build.

Use the host’s existing UI dependencies and @/ imports. A package-local package.json does not install frontend dependencies into the host. Additional dependencies require an explicit change to the host package manifest and lockfile. Generate Wayfinder routes before browser/SSR builds, and use its controller/route helpers for links and forms.

Filament plugins under app/Filament/*Plugin.php are resolved through the package’s PSR-4 map. Register resources using their actual package namespace. The starter demonstrates this without assuming a Modules\\Name namespace. Module panel providers under app/Providers/Filament are also discovered.

The host blocks disabled module controller routes and Livewire mount/update requests. Route ownership is retained in route-cache metadata. An explicit ensure.module:ModuleName middleware is available for routes implemented outside the module directory.

Class-based jobs, queued listeners, mailables, and notifications are checked before execution. When unavailable, asynchronous work is released for 60 seconds; normal attempt and deadline limits still apply. Synchronous queued work fails explicitly. Choose an appropriate retry window and monitor terminal failures.

Scheduled commands, direct service calls, and anonymous queued closures must explicitly check ModuleAccessService::isAvailable() before performing extension work. PHP packages are trusted application code; the marketplace does not sandbox them.

Disabling blocks guarded work even if an older worker still has routes registered. Enabling older modules that conditionally register providers can still require a restart or deployment. Preserve the restart notice until all application workers have been rolled and acknowledged.

The included tests use the host’s existing Pest dependencies and Tests\\TestCase as a workbench. They verify permissions, validation, cross-school access, school assignment on writes, and disabled routes. The host lifecycle suite adds discovery, migrations, Filament, navigation, Livewire, and queue checks.

Copy the starter’s workflow into the new repository. It checks out Koakademy, installs the contributed package as a path dependency, tests it, and builds browser/SSR assets. Pin a compatible host tag or commit before publishing. The workflow does not need a registry signing key or production secrets.

  1. Keep source in your public repository under a Composer vendor namespace you control, with a license, support information, tests, and upgrade/rollback notes. Match the Composer name and module.json composer_package; use the koakademy namespace only with its maintainer’s authorization.
  2. Run composer validate --strict, package tests, and host integration checks. Publish a public vX.Y.Z Git tag matching the module.json version.
  3. Submit the repository to Packagist, configure automatic GitHub updates, and verify that the package name, tag, and source commit are visible there.
  4. Open a PR to the marketplace registry adding your repository to modules.json. Include the release, Packagist link, passing CI, compatibility, migrations, permissions, and rollback details.
  5. Maintainers manually verify the Packagist release and review the generated catalog and legacy index before signing with the existing key. Publication to Packagist does not automatically list or approve a module in the Marketplace.
  6. An operator adopts the package in an application lockfile, builds a tested image, applies migrations, provisions permissions, and completes deployment/activation.

See Module Registry for registry and rollout commands. Catalog publication alone does not install a package on a school’s server.

Move one module at a time. Add its package and remove its Modules/ source copy in the same reviewed change. Preserve migration identifiers, database tables and data, route names, permission names, and the existing activation state.

modules:validate --all rejects duplicate names, aliases, or package identities. Test both an existing upgraded database and a fresh installation before releasing. Do not keep both copies installed while relying on discovery order to choose one.