Skip to content

Your First App

This guide takes you from an empty directory to a running desktop application in a few minutes. You will create a project, change a screen while it runs, add state and a stylesheet, call a service, and run the test the skeleton ships. It assumes you finished Installation.

  1. Create the project with the desktop template:

    Terminal window
    pam init my-app --template desktop
    cd my-app

    pam init creates the directory, installs pushinbr/pam-desktop and runs pam desktop init, which writes a small, ready application.

  2. Start it:

    Terminal window
    pam desktop dev

    A window opens on the home screen. The first run downloads the native host for your system and, if no PHP is found, offers to install the PAM runtime.

  3. Open src/Screens/Home/HomeScreen.pam.php in your editor, change the text of the lead paragraph and save. The window updates in about a third of a second and keeps its state: the click count survives the reload.

If you created the project with --no-install, finish it by hand:

Terminal window
pam composer install
pam desktop init
pam desktop dev
my-app/
pam-desktop.json identity, window and packaging
composer.json PHP 8.5, pushinbr/pam-desktop; scripts dev, start, build, test
index.php boots the router
src/
app.css design tokens (light and dark) shared by every screen
Navigation/AppRoute.php the routes, as an enum
Navigation/AppRouter.php the stack and the screen of each route
Screens/Home/HomeScreen.pam.php the home screen: class, <template> and scoped <style>
Services/Greeting.php application logic the screens call
Lib/Plural.php a small shared helper
tests/HomeScreenTest.php mounts the home screen without a window

The entry script registers the components under src and starts the router:

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());

Project Structure explains every file and the pam-desktop.json manifest.

Each screen is one .pam.php file: a PHP class with its state and actions, a <template> of tags and a <style scoped> block. Replace the home screen with a small task list:

src/Screens/Home/HomeScreen.pam.php
<?php
declare(strict_types=1);
namespace App\Screens\Home;
use Pam\Desktop\Attributes\State;
use Pam\Desktop\Component;
final class HomeScreen extends Component
{
#[State]
public string $draft = '';
/** @var list<string> */
#[State]
public array $tasks = [];
public function add(): void
{
$task = trim($this->draft);
if ($task === '') {
return;
}
$this->tasks[] = $task;
$this->draft = '';
}
public function remove(int $index): void
{
array_splice($this->tasks, $index, 1);
}
}
?>
<template>
<Column class="page">
<Text class="title">Tasks</Text>
<Row class="composer">
<Input class="field" model="draft" placeholder="What needs doing?" on:submit="add" />
<Button class="primary" label="Add" on:press="add" />
</Row>
<Text p-if="count($tasks) === 0" class="empty">Nothing yet.</Text>
<Row p-for="$task in $tasks" p-key="$task" class="task">
<Text class="task-text">{{ $task }}</Text>
<Button label="Done" on:press="remove($taskIndex)" />
</Row>
</Column>
</template>
<style scoped>
.page { flex: 1; padding: 32px; gap: 14px; background-color: var(--background); }
.title { color: var(--text); font-size: 28px; font-weight: 700; }
.composer { gap: 10px; align-items: center; }
.field { flex: 1; height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border); }
.primary { background-color: var(--accent); color: #FFFFFF; border-radius: 8px; height: 40px; padding: 0 18px; }
.primary:hover { background-color: var(--accent-strong); }
.empty { color: var(--muted); }
.task { gap: 12px; align-items: center; padding: 10px 12px; border-radius: 8px; background-color: var(--surface); }
.task-text { flex: 1; color: var(--text); }
</style>

Save, and the window shows the new screen. A few things to notice:

  • #[State] properties are reactive. Assigning to one schedules exactly one render after the handler returns.
  • model="draft" binds the input to the $draft property in both directions; on:submit runs when the user presses Enter.
  • p-for repeats an element, p-key gives each row a stable identity and $taskIndex is the position.
  • .primary:hover is applied by the host itself, without a round trip to PHP.
  • var(--accent) and the other tokens come from src/app.css, which switches them for dark mode.

Templates and Styling cover the syntax in depth.

Keep the list across launches with the key/value storage module. Module calls are asynchronous: the result arrives in a callback, and the component renders again after the callback returns.

src/Screens/Home/HomeScreen.pam.php
use Pam\Desktop\Storage\Storage;
public function mount(): void
{
Storage::get('tasks', function (?string $json): void {
$this->tasks = $json === null ? [] : json_decode($json, true);
});
}
private function save(): void
{
Storage::set('tasks', json_encode($this->tasks));
}

Call $this->save() at the end of add() and remove(). In pam desktop dev the stored values live in .pam-desktop/data/storage.json inside the project, so development never touches your real profile.

The skeleton ships a test that mounts the screen through its real lifecycle, without a host or a window:

tests/HomeScreenTest.php
<?php
declare(strict_types=1);
use App\Screens\Home\HomeScreen;
use Pam\Desktop\App;
use function Pam\Desktop\Testing\mount;
require dirname(__DIR__).'/vendor/autoload.php';
App::components(dirname(__DIR__).'/src', dirname(__DIR__).'/.pam-desktop/components');
$home = mount(HomeScreen::class);
$home->instance->draft = 'Write the docs';
$home->instance->add();
$home->render();
if (!str_contains($home->text(), 'Write the docs')) {
fwrite(STDERR, "failed: a task is added\n");
exit(1);
}
$home->unmount();
echo "ok\n";
Terminal window
pam tests/HomeScreenTest.php

The skeleton also wires it as the Composer test script.

Check every template, stylesheet and route without opening a window:

Terminal window
pam desktop check

See Testing for more.

Build a self-contained bundle and the installers of your system:

Terminal window
pam desktop build

The artifacts land in dist/. Distribution covers every format and signing.