cahyadsn / ci4basic
CodeIgniter 4 Basic Boilerplate based on AdminLTE 3 with user management, roles, permissions, ...
Requires
- php: ^8.2
- codeigniter4/framework: ^4.7
- codeigniter4/translations: ^4.7
- hybridauth/hybridauth: ^3.13
- myth/auth: ^1.2
Requires (Dev)
- fakerphp/faker: ^1.24
- phpunit/phpunit: ^10.5 || ^11.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-14 05:01:00 UTC
README
ci4basic is an open-source, extensible back-office administration panel boilerplate for CodeIgniter 4. Built on top of AdminLTE 3, upgraded to modern Bootstrap 5 and Font Awesome 7, it provides out-of-the-box user management, role-based access control (RBAC) via Myth/Auth, a dynamic drag-and-drop menu manager, and customizable themes.
Features
- Modern UI / UX:
- Clean backend interface based on AdminLTE 3.
- Fully upgraded to Bootstrap 5.3.3 (clean flexbox layouts, modern modal and dropdown behaviors).
- High-resolution icon library powered by Font Awesome 7.3.1.
- Responsive tables with DataTables (Bootstrap 5 styling) including server-side search, sort, and pagination.
- Authentication & RBAC (Role-Based Access Control):
- Built on Myth/Auth (^1.2).
- Google SSO Integration: Seamless single sign-on powered by Hybridauth v3 with automatic account linking and optional auto-registration.
- User management: create, edit, activate/deactivate, and delete users.
- Role management: create custom roles and assign granular permissions via an interactive Bootstrap Dual Listbox.
- Permission management: dynamic permission assignment with instant modal editing.
- User self-service profile management (avatar update, password change, personal details).
- Dynamic Hierarchical Menu Manager:
- Drag-and-drop menu tree sorting using jQuery Nestable.
- Font Awesome icon selector integrated via FontAwesome Iconpicker.
- Role-based menu visibility (menus automatically appear only to permitted roles).
- Configurable & Extensible:
- Centralized configuration file (
Config/Boilerplate.php) for navbar styles, sidebar theme, app branding, and default landing routes. - Easy layout extension using CodeIgniter 4 view sections (
content,content-header,css,js).
- Centralized configuration file (
- Localization (i18n):
- Built-in multi-language support (English and Indonesian).
- Localized DataTables language packs.
Requirements
Ensure your environment satisfies the following requirements:
| Requirement | Minimum Version |
|---|---|
| PHP | ^8.2 (PHP 8.2, 8.3, or higher) |
| CodeIgniter | ^4.7 (tested with CI 4.7.4) |
| Database | MySQL (5.7+ / 8.0+), MariaDB (10.3+), SQLite3, or PostgreSQL |
| PHP Extensions | intl, mbstring, json, curl, and your database driver (pdo_mysql, mysqli, or sqlite3) |
| Composer | 2.0+ |
Installation
Step 1: Install via Composer
In your CodeIgniter 4 project root:
composer require cahyadsn/ci4basic
Step 2: Database & Environment Setup
Verify that your .env file contains your database connection details and proper app.baseURL:
app.baseURL = 'http://localhost:8080/' database.default.hostname = localhost database.default.database = my_ci4_db database.default.username = root database.default.password = database.default.DBDriver = MySQLi
Step 3: Run the Boilerplate Installer
Execute the following spark command in your terminal:
php spark boilerplate:install
This single command automatically:
- Publishes configuration files to
app/Config/Boilerplate.phpandapp/Config/GoogleSSO.php. - Publishes and runs all database migrations for authentication, users, roles, permissions, menus, and OAuth SSO identities (
auth_oauth_identities). - Seeds the database with default roles, permissions, menus, and initial user accounts.
Step 4: Register Filters
Open app/Config/Filters.php and register the aliases for authentication and authorization:
public array $aliases = [ 'csrf' => \CodeIgniter\Filters\CSRF::class, 'toolbar' => \CodeIgniter\Filters\DebugToolbar::class, 'honeypot' => \CodeIgniter\Filters\Honeypot::class, // Add these three filters: 'login' => \Myth\Auth\Filters\LoginFilter::class, 'role' => \cahyadsn\ci4basic\Filters\RoleFilter::class, 'permission' => \cahyadsn\ci4basic\Filters\PermissionFilter::class, ];
Default Accounts & Seed Data
Once installed, the following default accounts are seeded:
| Role | Username | Password | Description | |
|---|---|---|---|---|
| Admin | admin |
super-admin |
admin@admin.com |
Has full access to all back-office management features. |
| Member | user |
super-user |
user@user.com |
Standard user account without administration privileges. |
Warning
Production Security: Make sure to change the default passwords or delete default accounts immediately after initial deployment.
Pre-Configured Routes & Permissions
The package registers the following routes under the /admin prefix:
| Method | URI | Controller Action | Permission |
|---|---|---|---|
GET |
/admin |
Configurable in Boilerplate.php |
back-office |
GET/POST |
/admin/user/profile |
UserController::profile |
back-office |
RESOURCE |
/admin/user/manage |
UserController |
manage-user |
RESOURCE |
/admin/role |
RoleController |
role-permission |
RESOURCE |
/admin/permission |
PermissionController |
role-permission |
RESOURCE |
/admin/menu |
MenuController |
menu-permission |
PUT |
/admin/menu-update |
MenuController::new |
menu-permission |
GET |
/sso/google |
GoogleSSOController::redirect |
None (Public) |
GET |
/sso/google/callback |
GoogleSSOController::callback |
None (Public) |
Google Single Sign-On (SSO) Setup
ci4basic integrates Google Single Sign-On using Hybridauth v3.
1. Obtain OAuth 2.0 Credentials
- Go to the Google Cloud Console Credentials.
- Create an OAuth 2.0 Client ID (Web application).
- Set Authorized redirect URIs to:
(Replacehttp://localhost:8080/sso/google/callbackhttp://localhost:8080/with your production domain when deploying).
2. Configure Environment Variables
Add your Google credentials to your .env file:
# Google SSO Configuration google.clientId = 'YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com' google.clientSecret = 'YOUR_GOOGLE_CLIENT_SECRET' # Optional customizations: google.enabled = true google.autoRegister = true google.defaultRole = 'member'
Alternatively, you can customize settings directly in app/Config/GoogleSSO.php. When google.clientId is configured, the "Sign in using Google" button will automatically appear on the login page.
Configuration
After running boilerplate:install, you can customize settings in app/Config/Boilerplate.php and app/Config/GoogleSSO.php:
Boilerplate Configuration (app/Config/Boilerplate.php)
namespace Config; use CodeIgniter\Config\BaseConfig; class Boilerplate extends BaseConfig { // Application branding name public $appName = 'Boilerplate'; // Dashboard entry route configuration public $dashboard = [ 'namespace' => 'cahyadsn\ci4basic\Controllers', 'controller' => 'DashboardController::index', 'filter' => 'permission:back-office', ]; // DataTables localization ('Indonesian', 'English', etc.) public $i18n = 'Indonesian'; // Theme and layout appearance public $theme = [ 'body-sm' => false, 'navbar' => [ 'bg' => 'white', // white, primary, dark, etc. 'type' => 'light', // light, dark 'border' => true, 'user' => [ 'visible' => true, 'shadow' => 0, ], ], 'sidebar' => [ 'type' => 'dark', // light, dark 'shadow' => 4, // 0 - 4 'border' => false, 'compact' => true, 'links' => [ 'bg' => 'primary', 'shadow' => 1, ], 'brand' => [ 'bg' => 'white', 'logo' => 'vendor/cahyadsn/ci4basic/assets/icon.png', ], 'user' => [ 'visible' => true, 'shadow' => 2, ], ], 'footer' => [ 'fixed' => false, 'vendor' => 'cahyadsn', 'link' => 'https://github.com/cahyadsn/ci4basic', ], ]; }
Google SSO Configuration (app/Config/GoogleSSO.php)
namespace Config; use CodeIgniter\Config\BaseConfig; class GoogleSSO extends BaseConfig { // Enable or disable Google SSO public bool $enabled = true; // Google OAuth 2.0 Client ID (can also be set via .env: google.clientId) public string $clientId = ''; // Google OAuth 2.0 Client Secret (can also be set via .env: google.clientSecret) public string $clientSecret = ''; // Redirect callback URL (default: site_url('sso/google/callback')) public string $callbackUrl = ''; // OAuth 2.0 scopes public array $scope = ['email', 'profile']; // Default role assigned to newly auto-registered users public string $defaultRole = 'member'; // Automatically register user if email does not exist in database public bool $autoRegister = true; }
Creating Custom Admin Pages
To build new back-office modules that integrate seamlessly with the theme and permissions:
1. Create a Controller
namespace App\Controllers\Admin; use App\Controllers\BaseController; class ProductsController extends BaseController { public function index() { $data = [ 'title' => 'Products Management', ]; return view('admin/products/index', $data); } }
2. Create the View
Extend the boilerplate master layout (cahyadsn\ci4basic\Views\layout\index) and inject content into the view sections:
<?= $this->extend('cahyadsn\ci4basic\Views\layout\index') ?> <!-- Optional: Custom Page Header --> <?= $this->section('content-header') ?> <div class="row mb-2"> <div class="col-sm-6"> <h1 class="m-0"><?= esc($title) ?></h1> </div> <div class="col-sm-6"> <ol class="breadcrumb float-sm-end"> <li class="breadcrumb-item"><a href="<?= base_url('admin') ?>">Home</a></li> <li class="breadcrumb-item active">Products</li> </ol> </div> </div> <?= $this->endSection() ?> <!-- Main Content Area --> <?= $this->section('content') ?> <div class="card card-outline card-primary"> <div class="card-header"> <h3 class="card-title">Product List</h3> <div class="card-tools"> <a href="<?= base_url('admin/products/new') ?>" class="btn btn-primary btn-sm"> <i class="fas fa-plus me-1"></i> Add Product </a> </div> </div> <div class="card-body"> <p>Your products table or content goes here.</p> </div> </div> <?= $this->endSection() ?> <!-- Optional: Page-specific JavaScript --> <?= $this->section('js') ?> <script> console.log('Products page loaded.'); </script> <?= $this->endSection() ?>
3. Register the Route
In app/Config/Routes.php:
$routes->group('admin', ['filter' => 'permission:back-office'], function ($routes) { $routes->get('products', 'Admin\ProductsController::index'); });
4. Add to Dynamic Menu
- Log in to the admin panel with an administrative account.
- Navigate to Menu Management (
/admin/menu). - Add a new menu item:
- Title: Products
- Route:
admin/products - Icon: Choose any Font Awesome icon (e.g.
fas fa-boxes-stacked) - Roles: Select the roles allowed to see this menu item.
- Drag and position the item within your sidebar hierarchy, then click Save.
Running Tests
Automated tests are powered by PHPUnit 11:
# Run tests with composer composer test # Or run PHPUnit directly ./vendor/bin/phpunit
License
This package is open-source software licensed under the MIT License.