# Package Development

A package is a self-contained Laravel module that adds functionality to Krayin without touching the core. Every built-in Krayin feature ships as a package (see Packages), and your own customisations should too — that's what keeps upgrades painless and code shareable across projects.

This section is the build-it-yourself guide — each page covers one slice of a package (routes, controllers, repositories, ...). Follow them in order and you'll have a working CRUD package by the time you reach the end.

# What's in this section

  • Getting Started — scaffold a package called Example, register its service provider, dump the autoloader.
  • Admin Menu — add a sidebar entry via config/admin-menu.php.
  • Assets — per-package Vite, Tailwind, PostCSS, HMR + production builds.
  • Blade Components — reusable admin UI primitives (<x-admin::layouts>, <x-admin::datagrid>, ...).
  • Access Control List — permission entries gated with bouncer()->can().
  • Models — the three-part Concord pattern: Contract, Model, Proxy.
  • Migrations — database schema for your package.
  • Controllers — admin / shop split, repository injection, view returns.
  • DataGrid — paginated, filterable, sortable list views.
  • Layouts — extending or overriding the admin layout.
  • Localization — multi-language strings via Resources/lang/<locale>/app.php.
  • Routes — admin route registration with admin middleware.
  • Repository — Prettus-based data-access layer.
  • Validation — Form Request classes for input validation.
  • Views — Blade templates under Resources/views/ with a namespace.
You want to... Go to
Create your first package Getting Started
Add a CRUD list view DataGrid
Add a sidebar entry Admin Menu
Lock a route behind a permission Access Control List
Ship CSS / JS with your package Assets
Override an existing core file Override a Layout

# Build-from-scratch order

Each page assumes the previous one is done. Follow this order for a complete walkthrough:

  1. Getting Started — scaffold the package and register its service provider.
  2. Routes — wire admin URLs.
  3. Migrations — define the database schema.
  4. Models — Eloquent model + contract + Concord proxy.
  5. Repository — data-access layer.
  6. Controllers — handle requests, talk to repositories.
  7. Views and Layouts — Blade templates wrapped in the admin shell.
  8. Validation — form-request rules.
  9. Admin Menu — surface the package in the sidebar.
  10. Access Control List — gate routes by permission.
  11. Localization — translation files.
  12. Assets — JS / CSS bundling with Vite.
  13. DataGrid — sortable / filterable / paginated list views.
  14. Blade Components — reusable admin UI primitives.

# Standard package layout

Every Krayin package follows the same folder structure, so once you know one you know them all. Reference tree for a package called Example:

packages
└── Webkul
    └── Example
        └── src
            ├── Config
            │   ├── acl.php
            │   ├── admin-menu.php
            │   └── system.php
            ├── Console
            │   └── Commands
            ├── Contracts
            │   └── Example.php
            ├── Database
            │   ├── Migrations
            │   │   └── 2023_04_21_173057_create_examples_table.php
            │   └── Seeders
            ├── DataGrids
            │   └── Admin
            │       └── ExampleDataGrid.php
            ├── Events
            ├── Http
            │   ├── Controllers
            │   │   └── Admin
            │   │       └── ExampleController.php
            │   ├── Middleware
            │   └── Requests
            │       └── ExampleRequest.php
            ├── Listeners
            ├── Mail
            ├── Models
            │   ├── Example.php
            │   └── ExampleProxy.php
            ├── Providers
            │   ├── ExampleServiceProvider.php
            │   ├── ModuleServiceProvider.php
            │   └── EventServiceProvider.php
            ├── Repositories
            │   └── ExampleRepository.php
            ├── Routes
            │   └── admin-routes.php
            └── Resources
                ├── assets
                │   ├── css/app.css
                │   ├── js/app.js
                │   └── images
                ├── lang
                │   └── en
                │       └── app.php
                └── views
                    ├── admin
                    │   └── examples
                    │       ├── index.blade.php
                    │       ├── create.blade.php
                    │       └── edit.blade.php
                    └── components