How the framework works
The framework as it is in the code today: the parts, a request, the frontend start, permissions and background work. For unfamiliar symbols, use the diagram guide.
1. System overview
One install serves two single-page apps (the main app and the admin panel) through one PHP backend. Cron drives the background scheduler, and developers use the CLI entry points. All of them boot the same framework core, which hands work to apps.
Where to look
index.php,server.php,xp.js: the main app's shell and runtime.api/admin/: the admin panel (same backend, its own session cookieDCADMINSESS).api/core/Framework.php:run(),run_shell(),run_heartbeat(),run_migrate(),run_upgrade().- Permission checks live in the
authsystem app, not in the core (see section 4). api/core/classes/,api/core/Modules/: core classes and modules.
2. An API request
A call to /api/{controller}/{action} enters through
api/index.php, and Framework::run() boots: session, class
loaders, health check, SDK loaders, then every active app's register()
and boot(). dispatch() then lets UpgradeGate run
any pending upgrade steps, refuses the request in maintenance or down mode (except
for system_admin_app) or when a RequestGate check refuses
it, and otherwise builds the controller and calls authenticate() and then
Render().
Where to look
api/core/Framework.php:run()lists the boot steps;dispatch()holds the checks.api/core/classes/Controller.class.php,Request.class.php,Response.class.php.api/core/Modules/RequestGate/,api/core/Modules/SessionChannel/,api/core/Modules/Upgrader/,api/core/Modules/Loging/(the folder is spelled this way).- Status codes: health check failed
500; controller or action missing from the URL400; upgrade running or app held503; maintenance or down503; refused byRequestGate403; no such controller501; not authorised401. - The base
Controller::authenticate()only validates the session; app controllers override it withauth::appUserPermission(system_admin_apphas its own).AdminActivityrecords every dispatched request insystem_admin_app_activity_log; theaccess_logtable is written only when heartbeat tasks are added, edited or removed.
3. Frontend boot
There is no build step. On each page load the PHP shell fetches the public app options
from the API, gathers the resources that the configs list into a few bundle files and
writes the config and the tags into the page. The browser then starts the Vue app, and
index.php finishes with the theme and the service worker.
Where to look
index.php: definesXP_CONFIG_PUBLICand loads the bundles.server.php:XP_SERVER, which writes the bundles and reads the language files.xp.js: theXPruntime, Vue app, Router andmountApp().- The admin panel boots the same way from
api/admin/index.php, with its ownserver.phpandxp.js, but without the options call or the service worker.
4. Who can do what
Apps declare their permissions and roles in their manifest. Installing an app grants
its permissions to the admin role; reinitialising it (initialize_app)
writes its permissions and roles into the permission tables. Admins adjust them on
the Roles page. The first permission check in a request brings the session's copy in
step with the tables, and both the backend and the SPA check that copy.
Where to look
- README "Permissions", "Scoped grants" and "Space permissions".
api/apps/auth/:auth::appUserPermission,auth::can,auth::syncSession.api/apps/xp_users/: roles, memberships and scope resolution.api/core/Modules/PermissionSource/,RequestGate/.
5. Background work
Three kinds of work that are not part of an app's own request handling.
Heartbeat: recurring tasks
Migrations: schema changes
Upgrade steps: one-off work for a release
The first request that sees new step files runs them and waits for them; requests to
an app that is being upgraded are held with a 503.
Where to look
api/core/heartbeat/:HeartbeatFunctions,DoScheduler,DoSchedulerFunctions(runs the tasks),HeartbeatDAO.api/core/Modules/Migrator/and README "Database Migrations".api/core/Modules/Upgrader/,api/upgrades/README.mdanddocs/upgrading.md.
6. Step by step
The two flows a developer asks about most, as calls between the parts in order. How to read a sequence diagram: Diagram components.
An API request
Signing in
A password login answers with the user payload and permissions, or asks for a
two-factor code first. The not-activated and disabled checks are skipped while
auth::$SKIP_ACCOUNT_ACTIVATION_CHECK is true (its current
value). Afterwards the SPA posts validate_session on every navigation to a
route that requires auth, to keep its copy of the permissions fresh.
Where to look
api/core/Framework.php:run()anddispatch(); the status codes are listed under section 2.api/apps/auth/authController.class.php:login_user(),validate_two_fa()(thevalidate2faaction),resend_two_fa(),validate_session()(POST only).api/apps/auth/authService.class.php:authenticateUser()creates the session and rebuilds the permissions.api/apps/auth/authSession.class.php: the session and the two-factor code.apps/xp_system/assets/scripts.js: the route guard that postsvalidate_session. README "Permissions" ("Live sessions") for what it returns.