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.
Create the project
Section titled “Create the project”-
Create the project with the desktop template:
Terminal window pam init my-app --template desktopcd my-apppam initcreates the directory, installspushinbr/pam-desktopand runspam desktop init, which writes a small, ready application. -
Start it:
Terminal window pam desktop devA 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.
-
Open
src/Screens/Home/HomeScreen.pam.phpin your editor, change the text of theleadparagraph 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:
pam composer installpam desktop initpam desktop devWhat was generated
Section titled “What was generated”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 windowThe entry script registers the components under src and starts the router:
<?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.
Build a screen
Section titled “Build a screen”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:
<?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$draftproperty in both directions;on:submitruns when the user presses Enter.p-forrepeats an element,p-keygives each row a stable identity and$taskIndexis the position..primary:hoveris applied by the host itself, without a round trip to PHP.var(--accent)and the other tokens come fromsrc/app.css, which switches them for dark mode.
Templates and Styling cover the syntax in depth.
Persist the tasks
Section titled “Persist the tasks”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.
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.
Test it
Section titled “Test it”The skeleton ships a test that mounts the screen through its real lifecycle, without a host or a window:
<?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";pam tests/HomeScreenTest.phpThe skeleton also wires it as the Composer test script.
Check every template, stylesheet and route without opening a window:
pam desktop checkSee Testing for more.
Ship it
Section titled “Ship it”Build a self-contained bundle and the installers of your system:
pam desktop buildThe artifacts land in dist/. Distribution covers every format and signing.
Next steps
Section titled “Next steps”- Components for every element.
- State & Lifecycle for reactivity and lifecycle hooks.
- Windows, Menus & Tray for menus, shortcuts and dialogs.
- Debugging for the error overlay and the inspector.