# Projects

Bootgly organizes applications as **projects** — self-contained directories inside `projects/` that contain a boot file. Each project declares its metadata (name, description, version, author) and a boot Closure that initializes the application.

A project can live at **any depth** inside `projects/`. A directory like `Demo/` can group several **subprojects** (`Demo/HTTP_Server_CLI`, `Demo/TCP_Server_CLI`, …), each started independently by its path. Projects are managed entirely through the `project` CLI command, which lists, runs, stops, inspects and hot-reloads them.

## Project structure

A project is a directory inside `projects/` (at any depth) containing a boot file named after its **leaf** folder — the convention is `{leaf}.Project.php`. The file name matches the last path segment, not the full path.

```
projects/
├── Bootgly.projects.php          ← the registry (allow-list)
├── Site/                         ← a flat project (one path segment)
│   └── Site.Project.php
└── Demo/                         ← a grouping folder (not a project itself)
    ├── HTTP_Server_CLI/
    │   └── HTTP_Server_CLI.Project.php
    └── TCP_Server_CLI/
        └── TCP_Server_CLI.Project.php
```

Here `Demo/HTTP_Server_CLI` and `Demo/TCP_Server_CLI` are two subprojects grouped under `Demo/`. `Demo/` itself has no `.Project.php` — it is only a container.

### Boot file example

Each boot file returns a `Project` instance with metadata and a boot Closure:

```php
use Bootgly\API\Projects\Project;

return new Project(
   name: 'Generic Project',
   description: 'A generic Bootgly project example',
   version: '1.0.0',
   author: 'Your Name',
   exportable: true,

   boot: function (array $arguments = [], array $options = []): void
   {
      // Initialize and run your application here
   }
);
```

