# Getting Started
A package in Krayin is a self-contained Laravel module that adds new functionality without touching the core. This is how every built-in Krayin feature ships (see Packages) and how you should add your own. The result is cleaner code, easier upgrades, and a clear path to share work between projects.
This guide walks you through creating a package called Example from scratch — the same Example you'll see referenced across the rest of the Package Development pages.
# ⚙️ Prerequisites
- A working Krayin application — see Installation.
- Composer — bundled when you install PHP via php.new.
There are two paths from here. Quickstart is recommended — one command does the whole scaffold for you. Manual setup is below if you want to see exactly what the generator does.
# 🪄 Quickstart — Package Generator
The official Krayin Package Generator (opens new window) creates every folder, file, and service-provider stub for you.
# 1. Install the generator
Run this in your Krayin application's root directory:
composer require krayin/krayin-package-generator
# 2. Generate the package
php artisan package:make Webkul/Example
This creates the full packages/Webkul/Example/ tree with all the standard sub-folders (src/Config, src/Database, src/Http, src/Models, src/Providers, src/Routes, etc.) and a working service provider.
Re-running the generator
If the package directory already exists and you want to overwrite it, pass --force:
php artisan package:make Webkul/Example --force
# 3. Register the namespace in composer.json
Add your package to the psr-4 block in the root composer.json:
"autoload": {
"psr-4": {
"Webkul\\Example\\": "packages/Webkul/Example/src"
}
}
# 4. Register the service provider
Add the provider to the providers array in config/app.php:
'providers' => ServiceProvider::defaultProviders()->merge([
// ...
Webkul\Example\Providers\ExampleServiceProvider::class,
])->toArray(),
# 5. Autoload and publish
composer dump-autoload
php artisan optimize
php artisan vendor:publish --provider=Webkul\Example\Providers\ExampleServiceProvider
When prompted, pick the entry for Webkul\Example\Providers\ExampleServiceProvider to publish the package's assets and configs.
Done — jump to Verify below.
# 🧱 Manual setup
Use this path when you want to learn the package layout by building it by hand, or when you can't add the generator dependency.
# 1. Create the package directory
Inside packages/Webkul/, create your package folder with a src/ sub-directory:
packages
└── Webkul
└── Example
└── src
# 2. Create the service provider
Inside src/, create a Providers/ folder and add ExampleServiceProvider.php:
packages
└── Webkul
└── Example
└── src
└── Providers
└── ExampleServiceProvider.php
Paste this into the file:
<?php
namespace Webkul\Example\Providers;
use Illuminate\Support\ServiceProvider;
class ExampleServiceProvider extends ServiceProvider
{
public function boot(): void
{
//
}
public function register(): void
{
//
}
}
# 3. Register the namespace in composer.json
Add the package to the psr-4 block in the root composer.json:
"autoload": {
"psr-4": {
"Webkul\\Example\\": "packages/Webkul/Example/src"
}
}
# 4. Register the service provider
Add the provider to the providers array in config/app.php:
'providers' => ServiceProvider::defaultProviders()->merge([
// ...
Webkul\Example\Providers\ExampleServiceProvider::class,
])->toArray(),
# 5. Autoload
composer dump-autoload
# 🧪 Verify
Confirm Laravel picked up your service provider:
php artisan about | grep "Webkul\\\\Example"
You should see Webkul\Example\Providers\ExampleServiceProvider in the list. If nothing prints, re-check the namespace in composer.json and re-run composer dump-autoload.
# 📝 Next steps
Your package is registered but empty. Build it out in this order — each page assumes the previous one is done:
- Routes — wire up admin URLs for your package.
- Migrations — define the database schema.
- Models — the Eloquent layer.
- Repository — the data-access layer Krayin standardises on.
- Controllers — handle requests, talk to repositories.
- Views and Layouts — render Blade templates.
- Validation — form requests for create / update.
- Admin Menu — surface your package in the sidebar.
- Access Control List — gate routes by user permission.
- Localization — translation files.
- Assets — JS / CSS bundling for your package.
- DataGrid — tabular list views with filters and sorting.
- Blade Components — reuse the admin UI primitives.