Build your first Marwa Framework application in under 5 minutes.
Prerequisites: Complete Installation first
If you prefer to start from a ready-made app skeleton, use memran/marwa-php. This tutorial is for developers who want to wire the framework package into an application manually.
A simple web application with:
Open public/index.php and add:
<?php
use Marwa\Framework\Application;
use Marwa\Framework\HttpKernel;
use Marwa\Framework\Adapters\HttpRequestFactory;
require __DIR__ . '/../vendor/autoload.php';
$app = new Application(__DIR__ . '/..');
$app->boot();
$kernel = $app->make(HttpKernel::class);
$request = $app->make(HttpRequestFactory::class)->request();
$response = $kernel->handle($request);
$kernel->terminate($response);
Open routes/web.php and add:
use Marwa\Framework\Facades\Router;
use Marwa\Router\Response;
// Health check endpoint
Router::get('/health', fn () => Response::json([
'status' => 'ok',
'timestamp' => time()
]))->register();
// Welcome page
Router::get('/', fn () => Response::html('
<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h1>Welcome to Marwa Framework</h1>
<p>Your first application is running!</p>
</body>
</html>
'))->register();
php -S localhost:8000 -t public
Visit http://localhost:8000/health:
{"status":"ok","timestamp":1712684400}
Visit http://localhost:8000/:
<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h1>Welcome to Marwa Framework</h1>
<p>Your first application is running!</p>
</body>
</html>
sequenceDiagram
participant User
participant Browser
participant Index
participant Router
participant Controller
User->>Browser: Visit URL
Browser->>Index: HTTP Request
Index->>Index: Create App
Index->>Index: Boot App
Index->>Router: Route Request
Router->>Controller: Match Route
Controller->>Browser: HTTP Response
Browser->>User: Show Page
flowchart TD
A[HTTP Request] --> B[Index.php]
B --> C[Application Created]
C --> D[App Bootstrapped]
D --> E[HttpKernel Handles]
E --> F[Middleware Pipeline]
F --> G[Router Matches Route]
G --> H[Controller/Handler]
H --> I[Response]
I --> J[Terminate]
J --> K[Send to Client]
F -.->|Auth| L[Security Middleware]
F -.->|Session| M[Session Middleware]
Run the test suite:
composer test
You should see:
OK (99 tests, 569 assertions)
Run static analysis:
composer stan
You should see:
[OK] No errors
You now have a working application. Explore these guides:
| Topic | Description |
|---|---|
| Controllers | Handle HTTP requests |
| Validation | Validate user input |
| View | Use Twig templates |
| Models | Work with databases |
| Database | DB management commands |
| Console | CLI commands |
Run:
composer dump-autoload
If using SQLite, create the database:
touch database/app.sqlite
Use a different port:
php -S localhost:8080 -t public