The constructor derives `path` (the absolute project directory) and `folder` (the project's path **relative to** `projects/`, e.g. `Demo/HTTP_Server_CLI`) automatically from the boot file's location — `folder` is the project's canonical identifier.

## The project registry

A single file at the root of `projects/` — **`Bootgly.projects.php`** — declares every registered project. It is both the interface map (which projects belong to CLI and/or WPI) **and the security boundary**: only paths listed here may be started.

It returns a project-keyed map, kept in **alphabetical order by path**. Each key is a project's canonical path (relative to `projects/`); each value lists the `interfaces` it serves:

```php
<?php
return [
   'Demo/CLI'             => ['interfaces' => ['CLI']],
   'Demo/HTTP_Server_CLI' => ['interfaces' => ['WPI']],
   'Demo/TCP_Server_CLI'  => ['interfaces' => ['WPI']],
   'Site'                 => ['interfaces' => ['CLI']],
];
```

A project that serves both interfaces lists both: `['interfaces' => ['CLI', 'WPI']]`. Web projects are served by Bootgly's own CLI HTTP server and are always started by name (`bootgly project <path> start`) — there is no web SAPI mode and no autoboot default.

### Why an allow-list

Because projects can nest arbitrarily, an attacker who compromised your project tree could otherwise hide a rogue nested `.Project.php` and have it executed. The registry closes that door: `bootgly project <path> start` runs **only** paths that are exact keys of `Bootgly.projects.php`. Anything else — an unregistered path, a grouping container (`Demo`), path traversal (`..`), an absolute path, a backslash or a null byte — is rejected, and the resolved directory is additionally jailed under the `projects/` base.

To make a new project runnable, use `bootgly projects create` — it generates the directory, the boot file and the registry entry in one step. The registry file is machine-managed by `create`/`import` (entries are re-emitted sorted; hand-added comments inside the array are not preserved).

Every value is re-emitted as an escaped PHP literal, the file is parse-verified before it is installed and the write is atomic — so no project name or metadata can leave the registry unparseable. Paths minted by `create`/`import` follow a naming alphabet: each segment starts uppercase and uses only letters, numbers, `_` or `-` (e.g. `App` or `App/API`). A path that was hand-registered before that rule keeps working — the allow-list check is the boundary, not the alphabet.

## Creating a project

`bootgly projects create` is the canonical way to start a new project. On interactive terminals it opens a **wizard**:

```bash :toolbar="true";
php bootgly projects create
```

The wizard prepares the kit on first run — every platform submodule (`Console` and `Web`), the `bootgly kit boot` resources and the shipped examples, none of it asked — then asks for the creation mode:

- **Using what is already imported** — the first mode creates nothing. A prepared kit already carries every exportable platform project, so standing pat and opening one of them is a first-class way to start; the option states how many the kit holds;
- **From scratch** — a minimal `CLI` or `WPI` project generated from the framework stubs: it asks the project path, interface, port and metadata, shows a summary and confirms;
- **Importing from a Git remote** — it asks the repository URL (checked at the prompt, see *Importing a project*), the target path and the interface, then delegates to `bootgly projects import`: the repository is cloned, validated against the `*.Project.php` signature and registered.

Only projects declared with `exportable: true` — written as the literal `true` — in their `new Project(...)` signature are stocked as examples and offered by the wizard; `--from=<source>` copies the platform project you name.

Non-interactively (CI, scripts, AI agents), everything comes from flags:

```bash
php bootgly projects create App/API --from=scratch --interfaces=WPI --port=8080 --yes
php bootgly projects create --from=Demo/HTTP_Server_CLI --yes
```

**Every project you create is booted — a git repository of its own.** `create`
runs the `bootgly project <Name> boot` hook: the scaffold — the project
signature, a `tests/` registry with an example suite and a `.gitignore`
(ignoring `/vendor/` and the `configs/**/.env` secrets) — lands as one initial commit, so `git log`, branches
and a remote of your choosing work from minute one. `--no-git` skips the hook;
on a machine with no git identity configured, the repository is left
initialized with the scaffold staged and nothing is committed in your name. A
nested project (e.g. `App/API` inside `App`) joins its parent's repository
instead of nesting one.

The **shipped platform examples** — the Demos, the Console games and the Web
apps — are imported automatically when the kit is prepared (first boot, and
whenever a platform is initialized), so a fresh kit always carries living
guides for people and AI agents alike. They arrive **unbooted** — they are
guides, not your work; adopt one with `php bootgly project <Name> boot`. An
example you delete stays deleted. The kit itself never tracks `projects/` —
each project is the unit of versioning, and **Composer is per project too**:
run `composer require` inside `projects/<Name>/`, and the framework loads that
project's `vendor/autoload.php` when the project boots.

## Importing a project

Any directory carrying the **Bootgly project signature** — a `*.Project.php` file at its root — is an importable project. `bootgly projects import` fetches one from a git repository URL:

```bash :toolbar="true";
php bootgly projects import https://github.com/foo/project1 Project1
```

The repository is cloned (system git) with its **full history**, validated against the signature, placed into `projects/Project1/` — `.git`, `origin` remote and all, so you keep committing and pushing from there — and registered in the allow-list. When the target name differs from the source's, the signature file is renamed to the new leaf and left **uncommitted** for you to review. Every rule the registry enforces is checked before the copy, so a refused import leaves nothing behind.

The URL is checked before anything is written or run. Accepted: `https://` without credentials, SSH (`git@host:owner/repo.git` or `ssh://git@host/owner/repo.git`), `file://` without credentials and a local path. Refused, each with its remedy:

- **credentials in the URL** — `https://user:token@…`, a token as the user name, any user part in a `file://` URL, or an SSH address `user:password@host:path`: let git supply them through a credential helper (`git help credentials`) or use SSH;
- **a remote helper** — `ext::` (runs a command), `fd::` or any `<name>::`: clone the repository yourself and import its local path;
- **a plaintext transport** — `http://`, `git://`, `ftp://`: use `https://` or SSH;
- **an unsupported transport** — any other scheme (`rsync://`, `ssh+git://` — write `ssh://` or `git+ssh://`);
- **a malformed URL** — one that is empty, starts with a dash, carries a control character or surrounding blanks, has text before its `scheme://`, a third slash after it or a slash missing (`https:/…`), or has `?`, `#`, `\` or a blank in its host part.

The clone runs without a shell and without terminal prompts (git asks no user name or password — use a credential helper or SSH), under the network deadline and `GIT_ALLOW_PROTOCOL=file:https:ssh`, so an `insteadOf` rewrite to another transport fails too. A `GIT_ALLOW_PROTOCOL` you already export narrows that list (only the transports both name), never widens it. The clone is staged in a private temporary directory (random name, mode `0700`) that is removed whether the import succeeds, is declined — Ctrl+C at the prompt included — or fails, and no output shows the URL's credentials. Since 1.0.10.

The lines git prints while cloning are shown as text: a carriage return (git's progress repainting) is dropped, and every other control character but TAB — in a remote's `remote:` messages, a path, a tag name — appears as a visible escape (`\u001b`, `\u009b`) instead of reaching the terminal; a byte that is not UTF-8 appears as `?`. This holds for a UTF-8 terminal. Since 1.0.12.

> [!WARNING]
> Imported projects run third-party code when started (`start`, `restart`, a `startup` unit), on their `migrate`, `seed` and `schedule`, and when their tests or queues run — the command asks for confirmation (skip with `--yes`). `projects list` and `project <path> info` only read the signature. A repository whose `*.Project.php` is a symbolic link, or that carries a `bootgly` launcher or a symbolic link named `bootgly` (the global `bootgly` command would run it from inside the project), is refused. Since 1.0.10.

## The `projects` and `project` commands

Two commands split the work by what they address. `projects` is the kit as a whole — the registry (`create`, `import`, `list`) and what is running across it (`show`); `project <Name>` is one project you name. Run `php bootgly projects` or `php bootgly project` to see the subcommands of each:

```mermaid
graph LR
  projects["php bootgly projects"]
  projects --> create["create"]
  projects --> import["import"]
  projects --> list["list"]
  projects --> ps["show"]
  project["php bootgly project &lt;Name&gt;"]
  project --> boot["boot"]
  project --> start["start"]
  project --> stop["stop"]
  project --> show["show"]
  project --> reload["reload"]
  project --> restart["restart"]
  project --> info["info"]
  project --> migrate["migrate"]
  project --> seed["seed"]
  project --> logs["logs"]
  project --> schedule["schedule"]
  project --> startup["startup"]
  project --> unstartup["unstartup"]
  project --> status["status"]
```

### `projects create`

Creates a new project — wizard on interactive terminals, flags otherwise:

```bash
php bootgly projects create [<Name>] [--platform=console,web] [--from=scratch|<source>] \
   [--interfaces=CLI|WPI] [--port=] [--description=] [--version=] [--author=] [--yes]
```

- `--platform` — narrows what the kit's first run sets up, comma-separated. Every platform is set up by default (`Console` and `Web` submodules initialized, `bootgly kit boot` run, shipped examples imported), so this flag only matters when you want less: `--platform=console` for one of them, `--platform=none` for the base platform alone. A later run only ever sets up what it names — a platform you removed stays removed;
- `--from` — `scratch` (default) or a platform project path (e.g. `Demo/HTTP_Server_CLI`). Platform imports keep their own path (`<Name>` is optional) and refresh an existing copy — the new copy is built beside the old one and swapped in only once it is complete. Only a project copy (a directory with a `*.Project.php` at its root) is refreshed; a group of projects or a hand-made directory at that path is refused, never replaced;
- `--interfaces` — interface bound to a from-scratch project (`CLI` default);
- `--port` — HTTP port written into a from-scratch WPI project file (`8080` default); a number between 1 and 65535, refused otherwise;
- `--description`, `--version`, `--author` — metadata written into the project file; quotes and backslashes are stored safely, control characters are refused;
- `--yes` — skips confirmations;
- `--no-git` — skips the boot hook (the project's own git repository, created and committed by default on from-scratch creates);
- `--refresh` — with `--from=<source>`, replaces a target that is already a git repository. Without it the command refuses: a repository in `projects/` is your only copy of that history.

A name you pass to `create` is yours: a **platform** example that would take the same path is left unstocked, so the first command on a new kit never loses to a name you have not seen. Names the **framework** itself ships (`Demo/*`) are the exception — those are refused outright, before anything is stocked, because the shelf they would be taken from is where the copy lives.

An unimplemented `--platform` value is refused too, on every layout: it used to be accepted and dropped in a framework checkout and in a kit without `.gitmodules`.

Setting a platform up initializes its submodule — and, when the kit pins it past a release, moves it back onto that release (`Console: pinned past a release — using v1.0.1.`) — through Bootgly's git engine: no shell, git's messages in English, no credential prompt, the network deadline. The lines git prints are shown as text — a carriage return dropped, every other control character but TAB as a visible escape (`\u001b`, `\u009b`), a byte that is not UTF-8 as `?` — and so is the release name. Since 1.0.12.

### `project boot`

Boots a project — initializes the resources a project of your own carries. Today that is version control (a git repository of its own, with the current tree as the initial commit); more responsibilities will land here as the project lifecycle grows:

```bash
php bootgly project <Name> boot
```

`projects create` runs the same hook for every from-scratch project. The shipped platform examples arrive unbooted; this subcommand is how you adopt one. A URL import brings its own repository and history along. Best-effort by design: a disabled shell, a missing git or an unset identity degrades to a note, never to a failure.

### `projects import`

Imports a project from a git repository URL (`https://`, SSH, `file://` or a local path — see *Importing a project* for what is refused) carrying the `*.Project.php` signature. Without arguments, interactive terminals choose the import source first — the Platforms (a multi-selection showing how many exportable projects are available) or a Git remote (asks the URL):

```bash
php bootgly projects import <url> [<Name>] [--interfaces=CLI|WPI] [--yes]
```

### `projects list`

Lists every registered project — one row each, with the interfaces the registry binds it to and the description its signature carries. The description is clipped to the terminal width, never wrapped. The signature is read, never run: the description comes from a plain string literal in `return new Project(...)` (a computed value shows as `(dynamic)`), a signature that is missing, a symbolic link, larger than 256 KiB, does not parse or does not `return new Project(...)` is listed as `(invalid signature: <reason>)` while the rest of the listing prints. Metadata is shown as text: a control character in it appears as a visible escape (`\u001b`, `\u009b`) and a byte that is not UTF-8 as `?`, bidi and zero-width marks are removed, and Output markup is not rendered. Since 1.0.12 — before, control characters were removed.

```bash :toolbar="true";
php bootgly projects list
```

Example output:

```
╔═════╤══════════════════════╤════════════╤═══════════════════════════════════════════════════════╗
║ #   │ Project              │ Interface  │ Description                                           ║
╟─────┼──────────────────────┼────────────┼───────────────────────────────────────────────────────╢
║ 1   │ App/API              │ WPI        │ Orders API                                            ║
║ 2   │ Demo/CLI             │ CLI        │ Demonstration project for Bootgly CLI features        ║
║ 3   │ Demo/HTTP_Server_CLI │ WPI        │ Demonstration project for Bootgly HTTP Server CLI     ║
╚═════╧══════════════════════╧════════════╧═══════════════════════════════════════════════════════╝
```

### `projects show`

Shows every **running instance** across the registered projects — the `ps` of the kit. One line per instance, never per project: a project can hold several (one per bound port for servers, one per master PID for console and schedule workers), and the instance is what you address by port in `stop`/`reload` or with `--instance` in `logs`:

```bash :toolbar="true";
php bootgly projects show
```

Example output:

```
╔══════════════════════╤══════════╤═══════════╤═════════╤════════╤═════════╤════════╤══════════════╤═════╗
║ Project              │ Instance │ Interface │ Status  │ Master │ Workers │ Uptime │ Address      │ Tap ║
╟──────────────────────┼──────────┼───────────┼─────────┼────────┼─────────┼────────┼──────────────┼─────╢
║ Demo/HTTP_Server_CLI │ 8080     │ WPI       │ running │ 41230  │ 4       │ 2h 15m │ 0.0.0.0:8080 │ yes ║
║ App/API              │ 8443     │ WPI       │ paused  │ 41301  │ 4       │ 2h 14m │ 0.0.0.0:8443 │ yes ║
║ App/API              │ 41988    │ CLI       │ running │ 41988  │ -       │ 5m 12s │ -            │ -   ║
╚══════════════════════╧══════════╧═══════════╧═════════╧════════╧═════════╧════════╧══════════════╧═════╝
```

Liveness is the instance lock — the same proof `project <Name> show` uses — so a state file left behind by a crash never shows as running. `Tap` says whether the instance publishes the live-log socket that `logs -f` attaches to. On a narrow terminal the table gives up its secondary columns first — `Tap`, `Workers`, `Master`, `Interface`, then `Address` and `Uptime` — the way `pm2 ps` does; `Project`, `Instance` and `Status` always stay, and `--json` always carries every field. Two flags:

- `--all` — also lists what is still on record but no longer running (`stopped`): the tombstone a clean stop leaves, or a document whose master is gone;
- `--json` — one JSON document with the same rows (`project`, `instance`, `interface`, `status`, `master`, `workers`, `uptime` in seconds, `address`, `tap`), for scripts and agents.

Nothing running prints `No running instance found.` — plus, when state files exist that this user cannot verify, a tip naming the service account that started them.

### `project start`

Boots a project by its path:

```bash
# Run a subproject by its path
php bootgly project Demo/HTTP_Server_CLI start

# Run in interactive mode
php bootgly project Demo/HTTP_Server_CLI start -i

# Run in monitor mode
php bootgly project Demo/HTTP_Server_CLI start -m
```

You can reverse the order of the arguments (subcommand first):

```bash
php bootgly project start Demo/HTTP_Server_CLI
php bootgly project stop Demo/HTTP_Server_CLI
```

Available options:

| Option | Description |
|--------|-------------|
| `-d` | Run in daemon mode (default) |
| `-i` | Run in interactive mode |
| `-m` | Run in monitor mode |

#### Multiple instances

A server project can run **multiple instances at once** — one per port. The bound port is the instance qualifier, so start extra instances by overriding the `PORT` environment variable:

```bash
php bootgly project start Blog             # instance on the project's default port (8080)
PORT=8081 php bootgly project start Blog   # second instance on 8081
```

Starting a second instance on a port that is already in use by the same setup fails with a clean error — the server takes a non-blocking lock on the port-qualified state files before booting workers.

### `project stop`

Stops a running project by sending SIGTERM to the master process. If the process does not terminate within 5 seconds, it sends SIGKILL:

```bash :toolbar="true";
php bootgly project Demo/HTTP_Server_CLI stop
```

This stops **all running instances** of the project. To stop a single instance, pass its qualifier — the bound port for servers (or the master PID for TUI projects):

```bash :toolbar="true";
php bootgly project stop Blog 8081   # stops only the instance on port 8081
```

### `project show`

Shows the current status of a running project — one status card per instance — including PID, workers, address and uptime:

```bash :toolbar="true";
php bootgly project Demo/HTTP_Server_CLI show
```

Example output:

```
┌─ Project Status ────────────────────┐
│ Project        Demo/HTTP_Server_CLI │
│ Type           WPI                  │
│ Status         running              │
│ Master PID     12345                │
│ Workers        11/11                │
│ Address        0.0.0.0:8082         │
│ Uptime         2h 15m 30s           │
└─────────────────────────────────────┘
```

### `project logs`

Reads a project's persisted log backlog and, with `-f`, follows it **live** — in any server mode,
Daemon included. Addressed by name, never by port; `--instance` narrows to one instance — on the
backlog by the records' `instance` field, and live by picking which tap to follow (with several
live and no `--instance`, `-f` lists them and refuses). See the
**[Logs CLI guide](/guide/logs/overview/)** for the full flow and filters:

```bash :toolbar="true";
php bootgly project Demo/HTTP_Server_CLI logs -f
php bootgly project Demo/HTTP_Server_CLI logs --since=15m --level=warning --json
```

### `project schedule`

Runs a project's cron-style jobs (its `schedule.php`) — the command **mounts** the project
environment (configs, catalogs, autoloader, log provenance) without running its boot entry,
so a WPI project's server never starts. The worker registers a PID-qualified instance, so
`show`/`stop`/`logs` address it. See the **[Scheduler guide](/guide/scheduler/overview/)**:

```bash :toolbar="true";
php bootgly project App schedule run    # minute-aligned worker loop (SIGTERM stops it)
php bootgly project App schedule list   # registered jobs and their next run
```

### Process state (PID files)

When a project starts, it saves its process state (master PID, worker PIDs, type, etc.) in a JSON file under `storage/pids/`. The file is named after the project's canonical path, with `/` encoded as `~` so nested leaves never collide, plus an **instance qualifier**: the bound port for servers, the process PID for TUI projects and WPI clients. Running `Demo/HTTP_Server_CLI` on port 8082 creates `storage/pids/Demo~HTTP_Server_CLI.8082.json`. A **console-only project** started with `project start` also registers an instance, qualified by its master PID — so `show`, `stop` and `logs` can address it. Server instances additionally publish a `.logs.sock` sibling: the live-log tap socket that `logs -f` attaches to. Server and console instances also stamp that qualifier on every record they write — the `instance` field that `logs --instance` filters by; client records carry none.

Because clients qualify by PID, any number of client processes of the same project can run at once — including forked load generators, where every forked child constructs its own client instance.

The `project stop`, `project show`, `project reload` and `project restart` commands automatically discover all instances for a given project path (legacy unqualified `<project>.json` files are still recognized).

### `project reload`

Sends a hot-reload signal (SIGUSR2) to all running instances of a project, allowing them to reload code without a full restart — or to a single instance when a port is given:

```bash
php bootgly project Demo/HTTP_Server_CLI reload
php bootgly project reload Blog 8081   # reloads only the instance on port 8081
```

### `project restart`

Stops and then starts a project again, preserving the instance's port. With a single running instance the port is derived automatically; with multiple instances, pass the port of the one to restart:

```bash
php bootgly project Demo/HTTP_Server_CLI restart
php bootgly project restart Blog 8081   # restarts only the instance on port 8081
```

### `project startup`

Installs the OS service that boots the project at startup — the `pm2 startup` of one project. systemd only, for now: on a machine booted by anything else (OpenRC, runit, a container whose PID 1 is the application itself, macOS) the command names the platform, prints the command a hand-written service must run, and stops.

```bash
php bootgly project Demo/HTTP_Server_CLI startup
```

Run as the account that owns the kit, the command stages the unit under `storage/systemd/` (a directory only that account can write) and prints the exact `sudo` commands that install, enable and start it — root only ever installs a file it can read, never runs the kit. Run as root (`sudo php bootgly … startup --now`, fine on a kit root owns), it installs under `/etc/systemd/system`, reloads systemd and, with `--now`, enables and starts right away, refusing to call it started unless the unit is active a moment later. An instance you started by hand holds the port and the state record the unit would claim, so `--now` refuses until you stop it.

The unit runs `php bootgly project <Name> start -f` — foreground, so systemd holds the process and the journal keeps its output — from the kit directory, as `--user` (the invoking account by default), restarting on failure. A WPI project gets the server unit, `bootgly-<Name>.service` (`/` in the path becomes `-`, case is kept, any other character a name cannot carry — a `-` included — is hex-encoded as `:XX`); a project carrying a `schedule.php` gets a second unit for its worker, `bootgly-<Name>.schedule.service`. A project with a database (`configs/database/`) is ordered after `postgresql`, `mysql`, `mysqld` and `mariadb` when those services exist. Every unit is stamped with the project and the kit it belongs to (`X-Bootgly-Project`, `X-Bootgly-Kit`), and `startup`, `unstartup` and `status` refuse to touch a unit stamped by another project or another kit on the same machine. The start-rate limits in the unit are read by systemd 230 and newer; an older manager keeps its own defaults. A project file of your own must map `-f` to `Modes::Foreground` as the shipped ones do — the command warns when it cannot see that mapping.

- `--now` — enables the unit and starts it right away (`systemctl enable --now`). Without it the unit is installed and systemd reloaded, and the command prints how to enable it;
- `--user=<name>` — the account the service runs as. Ports below 1024 and Auto-TLS need `--user=root`: the server then demotes itself to the `user`/`group` of its own server `Configs`.

The unit it writes:

```ini
[Unit]
Description=Bootgly project Demo/HTTP_Server_CLI
X-Bootgly-Project=Demo/HTTP_Server_CLI
X-Bootgly-Kit=/srv/bootgly
After=network-online.target postgresql.service mysql.service mysqld.service mariadb.service
Wants=network-online.target

[Service]
Type=simple
User=deploy
WorkingDirectory=/srv/bootgly
ExecStart=/usr/bin/php /srv/bootgly/bootgly project Demo/HTTP_Server_CLI start -f
ExecReload=/bin/kill -USR2 $MAINPID
Restart=on-failure
RestartSec=5
KillMode=mixed
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target
```

The start-rate lines follow `Wants=` in the real unit (`StartLimitIntervalSec=300`, `StartLimitBurst=10`): a service that keeps dying stops being retried after ten starts in five minutes, and `systemctl reset-failed` arms it again.

A service starts with none of your shell's variables. When `startup` itself booted with the storage directory moved by the `BOOTGLY_STORAGE_DIR` environment variable, the unit carries it — `Environment="BOOTGLY_STORAGE_DIR=/data/storage"`, right before `ExecStart=` — so the service keeps its state where the commands you run by hand look for it. Run `startup` again after changing the value: the unit keeps the one it was written with. The staging folder follows the storage directory — `<BOOTGLY_STORAGE_DIR>/systemd/` when it is moved — and the paths the command prints are always absolute. Run `startup` as the account the service runs as and install with the `sudo` commands it prints: `sudo` drops the variable, so `sudo php bootgly … startup` writes a unit without it, and a root boot given the variable refuses a storage directory that belongs to another account. The staging folder must be that account's own, so on a storage directory root owns `startup` cannot create it and refuses to stage: create it for the account first (`sudo install -d -m 0700 -o deploy /data/storage/systemd`) or, on a kit root owns, name the variable on the command — `sudo env BOOTGLY_STORAGE_DIR=/data/storage php bootgly project <Name> startup` — and root installs the unit itself.

### `project unstartup`

Removes what `startup` installed: the units are disabled and stopped, their files deleted, systemd reloaded. Root only — anyone else gets the commands:

```bash
sudo php bootgly project Demo/HTTP_Server_CLI unstartup
```

The unit outlives the project on purpose: a project that was removed from the registry, or whose directory is gone, is still managed by its path, so nothing is left booting a project that no longer exists. A unit at that path that `startup` did not write — one stamped for another project or kit, one without a stamp, or a masked one (a link to `/dev/null`) — is named and left alone.

### `project status`

Shows the OS service of the project as systemd sees it — the unit, its file, whether it is enabled at boot and whether it is active now. The running instances themselves are `show`'s:

```bash
php bootgly project Demo/HTTP_Server_CLI status
```

### `project info`

Displays detailed metadata about a project in a Fieldset — read from its signature without running it (the same literal, `(dynamic)` and visible-escape rules as `projects list`; an invalid signature adds a `Signature` row with the reason), with the interfaces the registry binds:

```bash :toolbar="true";
php bootgly project Demo/HTTP_Server_CLI info
```

Example output:

```
┌─ Project Info ──────────────────────────────────────────────────────┐
│ Name           Demo HTTP Server CLI                                │
│ Folder         Demo/HTTP_Server_CLI                                │
│ Description    Demonstration project for Bootgly HTTP Server CLI   │
│ Version        1.0.0                                               │
│ Author         Bootgly                                             │
│ Interfaces     WPI                                                 │
│ Path           /path/to/projects/Demo/HTTP_Server_CLI             │
└─────────────────────────────────────────────────────────────────────┘
```

### `project migrate`

Applies, reverts and inspects a project's database migrations — the files in its
`database/migrations/` — on the database its `database` config scope declares. Without an
action it shows the status. The **[Database migrations](/guide/database-migrations/overview/)**
guide walks the workflow, and **[Migrations](/manual/ADI/Databases/SQL/Schema/Migrations/overview/)**
explains the files and the runner:

```bash
php bootgly project App migrate                               # status — the default action
php bootgly project App migrate create "Create Users Table"   # write a new migration file
php bootgly project App migrate up                            # apply every pending migration
php bootgly project App migrate up 2                          # apply at most 2
php bootgly project App migrate down 1                        # revert the last applied one
php bootgly project App migrate sync                          # reconcile the history (asks first)
```

Every action but `create` loads the project file — without booting it — and opens the database
from `configs/database/database.Config.php` (see
**[Configure the database](/guide/database-dbal/overview/#configure-the-database)**). Without
that scope the command stops with `Project has no configs directory: <name>` or
`Project has no database config scope: <name>`. The files live in the project, the locks in the
kit's storage:

```
projects/App/
├── App.Project.php
├── configs/database/database.Config.php   ← migrate, seed run
└── database/
    ├── migrations/                        ← migrate
    └── seeders/                           ← seed
storage/locks/
├── migrations/App.lock                    ← migrate up, down, sync
└── seeders/App.lock                       ← seed run
```

A nested project's lock takes its path with each `/` written as `~` (`App~API.lock`). The
actions:

- `status` (default) — counts the migrations `Applied`, `Local only` (pending) and `DB only`
  (recorded in the history, file gone), and names the `Next` pending file and the first DB-only
  one to `Remove`. Currently it creates the `_bootgly_migrations` history table when it is
  missing, outside the lock: it needs a database user allowed to create tables, and on a fresh
  PostgreSQL database it must not overlap a `migrate up`;
- `up [N]` — applies the pending migrations in filename order, as one new batch; with `N`, at
  most `N` of them. Prints `Migrations applied: <count>`. Currently `N` is cut to a whole number
  (`2.5` applies two), and a value that is not a number (`2x`) or is below 1 (`0`, `0.5`, or a
  negative one, which the CLI reads as an option) applies every pending migration;
- `down <N>` — reverts the last `N` applied migrations, newest first, and prints
  `Migrations reverted: <count>`. The count is required and cut the same way (`1.9` reverts one):
  without a number — none, `2x`, or a negative one, read as an option — the command stops with
  `Migration down requires a numeric step count.`, and below 1 (`0`, `0.5`) with
  `Migration down requires a positive step count.`;
- `sync` — makes the history match the files without running any migration: it deletes the
  rows whose file is gone and records every pending file as applied. It first prints a
  `Migration Sync Check` (`Add`, `Delete`, `Add first`, `Delete first`), then asks
  `Apply migration sync to _bootgly_migrations?` — the prompt currently shows its `[y/N]` hint
  twice. `y` or `yes`, in any letter case, applies it and prints `Migration Sync Applied` with the
  `Added` and `Deleted` counts; `n`, `no`, Enter or the end of the input cancel it with
  `Migration sync cancelled.`; any other answer asks again on a terminal and cancels without one.
  A script answers through its input (`echo y | php bootgly project App migrate sync`). With
  nothing to reconcile it prints `Migration history is already synchronized.` and asks nothing.
  Like `status`, the check creates a missing history table, even when you then decline;
- `create <migration>` — writes `database/migrations/<YmdHis>_<slug>.php`, the slug made from
  `<migration>`, creating the directory, and prints its path. It needs no database. Without a
  name the command prints its help and fails.

The command's own `--help` does not mention the `up` limit or the default action yet.

`up`, `down` and `sync` take the lock file plus an advisory lock on PostgreSQL and MySQL, and a
second run fails at once instead of waiting (see
**[Locking](/manual/ADI/Databases/SQL/Schema/Migrations/overview/#locking)**). A runner error —
a failing statement, a lock already held — or an unknown action
(`Invalid migration action: <action>`) prints its message and exits with status 1. What fails
outside the runner is not caught: an invalid database config, or a `create` that cannot write its
file, prints the uncaught exception and exits with status 255.

### `project seed`

Runs a project's seeders — the files in its `database/seeders/` — on the database its `database`
config scope declares. Without an action it lists them. The
**[Database seeders](/guide/database-seeders/overview/)** guide walks the workflow, and
**[Seeders](/manual/ADI/Databases/SQL/Seed/overview/)** explains the files and the runner:

```bash
php bootgly project App seed                       # list — the default action
php bootgly project App seed create "Demo Users"   # write database/seeders/demo_users.php
php bootgly project App seed run                   # run every seeder, in filename order
php bootgly project App seed run demo_users        # run one
php bootgly project App seed run --dry-run         # print the SQL instead of running it
```

`list` and `create` work on the files alone. `run`, with or without `--dry-run`, needs the same
`configs/database/` scope as `migrate`, and stops with the same two messages without it. The
actions and the option:

- `list` (default) — a `Seeder List` with the `Count` and one `Seeder` row per file;
- `run [seeder]` — runs every seeder in filename order, or the one named, and prints
  `Seeders run: <count>`. On PostgreSQL and SQLite the queries each seeder returns run in a
  transaction of their own; the first seeder that fails stops the run. An unknown name stops with
  `Seeder file not found: <seeder>.`;
- `--dry-run` — with `run`, prints a `Seeder Dry Run` with the SQL and the parameters each seeder
  would send, then `Dry run only; no seeder SQL was executed.` It takes no lock, but it still
  calls the seeders, so a statement a seeder executes by itself still runs;
- `create <seeder>` — writes `database/seeders/<slug>.php`, the slug made from `<seeder>`,
  creating the directory, and prints its path; a slug already taken stops with
  `Seeder already exists: <slug>.` Without a name the command prints its help and fails.

The command's own `--help` does not mention the default action yet.

A real run takes `storage/locks/seeders/<name>.lock` plus an advisory lock on PostgreSQL and
MySQL, and fails at once — `Seeder lock is already active.` or
`Seeder advisory lock is already active.` — when another run holds either (see
**[Locking](/manual/ADI/Databases/SQL/Schema/Migrations/overview/#locking)**). Any error prints
its message and exits with status 1; an unknown action prints `Invalid seeder action: <action>`.

## Project lifecycle

The typical lifecycle of a project follows this flow:

```mermaid
graph TB
  Create["Create project directory\nwith leaf-named boot file"] --> Register["Register the path in\nBootgly.projects.php"]
  Register --> Start["Start project"]
  Start --> Show["Monitor status"]
  Show --> Reload["Hot-reload changes"]
  Reload --> Show
  Show --> Restart["Restart if needed"]
  Restart --> Show
  Show --> Stop["Stop project"]
```

1. **Create** a directory in `projects/` (at any depth) with a `{leaf}.Project.php` boot file;
2. **Register** its path in `Bootgly.projects.php` under the right interface(s);
3. **Run** it with `project start`;
4. **Monitor** its status with `project show`;
5. **Reload** code changes with `project reload` (sends SIGUSR2);
6. **Restart** completely if needed with `project restart`;
7. **Stop** it with `project stop`.

## Built-in projects

Bootgly ships with example projects under `projects/`:

| Project | Interface | Description |
|---------|-----------|-------------|
| `Demo/CLI` | CLI | Interactive CLI demo for terminal components |
| `Demo/HTTP_Server_CLI` | WPI | HTTP server demo with routing, ORM and observability routes |
| `Demo/HTTPS_Server_CLI` | WPI | HTTPS server demo |
| `Demo/TCP_Server_CLI` | WPI | Raw TCP server with configurable workers |
| `Demo/Queue-HTTP_Server_CLI` | WPI | HTTP server that enqueues background jobs |
| `Benchmark/HTTP_Server_CLI` | WPI | HTTP server benchmark (simple/techempower/bootgly routers) |
| `Benchmark/TCP_Server_CLI` | WPI | Raw TCP server benchmark (HTTP or echo) |
| `Benchmark/UDP_Server_CLI` | WPI | Raw UDP echo server benchmark |
