Framework overview

Application Flow

Follow a browser request to /products/42 from the product page example. Atom first prepares the application, then uses that setup to dispatch the request and render the page.

Enter through the front controller

Atom Starter's public/index.php loads Composer's autoloader and runs the application. run() calls handle() to obtain a response, then sends it to the browser. In a test, you can call handle($request) to inspect the response directly.

public/index.php
<?php

declare(strict_types=1);

require dirname(__DIR__) . "/vendor/autoload.php";

(new App\Application())->run();

Initialize the application

The first call to handle() initializes the application instance. Each step gives the next one something it needs:

  1. Resolve paths and load settings. Atom sets up aliases such as @root and @app, loads the environment files, and builds the configuration. A catalogue filename can come from these settings before any catalogue service is created.
  2. Register services and build the injector. Atom gathers framework and application bindings. The catalogue provider binds ProductService to SampleProductService, giving the injector a concrete class to supply to ProductPage.
  3. Set up the router and register features. Atom prepares the router, registers jobs and schedules, loads modules, and registers component tags and middleware. The application's pages() hook points to @app/Pages. Atom discovers ProductPage there and registers the route declared by #[PageRoute("/products/{id}")].
  4. Run startup code. Atom runs provider bootstrappers, then the application's bootstrap() hook. Use that hook for setup that needs the injector or router already in place, such as attaching an API controller.

Match the request and render the page

  1. Dispatch the request. Atom creates a request scope and dispatches through its middleware pipeline. The router matches GET /products/42 to the registered page route and captures id as 42.
  2. Create the page and load its data. The injector creates ProductPage with its ProductService. Atom then calls get(string $id) with the route value. The handler loads the product and assigns it to the page's $product property.
  3. Render and send the response. Since get() returns void, Atom renders ProductPage.atom.html with the page instance available as $this. The template renders the product name and availability, and the shared layout places that HTML inside <main>. The front controller sends the resulting response.

For the route declaration and parameter binding in code, see Page routing. For the startup hooks and their responsibilities, see Application structure.

Repository Layout

If you are reading the framework source checkout, these are the starting points:

Location What you will find
packages/framework/ The Atom runtime, including the application, router, injector, and template renderer.
packages/starter/ The starter application and its public/index.php entry point.
apps/sample/ A sample application that uses the framework from the same checkout.
docs/ Framework source documentation.

Getting started shows how to run the starter from that checkout or from the standalone distribution.