Appearance
Build Your First Module
Build a complete Labmin LIMS module step by step — starting with a minimal 3-file Fusion page, then adding a MySQL schema, migration, DTOs, repository, service, POST form mutation, permissions, feature flags, and a submodule.
Worked reference in the repository
admin/Modules/Notes implements every step in this guide. Keep it open whenever you want a full working reference.
Part 1 — Minimal working module
Every module lives in its own folder under admin/Modules/<ModuleName>/. Only create folders as you need them. Start with three files:
text
admin/Modules/Orders/
Controllers/
OrdersController.php
UI/
Views/
OrderList/
OrderList.component.ts
index.php1. Entry point (index.php)
Create admin/Modules/Orders/index.php:
php
<?php
use LIMS\Modules\Orders\Controllers\OrdersController;
use LIMS\Platform\LimsRouter;
$router = new LimsRouter(
__DIR__,
default: OrdersController::class,
);
$router->render();LimsRouter automatically wires DatabaseManager & CurrentUser DI, one DB transaction per request, $_GET/$_POST HTML-entity decoding, blank-to-null POST conversion, and the Master admin pages (?feature=migrations, ?feature=access, ?feature=flags).
2. Controller
Create admin/Modules/Orders/Controllers/OrdersController.php:
php
<?php
declare(strict_types=1);
namespace LIMS\Modules\Orders\Controllers;
use Labmin\Fusion\Fusion;
use Labmin\Fusion\FusionResponse;
use Labmin\Router\Attributes\Controller;
use Labmin\Router\Attributes\Get;
use LIMS\Platform\CurrentUser;
#[Controller('orders')]
final class OrdersController
{
public function __construct(private readonly CurrentUser $user) {}
#[Get(default: true)]
public function index(): FusionResponse
{
return Fusion::render('OrderList/OrderList.component.ts', [
'userName' => $this->user->name,
'orders' => [
['id' => 1, 'title' => 'Sample batch #104', 'status' => 'open'],
],
]);
}
}Fusion::render('OrderList/OrderList.component.ts', $props) resolves the relative path automatically against this module's UI/Views/ folder.
3. Angular Fusion page
Create admin/Modules/Orders/UI/Views/OrderList/OrderList.component.ts:
ts
import { Component, input } from "@angular/core";
import { TableModule } from "@labmin/fusion-angular-ui";
type Order = { id: number; title: string; status: string };
@Component({
selector: "orders-list",
imports: [TableModule],
template: `
<div class="mt-6 flex flex-col gap-3">
<h1 class="text-xl font-medium">Orders for {{ userName() }}</h1>
<fusion-table [value]="orders()" stripedRows size="small">
<ng-template #header>
<tr>
<th>Title</th>
<th>Status</th>
</tr>
</ng-template>
<ng-template #body let-row>
<tr>
<td>{{ row.title }}</td>
<td><span class="badge badge-sm badge-info">{{ row.status }}</span></td>
</tr>
</ng-template>
</fusion-table>
</div>
`,
})
export class OrderList {
readonly userName = input.required<string>();
readonly orders = input<Order[]>([]);
}4. View it in the browser
Start the Vite dev server and open /admin/Modules/Orders/View:
bash
npm run devbash
pnpm devbash
bun run devadmin/app.ts discovers /admin/Modules/**/UI/Views/**/*.component.ts automatically and binds $props to your component's signal inputs.
Part 2 — Persistence, validation & mutations
Now replace the hard-coded array with a real MySQL table, DTOs, repository, service, and POST create action.
5. Database schema, migration & menu entry
Add Database/Schemas/Orders.php:
php
<?php
declare(strict_types=1);
namespace LIMS\Modules\Orders\Database\Schemas;
use DateTimeImmutable;
use Labmin\MaterializeSQL\Attributes\Column;
use Labmin\MaterializeSQL\Attributes\ColumnDefault;
use Labmin\MaterializeSQL\Attributes\ColumnType;
use Labmin\MaterializeSQL\Attributes\PrimaryKey;
use Labmin\MaterializeSQL\Attributes\Table;
#[Table('orders')]
#[PrimaryKey(columns: ['id'])]
final class Orders
{
#[Column(ColumnType::INT, autoIncrement: true)]
public ?int $id = null;
#[Column(ColumnType::VARCHAR, length: 120)]
public string $title;
#[Column(ColumnType::VARCHAR, length: 32, default: 'open')]
public string $status = 'open';
#[Column(ColumnType::TIMESTAMP, column: 'created_at', default: ColumnDefault::CURRENT_TIMESTAMP)]
public ?DateTimeImmutable $createdAt = null;
}- Open
/admin/Modules/Orders/View?feature=migrationsas a Master user (STATE=LOCAL) to generate and run the migration. - To add a sidebar menu entry, generate a custom migration in
Database/Migrations/that inserts your module's row intofeaturesidempotently (INSERT ... WHERE NOT EXISTS) withdb = 'orders'andaction = 'Modules/Orders/View'(seeNotes/Database/Migrations/0002_menu_entry.sql). - Add lookup seeds in
Database/Seeds/<Table>Seed.phpif your module has default rows.
6. Read & Form DTOs
Create Core/DTOs/OrderFormDTO.php and Core/DTOs/OrderDTO.php:
php
<?php
declare(strict_types=1);
namespace LIMS\Modules\Orders\Core\DTOs;
use Labmin\Materialize\ObjectMapping\Attributes\DataObject;
use Labmin\Materialize\ObjectMapping\Validation\Constraints\Length;
use Labmin\Materialize\ObjectMapping\Validation\Constraints\NotBlank;
#[DataObject]
final class OrderFormDTO
{
#[NotBlank]
#[Length(max: 120)]
public string $title;
}php
<?php
declare(strict_types=1);
namespace LIMS\Modules\Orders\Core\DTOs;
use DateTimeImmutable;
use JsonSerializable;
use Labmin\Materialize\ObjectMapping\Attributes\DataObject;
#[DataObject]
final class OrderDTO implements JsonSerializable
{
public int $id;
public string $title;
public string $status;
public ?DateTimeImmutable $createdAt = null;
public function jsonSerialize(): array
{
return [
...get_object_vars($this),
'createdAt' => $this->createdAt?->format('Y-m-d H:i'),
];
}
}7. Repository
Extend LIMS\Platform\Repository in Core/Repositories/OrderRepository.php:
php
<?php
declare(strict_types=1);
namespace LIMS\Modules\Orders\Core\Repositories;
use LIMS\Modules\Orders\Core\DTOs\OrderDTO;
use LIMS\Modules\Orders\Database\Schemas\Orders;
use LIMS\Platform\Repository;
final class OrderRepository extends Repository
{
/** @return list<OrderDTO> */
public function all(): array
{
return $this->many(
OrderDTO::class,
'SELECT id, title, status, created_at AS createdAt FROM orders ORDER BY id DESC',
);
}
public function find(int $id): ?OrderDTO
{
return $this->one(
OrderDTO::class,
'SELECT id, title, status, created_at AS createdAt FROM orders WHERE id = ?',
[$id],
);
}
public function create(array $values): int
{
return $this->insert(Orders::class, $values);
}
}8. Service & exceptions
Put authorization and domain rules in Core/Services/OrderService.php, throwing HttpException subclasses (403, 404, 409) from Core/Exceptions/:
php
<?php
declare(strict_types=1);
namespace LIMS\Modules\Orders\Core\Services;
use LIMS\Modules\Orders\Core\DTOs\OrderDTO;
use LIMS\Modules\Orders\Core\DTOs\OrderFormDTO;
use LIMS\Modules\Orders\Core\Exceptions\OrderForbiddenException;
use LIMS\Modules\Orders\Core\Exceptions\OrderNotFoundException;
use LIMS\Modules\Orders\Core\Repositories\OrderRepository;
use LIMS\Platform\CurrentUser;
final class OrderService
{
public function __construct(
private readonly OrderRepository $orders,
private readonly CurrentUser $user,
) {}
/** @return list<OrderDTO> */
public function list(): array
{
return $this->orders->all();
}
public function get(int $id): OrderDTO
{
return $this->orders->find($id) ?? throw new OrderNotFoundException();
}
public function create(OrderFormDTO $form): int
{
if (!$this->user->can('orders', 'add')) {
throw new OrderForbiddenException('You may not create orders.');
}
return $this->orders->create(['title' => trim($form->title)]);
}
}9. Wire the controller's GET & POST actions
Update Controllers/OrdersController.php:
php
#[Controller('orders')]
final class OrdersController
{
public function __construct(private readonly OrderService $orders) {}
#[Get(default: true)]
public function index(): FusionResponse
{
return Fusion::render('OrderList/OrderList.component.ts', [
'orders' => $this->orders->list(),
]);
}
#[Post]
public function create(OrderFormDTO $data): JsonResponse
{
return new JsonResponse(['id' => $this->orders->create($data)]);
}
}On the Angular side, submit forms with postForm() (see Forms, Validation & Actions), map 422 responses with fieldErrors(), then call await navigate(url(...)) and toastStore.success(...).
Part 3 — Access, flags, submodules & Export/
10. Declare permissions (access_config.php) & flags (flag_config.php)
Create access_config.php in the module root for domain-specific actions (generic add, edit, remove, settings are added automatically by the sync):
php
<?php
return [
'module' => 'orders',
'label' => 'Orders',
'primary_table' => 'orders',
'related_tables' => ['order_lines'],
'actions' => [
'approve_orders' => [
'label' => 'Approve orders',
'description' => 'Approve and cancel orders.',
'default' => false,
'risk' => 'high',
],
],
];Add flag_config.php if you need runtime feature toggles. See Access Control & Feature Flags.
11. Submodules & Export/
- Extract a cohesive child feature with its own tables and routes into
Modules/<Submodule>/, register its controller in the parent'sindex.php(controllers: [OrderLinesController::class]), and expose its embeddable UI or service contract inModules/<Submodule>/Export/. - Place anything external modules need from your module inside
Export/— never let other modules import directly fromCore/orUI/. See Submodules & Cross-Module Exports.
12. Sync locally
Open /admin/Modules/Orders/View as a Master user and verify all three built-in admin pages:
?feature=migrations— generate & run pending migrations and seeds?feature=access— syncaccess_config.php?feature=flags— syncflag_config.php(if present)
Next: learn how builds, CI, and server sync work in Deploy to Production.