Skip to content

Project Structure

A PAM Desktop project is an ordinary Composer project with one entry script and an optional manifest. Only the entry script is required to run; everything else is convention that pam desktop init sets up for you and that the rest of these docs follow.

my-app/
index.php entry script: registers components, calls App::run()
pam-desktop.json manifest: identity, window, packaging, updates
composer.json PHP 8.5, pushinbr/pam-desktop, App\ autoload
src/
app.css shared design tokens and global rules
Navigation/ route enum and router
Screens/<Name>/<Name>Screen.pam.php one folder per screen
Components/ reusable .pam.php components
Services/ application logic
Lib/ small shared helpers
assets/ files loaded with asset:// URLs (images, fonts)
tests/ PHP tests run without a window
vendor/ Composer packages
.pam-desktop/ created by `pam desktop dev`: data, cache, state, compiled templates
dist/ created by `pam desktop build`

The project directory is also:

  • the working directory of the PHP worker;
  • the root asset:// URLs resolve in (asset://assets/logo.png is assets/logo.png);
  • the directory pam desktop dev watches.

The .gitignore that init writes excludes vendor, .pam-desktop and dist.

index.php
<?php
declare(strict_types=1);
use App\Navigation\AppRouter;
use Pam\Desktop\App;
require __DIR__.'/vendor/autoload.php';
App::components(__DIR__.'/src', __DIR__.'/.pam-desktop/components');
App::run(AppRouter::make());

App::components($directory, $cacheDirectory) compiles every .pam.php file under $directory and registers each class as a template tag. App::run() boots the application with a root: a component, a closure that returns an element, a screen class or a navigator.

Optional packages register their tags in the same place, before App::run():

index.php
use Pam\Desktop\Charts\Charts;
use Pam\Desktop\Markdown\Markdown;
use Pam\DesktopUi\DesktopUI;
Markdown::register();
Charts::register();
DesktopUI::boot(__DIR__.'/.pam-desktop/desktop-ui');
App::components(__DIR__.'/src', __DIR__.'/.pam-desktop/components');
App::run(AppRouter::make());

The manifest is optional when you run an application: a missing or malformed file means defaults. pam desktop build and publish-update are strict and stop on an invalid value. This is what init writes:

pam-desktop.json
{
"$schema": "./vendor/pushinbr/pam-desktop/packages/desktop/resources/pam-desktop.schema.json",
"applicationId": "com.example.my-app",
"name": "my-app",
"version": "0.1.0",
"entry": "index.php",
"window": { "width": 960, "height": 640 }
}

The $schema points at the JSON Schema shipped in the package, so your editor completes and checks the keys.

Key Default Meaning
applicationId derived from the folder name Reverse-DNS identifier. It names the per-user directories, the keychain service and, on Linux, the GTK application. Declare one before distributing.
name PAM Desktop Title of the first window.
version, build empty Reported as DeviceInfo::$appVersion and DeviceInfo::$buildNumber.
entry index.php The script a project directory starts with.
singleInstance true under run when urlSchemes is set, else false A second launch hands its link to the running application and exits.
window.title name Title of the first window.
window.width, window.height 960 × 640 Initial size in logical units, clamped to 120…16384. Both must be present.
window.minWidth, window.minHeight none Smallest size the user can give the window. Both must be present.
window.resizable true Whether the user can resize the window.
window.remember true Reopen with the size and maximized state of the last session.

An applicationId needs at least two dot-separated segments, each starting with a letter, _ or -, holding only ASCII letters, digits, _ and -, at most 255 bytes in all.

description, publisher, category, icon, exclude, extensions and urlSchemes shape the bundle and installers; see Distribution. The updates block pins a signed update feed; see Signed Updates.

pam-desktop.json
{
"applicationId": "com.example.invoices",
"name": "Invoices",
"version": "1.0.0",
"window": {
"width": 1100,
"height": 720,
"minWidth": 640,
"minHeight": 480
}
}

