Search by

noirapi / framework

deba12

Small PHP 8.4 web framework: FastRoute routing, Latte views, noirapi/database models, Tracy debugging.

v2.14.0 2026-12-04 02:11 UTC

README

Small PHP 8.4 web framework: FastRoute routing, Latte views, noirapi/database models, Tracy debugging, NEON config, and pluggable auth (password, magic link, TOTP, GitHub/Google OAuth).

Package: noirapi/framework, namespace Noirapi\, PHP ^8.4, MIT.

Installation

There are two supported layouts, and they run the same code (Noirapi\Lib\Kernel).

Composer (new projects)

composer require noirapi/framework

Project layout. Every path is relative to the project root, which the kernel is given:

myapp/
  app/
    Route.php            App\Route: process($method, $uri) -> FastRoute dispatch result
    controllers/ models/ views/ layouts/
    config/default.neon  picked by the CONFIG env var, else the virtual host name, else "default"
  htdocs/index.php       web root
  temp/  logs/           must exist and be writable (Latte/config cache, Tracy logs)
  data/                  SQLite databases with relative DSNs
  vendor/
  composer.json          "autoload": {"classmap": ["app/"]}

htdocs/index.php:

<?php

declare(strict_types=1);

require dirname(__DIR__) . '/vendor/autoload.php';

Noirapi\Lib\Kernel::run(dirname(__DIR__));

CLI scripts only boot (config, timezone, sessions, Tracy):

require __DIR__ . '/../../vendor/autoload.php';
Noirapi\Lib\Kernel::boot(__DIR__ . '/../..');

Tools are exposed as one Composer binary (see docs/cli.md):

vendor/bin/noirapi dev-server start [--port 8000] [--host localhost] [--config NAME]
vendor/bin/noirapi dev-server stop|restart|status
vendor/bin/noirapi latte-lint app/views
vendor/bin/noirapi latte-check [--strict] [--no-controller-check]
vendor/bin/noirapi latte-format [--check] [paths]   # tidy templates
vendor/bin/noirapi crawl crawl.json [--start]   # see docs/crawl.md
vendor/bin/noirapi cache:clear | config:check | routes:list | key:generate
vendor/bin/noirapi make:controller Name | make:model Name | db:migrate

git submodule (existing projects)

Existing apps keep the framework checked out at <root>/noirapi/ and use the legacy entry points, which are thin shims over the same kernel:

require dirname(__DIR__) . '/noirapi/kernel.php';   // htdocs/index.php and CLI scripts
require dirname(__DIR__) . '/noirapi/include.php';  // bootstrap only
noirapi/bin/dev-server start
noirapi/bin/latte-lint app/views
php noirapi/bin/latte-check.php

See UPGRADE.md for what a submodule app needs when it updates to 1.x, and for moving it to the Composer layout.

How the application root is found

Noirapi\Config::getRoot() resolves, in order:

  1. the root passed to Kernel::run() / Kernel::boot();
  2. the NOIRAPI_ROOT environment variable (vendor/bin/noirapi and dev-server set it);
  3. the submodule layout: the framework's parent directory, when it contains app/;
  4. the Composer layout: the root of the Composer install that contains noirapi/framework.

The framework's own files (bundled templates, bin scripts) are found with Config::getFrameworkDir().

Desktop apps

Since 2.6 the same app can also run as a desktop program: a native shell (Tauri, or anything that can start a process and show a webview) starts PHP's built-in server on 127.0.0.1 and opens it. What the framework provides:

  • Read-only code: the code root can be a phar (NOIRAPI_ROOT=phar://…/app.phar, or htdocs/index.php inside it) or any read-only folder; everything written goes to the writable root, NOIRAPI_DATA (temp/, logs/, data/ for relative SQLite paths, Noirapi\Lib\WritableRoot).
  • Prebuilt (vendor/bin/noirapi prebuild <config>, docs/prebuilt.md): config, routes, ACLs, translations and compiled templates are made at build time, so nothing is compiled or cached at runtime and a new version starts as fast as a relaunch.
  • Secrets from the environment: %env(NAME)% config values, so no config file with a secret is written.
  • SQLite as the database: Windows paths (C:\…, \\server\share\…), transactions that begin IMMEDIATE, and connections that are the driver subclasses (Pdo\Sqlite: createFunction() for app functions). Since 2.7, per-connection pragmas (foreign keys, busy timeout, WAL) and schema migrations that apply on start (docs/db.md), and, with dialect: mariadb, SQLite that speaks MariaDB: the same queries, functions and answers, so one app runs on both (docs/sqlite-mariadb.md). Without it SQLite stays plain SQLite. Queries only: the schema is up to the programmer. CREATE/ALTER TABLE are not translated, so an app keeps SQLite migrations of its own next to the MariaDB ones (e.g. sql/sqlite/).

Documentation

Development

composer install
composer test        # PHPUnit
composer phpstan     # PHPStan (level 5)
composer psalm       # Psalm 7 (level 4, purity annotations required)
composer phpmd       # PHPMD 3
composer phpcs       # PSR-12
composer coverage    # coverage summary (needs pcov or Xdebug)

Commit messages follow Conventional Commits: a header type(scope): subject and a body (30+ characters, trailers don't count) that says why the change is made, not which files it touches. commitlint.config.js holds the rules; CI checks every commit of a pull request. To check locally before each commit, once per clone:

npm install
git config core.hooksPath .githooks

Releases are tagged vX.Y.Z on master. CI (.github/workflows/ci.yml) runs the tests and then notifies Packagist; it needs the PACKAGIST_USERNAME and PACKAGIST_TOKEN repository secrets.