How mollie/demo-checkout-backend works
1. Overall shape
- This is a Laravel 8/9-style PHP backend for the Mollie Checkout demo apps.
- Its primary job is to expose API endpoints for creating and tracking payments, and to receive Mollie webhook callbacks for payment status updates.
2. Request entry points
- Public traffic enters through Laravel’s HTTP kernel and routing layer.
- routes/api.php is the main contract for mobile/API clients.
- routes/web.php likely exists for a minimal browser-facing surface such as docs or fallback pages, but the core product is the API.
3. API layer
- app/Http/Controllers/Api/MethodsController.php and PaymentsController.php are the main application endpoints.
- app/Http/Controllers/Api/Controller.php is a shared base class for API controllers.
- app/Http/Controllers/PaymentsController.php at the non-API level suggests there is also a web-facing payment entrypoint or callback handler outside the versioned API namespace.
4. Payment domain
- app/Models/Payment.php is the central persisted entity.
- app/Models/Enums/PaymentStatus.php defines the payment lifecycle state machine at the domain level.
- database/migrations/2021_07_20_104127_create_payments_table.php defines the single core table that stores payment records.
5. Validation and input boundaries
- app/Http/Requests/PaymentRequest.php isolates request validation for payment creation or update flows.
- This is the main boundary preventing malformed client input from reaching the payment workflow.
6. Response shaping
- The app/Http/Resources classes (PaymentResource, MethodResource, IssuerResource, AmountResource, PriceResource, ImageResource) indicate the API returns curated JSON representations rather than raw models.
- This is important for architecture because the external contract is deliberately decoupled from the database schema.
7. External Mollie integration
- The backend depends on Mollie as an external payments provider, configured through config/services.php and the MOLLIE_KEY environment variable described in the README.
- The system creates payments via Mollie’s API and later updates local payment state based on webhook notifications from Mollie.
- The webhook is a key asynchronous boundary: payment creation is synchronous, payment finalization is event-driven.
8. Middleware and cross-cutting concerns
- app/Http/Middleware/Device.php appears to be a custom middleware, likely used to distinguish mobile clients or attach device context.
- Standard Laravel middleware handles CSRF, cookies, proxies, signature validation, maintenance mode, and input trimming.
- config/cors.php suggests the API is intended to be consumed cross-origin, which matters for client integration.
9. Persistence and runtime environment
- The system uses MySQL as its primary datastore, as stated in the README and reflected by the database config and migration-driven schema.
- config/database.php, config/cache.php, config/session.php, and config/queue.php show standard Laravel infrastructure, but the repo does not suggest a heavy queue-based architecture.
- Persistent runtime artifacts live under storage/, including logs and generated API docs.
10. Documentation and API discovery
- config/l5-swagger.php and storage/api-docs/ indicate Swagger/OpenAPI generation is built into the backend.
- The README points to /api/doc, so the API is designed to be self-describing for the mobile demo clients.
11. Deployment and containerization
- docker-compose.yml, docker/php/Dockerfile, and docker/nginx/default.conf define a containerized stack with PHP-FPM/Laravel, Nginx, and MySQL.
- The same app can also run locally with PHP and MySQL directly, so deployment is flexible but still centered on the Laravel app server.
12. End-to-end data flow
- Client app calls the API to fetch available methods and submit a payment request.
- Laravel validates the request, creates or persists a local Payment record, and interacts with Mollie.
- Mollie handles the actual payment checkout and later calls the webhook.
- The backend receives that callback, updates the payment status, and exposes the final state back to the client through JSON resources.
13. Key architectural boundaries to draw
- Client boundary: mobile apps or other API consumers.
- Application boundary: Laravel controllers, requests, and resources.
- Domain boundary: payment model and status enum.
- External service boundary: Mollie API and webhook callbacks.
- Infrastructure boundary: MySQL, Docker/Nginx/PHP, and Swagger-generated docs.
Main entry points: PaymentsController.php API payments · Payment.php Payment · MethodsController.php Methods · api.php API routes
Components 23
Entry & HTTP
Request routing, middleware, and controller entrypoints
- API routes · Main public API contract for clients
routes/api.php - Web routes · Secondary browser-facing surface
routes/web.php - HTTP kernel · Registers global and route middleware
app/Http/Kernel.php - Device · Adds device/client context to requests
app/Http/Middleware/Device.php - API base · Shared base controller for API endpoints
app/Http/Controllers/Api/Controller.php - Methods · Lists available payment methods
app/Http/Controllers/Api/MethodsController.php - API payments · Creates and tracks payments via the API
app/Http/Controllers/Api/PaymentsController.php - Web payments · Non-API payment entrypoint or callback handler
app/Http/Controllers/PaymentsController.php
Payment Domain
Core payment entity, lifecycle, and persistence
- Payment · Persistent payment record and state holder
app/Models/Payment.php - Status enum · Payment lifecycle states
app/Models/Enums/PaymentStatus.php - Payments table · Database schema for stored payments
database/migrations/2021_07_20_104127_create_payments_table.php
API Presentation
Validation and JSON response shaping
- Payment request · Validates payment input before processing
app/Http/Requests/PaymentRequest.php - Payment JSON · API view of payment state
app/Http/Resources/PaymentResource.php - Method JSON · API view of payment methods
app/Http/Resources/MethodResource.php - Aux resources · Supporting JSON wrappers for amounts, prices, issuers, and images
app/Http/Resources/AmountResource.php
Mollie & Docs
External payment provider integration and API documentation
- Services config · Mollie client configuration and secrets wiring
config/services.php - CORS config · Cross-origin API access policy
config/cors.php - Swagger config · OpenAPI generation setup
config/l5-swagger.php - API docs · Generated Swagger/OpenAPI output
storage/api-docs
Infrastructure
Database, container, and runtime support
- Database config · MySQL-backed persistence settings
config/database.php - Docker stack · PHP, Nginx, and MySQL runtime composition
docker-compose.yml - PHP image · PHP-FPM application image definition
docker/php/Dockerfile - Nginx config · Web server configuration for Laravel
docker/nginx/default.conf
Connections 24
- API routes → Methods: routes to · API routes dispatch to method discovery
- API routes → API payments: routes to · API routes dispatch to payment workflows
- Web routes → Web payments: routes to · Web routes expose browser-facing payment handling
- HTTP kernel → Device: includes · Kernel registers custom request context middleware
- API payments → API base: extends · API payment controller shares base behavior
- Methods → API base: extends · Methods controller shares API base behavior
- API payments → Payment request: validates with · Payment creation is guarded by request validation
- API payments → Payment JSON: returns · Payment state is serialized as JSON resource
- Methods → Method JSON: returns · Method discovery is serialized as JSON resource
- API payments → Aux resources: uses · Payment responses include amount/price/image/issuer wrappers
- API payments → Payment: persists · Controller reads and updates payment records
- Web payments → Payment: persists · Web-side flow also touches payment records
- Payment → Status enum: uses · Stored payment state follows domain enum
- Payment → Payments table: stored by · Migration defines the payment table schema
- API payments → Services config: calls Mollie · Controller is wired to the external payments provider
- Services config → CORS config: exposed through · API is intended for cross-origin clients
- Swagger config → API docs: generates · Swagger configuration produces published docs
- API routes → Swagger config: documented by · API routes are discoverable in generated docs
- Payment JSON → Payment: shapes · Resource presents payment model state
- Method JSON → Methods: shapes · Resource supports method listing responses
- Database config → Payments table: backed by · Payments are stored in the configured database
- Docker stack → PHP image: builds · Container stack includes the PHP app image
- Docker stack → Nginx config: serves with · Nginx is part of the runtime stack
- Docker stack → Database config: connects to · Stack includes the MySQL-backed app database