CI4MS Architecture

System Blueprint

Understand the moving parts behind CI4MS—filters, routes, modules, caches, and tooling. Use this guide alongside the developer handbook when designing new features or debugging runtime behaviour.

Application Bootstrap & Request Lifecycle

Every request passes through app/Filters/Ci4ms.php:

app/Config/Filters.php performs dynamic filter discovery:

app/Config/Routes.php preloads settings, loads template routes, then includes each module's routes before defining front-end routes. A default template is shipped as app/Config/DefaultRoutes.php — copy it to Routes.php during setup.

CommonModel Abstraction

bertugfahriozer/ci4commonmodel powers the generic CRUD layer. Modules lean on helpers such as lists, selectOne, create, createMany, edit, remove, and isHave.

The backend BaseController instantiates CommonModel once, exposing it via $this->commonModel to child controllers.

Authentication & Authorization

Authentication is powered by CodeIgniter Shield (codeigniter4/shield):

Module Pattern

Each module (under modules/<Name>/) includes:

Use php spark make:module Foo (provided by ci4-cms-erp/ext_module_generator) to scaffold a new module skeleton.

Installation Flow

Web Installer (Modules\Install)

  • Copies env to .env, updates base settings, triggers migrations, and seeds defaults via InstallService.
  • Regenerates app/Config/Routes.php from the DefaultRoutes.php template.

CLI (php spark ci4ms:setup)

The Ci4msSetup command provides a fully automated installation path:

  • Accepts admin account details as command-line arguments.
  • Runs all database migrations across every module (--all).
  • Calls InstallService::createDefaultData() to seed modules, permissions, admin user, sample pages/blog entries, and settings.
  • Designed for use in CI/CD pipelines (Docker, GitHub Actions) where a browser-based installer is not practical.

Docker & CI/CD

CI4MS ships with a complete Docker environment:

Key Paths.php note: CI4 4.4+ requires a $supportDirectory property in app/Config/Paths.php pointing to the framework's ThirdParty directory. This is pre-configured in the repository:

public string $supportDirectory = __DIR__ . '/../../vendor/codeigniter4/framework/system/ThirdParty';

Caching & Configuration

Cache key Contents TTL
settings Decoded JSON settings values 24h
menus Sidebar menu tree 24h
{userId}_permissions Per-user permission flags Until invalidated

Clear all caches with php spark cache:clear or selectively via cache()->delete($key).

Theme System

Content & SEO

Media, File Management & Logs

Backup & Restore

CLI & Automation

Command Purpose
php spark ci4ms:setup Full automated installation (migrations + seeding)
php spark make:module <n> Scaffold a new module skeleton
php spark make:abview <n> Generate a backend view from the AdminLTE template
php spark create:route Rebuild app/Config/Routes.php from the template
php spark migrate --all Run all pending migrations
php spark cache:clear Clear all application caches

Modules\Methods::moduleScan() inspects the router to align routes with permission records.

Development Tips

Common Data Tables

users, auth_groups, auth_identities, auth_groups_users, auth_permissions_pages, auth_users_permissions, modules, pages, blog, blog_categories_pivot, tags, tags_pivot, menu, settings, login_rules, etc.

Consult module migrations for schema details.

Design with Insight

Use this architecture map to reason about dependencies and extension points. Pair it with the developer handbook and user guide for the full CI4MS story.