waffle-commons / skeleton
The official skeleton for Waffle Framework applications.
Requires
- php: ^8.5
- ext-yaml: *
- ext-zend-opcache: *
- waffle-commons/cache: 0.1.0-beta2.1
- waffle-commons/config: 0.1.0-beta2.1
- waffle-commons/console: 0.1.0-beta2.1
- waffle-commons/container: 0.1.0-beta2.1
- waffle-commons/contracts: 0.1.0-beta2.1
- waffle-commons/error-handler: 0.1.0-beta2.1
- waffle-commons/event-dispatcher: 0.1.0-beta2.1
- waffle-commons/http: 0.1.0-beta2.1
- waffle-commons/http-client: 0.1.0-beta2.1
- waffle-commons/log: 0.1.0-beta2.1
- waffle-commons/pipeline: 0.1.0-beta2.1
- waffle-commons/routing: 0.1.0-beta2.1
- waffle-commons/runtime: 0.1.0-beta2.1
- waffle-commons/security: 0.1.0-beta2.1
- waffle-commons/utils: 0.1.0-beta2.1
- waffle-commons/waffle: 0.1.0-beta2.1
Requires (Dev)
- carthage-software/mago: ^1.29
- cyclonedx/cyclonedx-php-composer: ^6.2
- php-mock/php-mock-phpunit: ^2.15
- phpunit/phpunit: ^12.5
- vimeo/psalm: ^6.16
This package is auto-updated.
Last update: 2026-05-30 19:46:49 UTC
README
๐ฆ Waffle Skeleton
The official starting point for building robust, secure, and high-performance applications with the Waffle Ecosystem.
Welcome to the Waffle Skeleton, the official starting point for building robust, secure, and high-performance applications with the Waffle Ecosystem.
This skeleton is not just a folder structure; it is a Production-Grade Boilerplate pre-configured with:
-
FrankenPHP (Caddy): Modern application server with native HTTP/3 and Early Hints support.
-
Docker Multi-Stage: Optimized images for Development (with Xdebug) and Production (Immutable, <100MB).
-
Zero-Config Security: Automatic secret generation and hardened defaults.
-
Strict Standards: PHP 8.5+, Typed Properties, and Read-Only classes.
๐ Installation
Prerequisites
-
Docker & Docker Compose (Required)
-
PHP 8.5+ & Composer (Optional, for local commands)
Create a New Project
Use Composer to create your project. This will automatically trigger the setup scripts to generate secure keys and initialize the directory structure.
composer create-project waffle-commons/skeleton my-app
cd my-app
Note: If you don't have PHP installed locally, you can use the Docker setup immediately after cloning the repository manually.
๐ณ Docker Environment
Waffle is Cloud-Native by design. We provide two distinct environments managed via a single Dockerfile.
1. Development Mode (dev)
Optimized for Developer Experience (DX).
-
Hot Reload: Code is mounted via volumes. Changes are reflected instantly.
-
Debugging: Xdebug is installed and configured.
-
Tooling: Composer is available inside the container.
Start the Dev Server:
docker compose up --build -d
Your application is now available at: ๐ https://localhost (Accept the self-signed certificate auto-generated by Caddy).
2. Production Mode (prod)
Optimized for Performance and Security.
-
Immutable: No source code volumes. The code is baked into the image.
-
Fast: Opcache validation is disabled, Preloading is enabled.
-
Secure: Dev tools (Composer, Xdebug) are removed. Rootless execution.
Test the Production Build locally:
docker compose -f docker-compose.prod.yml up --build -d
๐ Directory Structure
A Waffle application follows a strict but simple structure:
.
โโโ config/ # โ๏ธ Configuration
โ โโโ app.yaml # Main Waffle Configuration
โ โโโ preload.php # Opcache Preloading Script
โโโ docker/ # ๐ณ Infrastructure as Code (Dockerfile, Caddyfile, PHP config)
โโโ public/ # ๐ Web Entry Point (index.php)
โโโ scripts/ # ๐ ๏ธ Composer Lifecycle Scripts
โโโ src/ # ๐ง Your Application Logic (Namespace: App\)
โ โโโ Controller/ # HTTP Entry points
โ โโโ Factory/ # Application Factory
โ โ โโโ AppKernelFactory.php # The Kernel Factory (Dependencies)
โ โโโ Service/ # Business Logic
โ โโโ Kernel.php # The Application Core (Configuration & Boot)
โโโ tests/ # ๐งช PHPUnit Test Suite
โโโ var/ # ๐ฆ Temporary files (Cache, Logs, Exports, etc) - Ignored by Git
๐ ๏ธ Configuration
Environment Variables (.env)
Waffle ships a native DotEnv parser (no third-party dependency). When you run create-project, a .env file is automatically created from .env.example with a generated APP_SECRET.
| Variable | Description |
|---|---|
APP_ENV |
dev (debug enabled) or prod (optimized). |
APP_DEBUG |
true displays detailed stack traces. false renders JSON errors. |
APP_SECRET |
32-byte Hex string used for cryptographic operations. |
WAFFLE_CSRF_SECRET |
32+ byte signing secret for stateless HMAC CSRF tokens (Beta-1 / SEC-01). Bound at boot by AppKernelFactory::resolveCsrfSecret(). In prod, a missing or short value aborts boot; non-prod falls back to a per-process random secret. |
SERVER_NAME |
The domain name used by Caddy (e.g., example.com or localhost). |
โ Precedence: OS env wins over
.env.AppKernelFactorymerges your.envwith the live process environment (Dockerenvironment:, Kubernetesenv:, shell exports, etc.) viaarray_merge((new DotEnv($root))->load(), getenv()). Becausearray_mergeis rightmost-wins on string keys, the OS value beats.envon collision. If you edit.envand the change doesn't take effect, check whether the same variable is exported by your shell ordocker-compose.ymlโ that export will silently override.env. This matches the Twelve-Factor convention. Seedocumentation/how-to/configuration.mdfor the merge rules and the type-normalization foot-gun aroundAPP_DEBUG/DEBUG.
Framework Config (config/app.yaml)
Waffle uses native YAML parsing (via PECL extension) for blazing-fast configuration loading.
# Main application configuration for the Waffle Framework waffle: # App environment (dev, prod, test). Set via server environment variable. env: '%env(APP_ENV)%' # Debug mode. Set to false in production for security. debug: '%env(APP_DEBUG)%' security: level: 10 csrf: # Beta-1 / SEC-01: signing secret for the stateless HMAC CSRF subsystem. # Resolved via getenv(WAFFLE_CSRF_SECRET). Production refuses to boot # without a 32+ byte value. secret: '%env(WAFFLE_CSRF_SECRET)%' paths: controllers: 'src/Controller' services: 'src/Service'
Beta-1 security defaults
The skeleton ships the canonical Beta-1 middleware pipeline out of the box:
ErrorHandler โ TrustedHost โ AnonymousSession โ Routing โ Csrf โ Security โ SecureHeaders โ Dispatcher
This means every controller action you write is, by default, subject to:
- Fail-closed ABAC โ an action without
#[Voter]returns HTTP403. Tag explicitly public actions with#[\Waffle\Commons\Contracts\Security\Attribute\PublicAccess]. - Stateless HMAC CSRF on mutating routes โ opt actions in with
#[RequiresCsrfToken]. Tokens are HMAC-bound to the per-browserWAFFLE_SIDcookie issued byAnonymousSessionMiddleware.
See the framework docs at waffle-commons/documentation for the full design rationale.
๐ฉโ๐ป Usage Example
1. Create a Service
Create src/Service/Greeter.php:
<?php namespace App\Service; readonly class Greeter { public function sayHello(string $name): string { return "Welcome to Waffle, {$name}!"; } }
2. Create a Controller
Create src/Controller/HelloController.php. Waffle uses Attributes for routing.
<?php namespace App\Controller; use App\Service\Greeter; use Psr\Http\Message\ResponseInterface; use Waffle\Commons\Routing\Attribute\Argument; use Waffle\Commons\Routing\Attribute\Route; use Waffle\Core\BaseController; class HelloController extends BaseController { // Services are automatically injected (Autowiring) public function __construct( private Greeter $greeter ) {} #[Route(path: '/greet/{name}', method: 'GET')] public function index(string $name): ResponseInterface { $message = $this->greeter->sayHello($name); return $this->jsonResponse(data: [ 'message' => $message, 'status' => 'success' ]); } }
Go to https://localhost/greet/Developer. You should see your JSON response!
๐งช Running Tests
The skeleton comes with PHPUnit pre-configured.
# Run tests inside the Docker container
vendor/bin/phpunit
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
๐ License
This project is licensed under the MIT License - see the LICENSE.md file for details.
