EN | ES

Application Kernel

The Application Kernel is the central nervous system of Wordless. It orchestrates the entire request lifecycle and coordinates all system components from bootstrap to response.

What Is the Application Kernel?

The kernel is a lightweight class that:

  • Initializes all services and dependencies
  • Routes incoming requests to handlers
  • Manages middleware execution
  • Coordinates error handling
  • Sends responses back to the client

How It Works

Every request follows this path through the kernel:

Request
  ↓
Application::handle()
  ↓
Middleware Stack
  ↓
Router::resolve()
  ↓
Handler (ContentController, SitemapController, etc)
  ↓
Response
  ↓
send()

Bootstrap Process

The kernel bootstraps in bootstrap/app.php:

<?php
$container = new Container();

// Register services
$container->singleton(Renderer::class, fn() => new Renderer($config['template_dir']));
$container->singleton(ContentRepositoryInterface::class, fn() =>
    new FileContentRepository($config['content_dir'])
);

// Create kernel
$app = new Application($container);
$app->handle($request);

Key Responsibilities

Service Coordination

All services (Router, Repository, Renderer) are registered with the container and injected into handlers. This ensures loose coupling and testability.

Middleware Support

The kernel executes a configurable stack of middleware before passing the request to the router. This enables features like error handling and response caching.

Error Handling

Exceptions are caught and normalized into structured error responses. In debug mode, full stack traces are displayed; in production, user-friendly error pages are shown.

Why This Pattern?

A centralized kernel provides:

  • Predictability: The request path is always the same
  • Extensibility: Middleware and hooks can intercept requests
  • Testability: The kernel can be tested in isolation
  • Control: No hidden request routing or magic behavior

← Back to Features