Skip to content

Module Architecture ​

How a Labmin LIMS module is organized on disk, how Controllers/ delegate to Core/, and the dependency boundaries that keep modules and submodules cleanly decoupled.

Directory layout & PSR-4 ​

composer.json maps the LIMS\ namespace to admin/ (covering both LIMS\Platform\ and LIMS\Modules\):

text
admin/Modules/Sales/Modules/Orders/Core/Services/OrderService.php
→ LIMS\Modules\Sales\Modules\Orders\Core\Services\OrderService

Every module and submodule follows the same predictable layout:

text
admin/Modules/<Module>/
  Controllers/          # Thin HTTP controllers (one class per file)
  Core/                 # Domain & business logic — NEVER depends on UI/
    DTOs/               # #[DataObject] form inputs & JsonSerializable read models
    Enums/              # Backed enums for statuses, tabs, roles
    Exceptions/         # HttpException subclasses (403, 404, 409)
    Interfaces/         # Contracts implemented by submodules or collaborators
    Repositories/       # SQL reads & MaterializeSQL writes (extends Platform\Repository)
    Services/           # Domain rules, access/flag checks, workflows, notifications
  Database/             # Schemas/, Migrations/, Seeds/ (see Database & Migrations)
  Export/               # Public API — the ONLY folder other modules may import
  Modules/              # Optional submodules, each using this same layout
  UI/
    Assets/             # Static images / files
    Components/         # Shared Angular components, request helpers, prop types (<module>.types.ts)
    Views/              # Fusion pages: Views/<Name>/<Name>.component.ts
  access_config.php     # Permissions declaration (?feature=access)
  flag_config.php       # Optional feature flags declaration (?feature=flags)
  index.php             # Entry point (top-level modules only)
  DEVELOPING.md         # Optional module-specific conventions & shared services

Only create a folder when you need it. A small module with no custom exceptions or flags simply omits Core/Exceptions/ and flag_config.php. Core/ may also hold specialized logic folders such as Core/Guards/ when needed, as long as they contain no UI code.


Request layers inside a module ​

Inside LimsRouter::render(), every action flows through two cleanly separated server layers:

text
HTTP Request → Controllers/ (parse & respond) → Core/Services/ (rules & auth) → Core/Repositories/ (SQL)

1. Thin controllers (Controllers/) ​

Every controller lives in Controllers/, even if a module only has one:

  • One class per file, named <Name>Controller, decorated with #[Controller('<kebab-feature-name>')].
  • Constructor DI: Declare services, repositories, CurrentUser, DatabaseManager, or LimsFileStorage as private readonly constructor parameters. LimsRouter resolves and instantiates them once per request.
  • No business logic in controllers: Parse IDs/query params, delegate to Core/Services/, and return a typed response.
Action typeReturn typeExample
Render a Fusion pageFusionResponseFusion::render('Order/Order.component.ts', [...])
Return async JSON data (GET)JsonResponsenew JsonResponse($page)
Mutate state (POST)JsonResponsenew JsonResponse(['id' => $id])
Serve a file (GET)FileResponsenew FileResponse($path, $name, download: true, contentType: $mime)

Never redirect from a POST action

POST actions return JSON (e.g. {"id": 5}) and let the Angular view call navigate() and show a confirmation toast. If the destination depends on server logic the view doesn't know, include the target IDs or URL in the JSON response.

When multiple controllers need to render the same complex page, extract a <Name>Page props builder class in UI/ (e.g. UI/OrderPage.php).

2. Core domain logic (Core/) ​

Core/ contains all business rules and never imports from UI/, keeping it safe to call from controllers, Export/, CLI jobs, or submodules:

  • Services/ — Authorization (CurrentUser::can()), feature flag gates (CurrentUser::hasFlag()), workflow transitions, domain invariants, reference numbering, notifications, and file-storage orchestration.
  • Repositories/ — Extend LIMS\Platform\Repository for parameterized SQL reads and schema-validated writes (zero business rules).
  • DTOs/ — #[DataObject] form inputs (with validation attributes) and read models implementing JsonSerializable (so DateTimeImmutable serializes cleanly as 'Y-m-d' or 'Y-m-d H:i').
  • Enums/ — Backed enums for statuses, tabs, and categories (OrderStatus::Open).
  • Exceptions/ — Subclasses of Labmin\Router\HttpException with semantic HTTP status codes: 403 (access denied), 404 (not found), 409 (workflow/state conflict).
  • Interfaces/ — Contracts implemented by submodules or collaborators.

Because LimsRouter wraps every non-migration request in a single transaction, throwing an HttpException or failing DTO validation (422) rolls back every database write from that request automatically.


Dependency boundaries ​

Strict boundaries prevent tight coupling across modules:

From → ToAllowed
Core/ → UI/Never. No HTML strings and no imports from UI/.
Submodule → ParentParent's Core/ and UI/Components/ (shared services, exceptions, base repositories, UI helpers).
Parent → SubmoduleSubmodule's Controllers/ (to register routes in index.php) and its Export/. Nothing else.
Sibling → SiblingOnly Export/.
Any external module → This moduleOnly Export/. Everything in Core/, UI/, and Database/ is private.

Top-level modules vs submodules ​

  • Top-level module: Has index.php, which constructs a LimsRouter for itself and all of its submodules. Accessed via /admin/Modules/<Module>/View.
  • Submodule (Modules/<Submodule>/): Has no index.php. Its controllers are registered in the parent's index.php. It can either:
    • Provide an embeddable component in Export/ (e.g. Notes/Modules/Todos/Export/TodoPanel.component.ts) backed by JSON actions, or
    • Own full Fusion pages in Modules/<Submodule>/UI/Views/<Page>/<Page>.component.ts (e.g. QualityAssurance/Modules/ProficiencyTesting/UI/Views/...).
  • Auto-discovery: LimsRouter automatically discovers every submodule's Database/, access_config.php, and flag_config.php beneath the parent module's directory.

Real-world reference modules ​

  • admin/Modules/Notes — Compact top-level module with one helper submodule (Todos), attachments, access action, feature flag, Fusion pages, and Export/.
  • admin/Modules/QualityAssurance — Large parent module hosting multiple full-page submodules (ProficiencyTesting, DocumentControl, Improvements, CorrectiveActions), shared Core/ services, and a dashboard integration interface (QualityFeature). See Submodules & Cross-Module Exports.

Next: learn how tables, schemas, migrations, and repositories work in Database & Migrations.

Labmin LIMS Module Developer Documentation