---
title: Scaffolding Modules & Controllers
description: Generate controllers, modules, and plugins with the CLI.
---

## Controllers

```bash
./nibiru -c products
```

Creates two files:

```
application/controller/productsController.php
application/view/templates/products.tpl
```

The controller stub:

```php
<?php
namespace Nibiru;
use Nibiru\Adapter\Controller;

class productsController extends Controller
{
    public function pageAction() {
        View::assign(['title' => 'Products']);
    }

    public function navigationAction() {
        JsonNavigation::getInstance()->loadJsonNavigationArray();
    }
}
```

The template stub:

```smarty
{include 'shared/header.tpl'}
<body>
{include file="navigation.tpl"}
<main class="container">
  <h1>{$title}</h1>
</main>
{include 'shared/footer.tpl'}
</body>
```

Controllers are PHP files only — no JS or CSS scaffold, so you stay in control of asset wiring.

## Modules

```bash
./nibiru -m billing
```

Creates:

```
application/module/billing/
├── billing.php
├── interfaces/billing.php
├── plugins/
├── settings/billing.ini
└── traits/
```

The main class implements `IModule` and exposes a constructor that loads the module's registry config. Add the `-g` flag to include Graylog observer wiring out of the box:

```bash
./nibiru -m billing -g
```

When `-g` is set the scaffold imports a `Graylog` observer, attaches it in the constructor, and emits `notify()` on key state changes — so any GELF-capable Graylog server picks up module events with no extra plumbing.

## Plugins

A plugin lives inside a module:

```bash
./nibiru -p invoices -m billing
```

Creates `application/module/billing/plugins/invoices.php`:

```php
<?php
namespace Nibiru\Module\Billing\Plugin;
use Nibiru\Module\Billing\Billing;

class Invoices extends Billing
{
    public function listOpen(): array
    {
        return \Nibiru\Pdo::fetchAll(
            'SELECT * FROM invoices WHERE status = :s ORDER BY due_date',
            [':s' => 'open']
        );
    }
}
```

Plugins inherit from the module so they share its registry, settings, and observer machinery.

## Bootstrap (`-s`)

`./nibiru -s` runs after install (or after pulling a fresh checkout) to:

- Create `application/view/templates_c/` and `application/view/cache/` if missing.
- Fix permissions (writable by the web server user) on those folders.
- Verify required PHP extensions are loaded.
- Verify the database driver in your INI is supported by this binary build.

It's safe to run repeatedly.

## Cache clear (`-cache-clear`)

Wipes both the Smarty compile cache and the rendered HTML cache:

```bash
./nibiru -cache-clear
```

Run after a deploy when:
- You changed `.tpl` files,
- You changed `[ENGINE] caching` settings,
- You modified Smarty plugins.

The cache regenerates on the next request.
