# 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
adminmiddleware. - Repository — Prettus-based data-access layer.
- Validation — Form Request classes for input validation.
- Views — Blade templates under
Resources/views/with a namespace.
# Quick links
| 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:
- Getting Started — scaffold the package and register its service provider.
- Routes — wire admin URLs.
- Migrations — define the database schema.
- Models — Eloquent model + contract + Concord proxy.
- Repository — data-access layer.
- Controllers — handle requests, talk to repositories.
- Views and Layouts — Blade templates wrapped in the admin shell.
- Validation — form-request rules.
- Admin Menu — surface the package in the sidebar.
- Access Control List — gate routes by permission.
- Localization — translation files.
- Assets — JS / CSS bundling with Vite.
- DataGrid — sortable / filterable / paginated list views.
- 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