The app pattern

An app is one feature: the page people use, the backend work behind it, and sometimes an admin settings page. This page starts with that simple picture, then uses helloworld as the complete technical example.

1. The parts of an app

Think of an app as one feature package. Give it one name, then build only the parts that feature needs.

  • One shared name: the same app name identifies its folders, configuration and PHP classes.
  • Frontend: the pages, buttons and forms people see in the main app.
  • Backend: the API actions, business rules and database work behind those pages.
  • Admin settings, when needed: pages used by an administrator to configure the feature.
  • Registration: installing or reinitialising tells the framework to create tables and apply permissions.
  • Tests and documentation: keep the feature verifiable and understandable for the next developer.
Show the complete file checklist

Use this reference while creating or reviewing an app. All placeholders use the same app name.

  • One name everywhere: the outer folder dev/{name}/, the inner folders, the manifest's <app_name> and the class prefixes ({name}Controller, {name}DAO, {name}.class.php) are the exact same string.
  • Backend api/apps/{name}/
    • {name}.xml: the manifest. <info> (app_name, app_type, versions), <app_permissions> (apps it may call), <user_permissions> (one <permission> per action, view included), optional <roles>, <admin_panel_permissions>, <user_notifications>, <storage>, <prerequisites>. Copy api/apps/helloworld/helloworld.xml.
    • {name}Controller.class.php extends Controller: authenticate() returns auth::appUserPermission(action, controller, publicEndpoints); Render() switches on the action (or on GET/POST first) and answers with Response::create().
    • {name}.class.php extends App: register(), init(), search(), optional boot(); the framework calls register() and boot() on every request.
    • {name}DAO.class.php: the SQL, as static methods that create new database(); never extend database. {name}Model.class.php: the entity.
    • migrations/: every table change, made with php api/migrate.php make {name} <change>; table names through $this->tableName() so they carry the app prefix.
  • Frontend apps/{name}/
    • app-config.json: status, resources (the app's scripts and styles, bundled by the framework), menus (icon and path_name), optional widgets.
    • route.js: Router.addRoute() with meta.requiresAuth and meta.permissions ({ name: "{name}", action: "view" }), then Router.replace(Router.currentRoute.value.fullPath).
    • services.js: every API call, fetch(XP.getApiUrl() + "/{name}/<action>").
    • components/{name}.js: the page, a Vue component exported as default and built only from the UI kit (docs/ui-guide.md); apps/{name}/components/widgets/ for dashboard widgets; assets/ for the app's CSS and JS.
  • Admin panel api/admin/apps/{name}/ (when the app has settings): the same shape, app-config.json, route.js, service.js, components/{name}-settings.js, under <admin_panel_permissions>.
  • Register it: the framework boots every api/apps/{name}/{name}.xml with <app_register active="true"/> (in development, linked from dev/{name}/). Install or reinitialise it so its tables are built and its permissions granted: installing grants the manifest's permissions to the admin role; reinitialising applies roles and migrations.
  • Tests and docs: dev/{name}/tests/ run by ./app-test {name}; a CLAUDE.md in the app's repo; dev/{name}/docs/architecture.html from the template.

Where to look

  • README "Creating a New App", "App Directory Layout" and "App XML Manifest".
  • CLAUDE.md: the naming rule and the UI rules. dev/README.md: the workspace.

2. Where the code lives

During development all of an app's code lives in one folder, dev/{name}/, which is its own git repo. The framework loads it from three places, which in development mode are links back into that folder.

The links are created on every page load when api/config.xml has <system_environment>development</system_environment>. Never create them by hand, and never edit through the framework locations.

3. Inside an app

Where to look

  • api/apps/helloworld/ and apps/helloworld/: the smallest complete example.
  • The URL names the controller, which is usually the app's name but not always: xp_users answers at /api/user/….

4. The app's classes

Two classes plug into the framework (App and Controller); the rest is the app's own. helloworld keeps its one action's logic in HelloTest.

Where to look

  • api/apps/helloworld/helloworld.class.php, helloworldController.class.php, HelloTest.php, helloworldDAO.class.php, helloworldModel.class.php, api/apps/helloworld/migrations/20261007134403_baseline.php.
  • The core side: Core classes.

5. A request inside the app

From the menu entry to the JSON answer. The route's meta.permissions guards the page in the SPA; authenticate() guards the action on the server.

Where to look

  • apps/helloworld/route.js, apps/helloworld/services.js, apps/helloworld/components/helloworld.js.
  • api/apps/helloworld/helloworldController.class.php: authenticate() and the get_hello_data case in Render().
  • The framework side of the same request: Step by step.

6. The app's tables

Declared in a migration, named through $this->tableName() so they get the app prefix: tableName('helloworld') is the table helloworld_helloworld, tableName('helloworld_meta') is helloworld_helloworld_meta.

Where to look

  • api/apps/helloworld/migrations/20261007134403_baseline.php: up() creates both tables, down() drops them.
  • README "Database Migrations" and "Table prefix".

7. The app's use cases

One use case per manifest permission: the actions users may be granted in the main app, and the admin-panel actions.

Where to look

  • api/apps/helloworld/helloworld.xml: <user_permissions> (view, get_hello_data) and <admin_panel_permissions>.
  • api/admin/apps/helloworld/: the settings page.