Create a project with one command, understand every file it writes, run it, add a page and its test.
- **You will have:** `acme.portal`, an application that runs in your browser, has two pages, passes its tests and is
ready to be deployed by mmo.admin.
- **You need:** the hub installed (a clone of MMOFramework with its `libs/`), PHP 8.3 or later.
## 1. Create the project
A project is a folder of its own, outside the hub. From the hub's folder:
```bash
php tools/mmo.php project ../acme.portal --description="The Acme customer portal"
```
Everything else follows from the folder's name: the package name `acme.portal`, the namespace `AcmePortal`, the
title `Acme Portal`. Pass `--name`, `--namespace` or `--title` to choose them yourself, and `--dry-run` to see the
files without writing them.
The command writes the application, its deployment files, a `libs` link to the hub's libraries, and runs
`git init`. It commits nothing.
> Not installed yet? The [playground](https://mmoframework.fr/en/playground) generates the same files, from
> the same code, for you to browse.
## 2. What it wrote
```text
acme.portal/
mmo.json the manifest: name, version, namespace, dependencies
bootstrap.php shared by the web, the scripts and the tests: the mode, the framework, the configuration
configs/ config.json, then dev.json or prod.json, then local.json (this machine's, never committed)
src/ the project's package: its classes, its pages, its stylesheet
www/index.php the web entry point; www/ is what a release serves
tests/ its phpunit suite
deploy.json where and how mmo.admin deploys it
AGENTS.md its rules, for AI agents (CLAUDE.md and .mcp.json point them there)
libs -> the hub's libs/
```
Three files decide how everything else behaves.
**The manifest.** There is no composer: the project's dependencies are libraries of the framework, at a major
version.
```json from=mmo.json
"sources": ["src"],
"dependencies": {
"mmo.core": "21.*",
"mmo.client": "4.*"
},
"bootstrap": "src/bootstrap.php",
```
**The root bootstrap.** It chooses the mode from the tree, not from the host name. A release never contains
`src/` -- it runs from `.phar` packages -- so a folder with `src/` is a developer's checkout:
```php from=bootstrap.php
if (!defined('MMO_MODE')) {define('MMO_MODE', is_dir(__DIR__ . '/src')? 'dev' : 'prod');}
```
Then it loads the framework (the libraries' sources in dev, their packages in prod) and the configuration, in this
order: `config.json`, then the mode's file.
**The package bootstrap.** Nothing autoloads. `src/bootstrap.php` requires every class file of `src/`, and
registers the namespace as a path:
```php from=src/bootstrap.php
return [
\MMO\core\Application::class => [
'paths' => [
__NAMESPACE__ => __DIR__,
]
]
];
```
That is what makes `{AcmePortal}` an alias of `src/` in the configuration. It also works in a release, where the
same folder is inside `packages/acme.portal.phar`:
```json from=configs/config.json
"MMO\\client\\Theme": {
"pages": ["{AcmePortal}/pages"],
```
Every configuration key is the name of the class it configures. Here, `MMO\client\Theme` gets its `pages` folder.
## 3. Run it
With PHP's built-in server, from the project's folder:
```bash
cd ../acme.portal
php -S localhost:8000 -t www www/index.php
```
Open <http://localhost:8000/>: the home page says `acme.portal 1.0.0, in dev mode`. Apache works the same once it
serves the folder (the root `.htaccess` sends every request to `www/index.php`), at <http://localhost/acme.portal/>.
In dev mode, the page has a console drawer with the request's log, and the theme's stylesheet is compiled again
whenever you edit a `.scs` file.
## 4. Add a page
A page is a folder of `src/pages`. Its `index.json` gives its entry in the menu and names its files, and each file
is rendered from `<key>.phtml` beside it. Create `src/pages/about/index.json`:
```json from=src/pages/about/index.json
{
"label": "About",
"icon": "circle-info",
"group": "Acme Portal",
"order": 10,
"default": "about",
"files": {
"about": {
"label": "About",
"title": "About Acme",
"description": "Who we are, and how to reach us."
}
}
}
```
Then its template, `src/pages/about/about.phtml`:
```php from=src/pages/about/about.phtml
<?php
/**
* The About page: `src/pages/about/index.json` names it, this file renders it.
*/
$since = 1998;
?>
<h1>About Acme</h1>
<p>Acme has served its customers for <?= date('Y') - $since ?> years.</p>
```
Reload: the menu has an About entry, and <http://localhost:8000/about> shows the page. No route and no
configuration: the pages folder is enough.
## 5. Test it
The project came with a test suite. Its tests send requests inside the test's own process, through the same routing,
pages and templates as the web server. Add `tests/unit/TestAbout.php`:
```php from=tests/unit/TestAbout.php
class TestAbout extends TestCase {
public function testTheAboutPageAnswers(): void {
$about = $this->http('GET', 'about');
$this->assertSame(200, $about->getStatusCode());
$this->assertStringContainsString('About Acme', (string)$about->getBody());
}
}
```
Then, from the project's folder:
```bash
phpunit
```
```text
OK (5 tests, 10 assertions)
```
The four other tests came with the project. They check what usually shows up in production first: a namespace
that differs between `mmo.json` and `src/bootstrap.php`, or a page without its template.
## 6. Commit
```bash
git add -A
git commit -m "acme.portal: the project, and its About page"
```
A pre-commit hook (`scripts/git/pre-commit`) refuses an obvious credential. Your own values, such as a local database
password, go in `configs/local.json`, which git ignores.
## Common mistakes
- **`{root}/src/...` in a configuration.** It works in your checkout and fails in production, where there is no
`src/`. Always write `{AcmePortal}/...`.
- **A class nobody requires.** A new file of `src/` is `require`d by `src/bootstrap.php`, after the files it extends
or uses. The framework does not look for it.
- **Moving the project's folder.** `libs` is a link to the hub's `libs/`. If you move one of them, run the
`project` command again or fix the link yourself.
- **An `index.json` key without its `.phtml`.** The page answers 404. The project's own test finds it.
## Going further
- [Pages](https://mmoframework.fr/en/documentation/mmo.client/Pages.md): menus, groups, the theme's shell.
- [Starting a new application](https://mmoframework.fr/en/documentation/mmo.core/NewProject.md): every file
of the tree, and how to write them by hand.
- [Testing](https://mmoframework.fr/en/documentation/mmo.core/Testing.md): `TestCase` and its requests.
- Next: **Configuration**, then **Your first controller**.