Every command runs through the PAM CLI as pam desktop <command>, or directly as vendor/bin/pam-desktop <command> when a PHP 8.5 is on PATH.

pam desktop init [directory] [--name NAME] [--id APPLICATION-ID]
pam desktop dev [app] [url] run with hot reload
pam desktop run [app] [url] run as in production, opened with a link
pam desktop check [--json] [--src=DIR] validate templates, stylesheets and routes without a window
pam desktop build [app] [options] bundle and build installers
pam desktop update-key --output FILE create the key that signs updates
pam desktop publish-update [app] ... sign an update feed
pam desktop --version

Without app, the commands use the nearest directory, from the current one up, that holds a pam-desktop.json. app may also be a PHP file, which then becomes the entry script. url is the link the application is opened with; Linking::initial() reports it.

init never overwrites a file: it prints [new], [kept] or [merged] for each one, so it is safe to run where Composer already wrote composer.json.

dev run
Source changes Restart the PHP worker and keep the window Not watched
Application directories .pam-desktop/ inside the project Per-user directories of the system
PAM_DESKTOP_MODE development production
Errors Shown with source and call stack Reload silently, then offer a retry screen
Plain http:// Allowed for images and HTTP requests Refused, except loopback hosts in HTTP requests
Code Meaning
0 The application ended, or a single instance already runs and was handed the link.
1 The PHP worker could not be started.
64 Unknown command.
66 The entry script does not exist.
69 The worker bootstrap of pushinbr/pam-desktop was not found.
73 The application directories could not be created.

Under pam desktop run and in installed bundles, each system’s conventions apply (<id> is the applicationId):

Directory Linux macOS Windows
Data ~/.local/share/<id> ~/Library/Application Support/<id> %APPDATA%\<id>
Cache ~/.cache/<id> ~/Library/Caches/<id> %LOCALAPPDATA%\<id>\Cache
State ~/.local/state/<id> ~/Library/Application Support/<id>/State %LOCALAPPDATA%\<id>\State

On Linux the XDG_DATA_HOME, XDG_CACHE_HOME and XDG_STATE_HOME variables are honored. Under pam desktop dev the three live in .pam-desktop/data, .pam-desktop/cache and .pam-desktop/state instead.

Directory Contents
Data storage.json (key/value storage), pam-files/ (file sandbox), pam-databases/ (SQLite), secure/ (encrypted large secrets)
Cache pam-images-v1/, pam-media-v1/, compiled PHP. Safe to delete at any time.
State settings.json (appearance and text scale), navigation state, hot reload checkpoints, window.json

Variables you may set before starting the host:

Variable Effect
PAM_DESKTOP_PHP Path of the PHP executable for the worker.
PAM_DESKTOP_AUTO_INSTALL 1 installs PHP without asking when none is found.
PAM_DESKTOP_HOST The host binary vendor/bin/pam-desktop runs instead of the downloaded one.
PAM_DESKTOP_WINDOW WIDTHxHEIGHT: the size of the first window for this run.
PAM_DESKTOP_DATA_DIR, PAM_DESKTOP_CACHE_DIR, PAM_DESKTOP_STATE_DIR Absolute paths that replace the application directories.
PAM_DESKTOP_LAUNCH_URL The URL the application was launched with. A url argument wins.
PAM_DESKTOP_DEBUG Logs every pointer press, key press and event sent to PHP.
PAM_DESKTOP_PROFILE 1 times each interaction on standard error.
PAM_DESKTOP_STRICT 1 makes BuildConfiguration::strict() true in development too.
PAM_DESKTOP_SECURE_STORAGE memory keeps secrets in the host process, for tests.
GTK_USE_PORTAL Linux: 0 reads dark mode from GTK settings instead of the desktop portal.

The host sets these for the worker; read them, do not set them: PAM_DESKTOP_PROJECT_ROOT, PAM_DESKTOP_APPLICATION_ID, the three directory variables, PAM_DESKTOP_PLATFORM (linux, macos or windows), PAM_DESKTOP_MODE and PAM_DESKTOP_LAUNCH_URL.